In: Computer Science
Write equivalent LLVM IR for the following SimpleC program. I need the answer ASAP please if possible
int x; int y; read x; y = x + 1; print y;
The program below is the LLVM IR program for the given C program:
; ModuleID = 'testfile.c'
source_filename = "testfile.c"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-darwin18.7.0"
@.str = private unnamed_addr constant [3 x i8] c"%d\00", align 1
; Function Attrs: noinline nounwind optnone
define i32 @main() #0 {
entry:
%x = alloca i32, align 4
%y = alloca i32, align 4
%call = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x
i8], [3 x i8]* @.str, i32 0, i32 0), i32* %x)
%0 = load i32, i32* %x, align 4
%add = add nsw i32 %0, 1
store i32 %add, i32* %y, align 4
%1 = load i32, i32* %y, align 4
%call1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3
x i8], [3 x i8]* @.str, i32 0, i32 0), i32 %1)
ret i32 0
}
declare i32 @scanf(i8*, ...) #1
declare i32 @printf(i8*, ...) #1
attributes #0 = { noinline nounwind optnone
"correctly-rounded-divide-sqrt-fp-math"="false"
"disable-tail-calls"="false" "less-precise-fpmad"="false"
"min-legal-vector-width"="0" "no-frame-pointer-elim"="false"
"no-infs-fp-math"="false" "no-jump-tables"="false"
"no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false"
"no-trapping-math"="false" "stack-protector-buffer-size"="8"
"target-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false"
"use-soft-float"="false" }
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false"
"disable-tail-calls"="false" "less-precise-fpmad"="false"
"no-frame-pointer-elim"="false" "no-infs-fp-math"="false"
"no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false"
"no-trapping-math"="false" "stack-protector-buffer-size"="8"
"target-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false"
"use-soft-float"="false" }
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"Apple clang version 11.0.0 (clang-1100.0.33.8)"}
C program:
LLVR program: