#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int g = -1;
  while (g <= 0) {
    printf("Enter positive number to calculate squares to:\n");
    scanf("%d", &g);
    printf("The Number you inputted was: %d \n", g);
  }
  int i;
  int pre[g];
  for (i = 0; i <= g; i++) {
    pre[i] = i;
    printf("Spot %d in the array is: %d\n", i, i);
  }
  for (i = 0; i <= g; i++) {
    pre[i] = i * i;
    printf("Spot %d in the array is now: %d\n", i, pre[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1174 <main+0x54>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%esi
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1136 <main+0x16>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11de <main+0xbe>
mov    -0x28(%rbp),%rax
mov    -0xc(%rbp),%edx
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a2 <main+0x82>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1229 <main+0x109>
mov    -0x28(%rbp),%rax
mov    -0xc(%rbp),%edx
imul   -0xc(%rbp),%edx
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%esi
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e5 <main+0xc5>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movl   $0xffffffff,0x4(%rsp)
ff
lea    0xf1c(%rip),%r14
lea    0xeb2(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xea9(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    1160 <main+0x30>
mov    %rsp,%r15
cmpl   $0x0,0x4(%rsp)
js     11ea <main+0xba>
mov    $0xffffffff,%ebx
lea    0xe87(%rip),%r14
xchg   %ax,%ax
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%eax
cmp    %eax,%ebx
jl     11a0 <main+0x70>
test   %eax,%eax
js     11ea <main+0xba>
mov    $0xffffffff,%ebx
lea    0xe79(%rip),%r14
nopl   0x0(%rax)
add    $0x1,%ebx
mov    %ebx,%edx
imul   %ebx,%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    0x4(%rsp),%ebx
jl     11d0 <main+0xa0>
mov    %r15,%rsp
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Enter positive number to calculate squares to:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"The Number you inputted was: %d \0A\00"
@.str.3 = [29 x i8] c"Spot %d in the array is: %d\0A\00"
@.str.4 = [33 x i8] c"Spot %d in the array is now: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
store i32 -1, i32* %2
br label %6
6: ; preds = %9, %0
%7 = load i32, i32* %2
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %6
14: ; preds = %6
%15 = load i32, i32* %2
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %4
%18 = alloca i32, i64 %16
store i64 %16, i64* %5
store i32 0, i32* %3
br label %19
19: ; preds = %31, %14
%20 = load i32, i32* %3
%21 = load i32, i32* %2
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = load i32, i32* %3
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %18, i64 %26
store i32 %24, i32* %27
%28 = load i32, i32* %3
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 %29)
br label %31
31: ; preds = %23
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %19
34: ; preds = %19
store i32 0, i32* %3
br label %35
35: ; preds = %52, %34
%36 = load i32, i32* %3
%37 = load i32, i32* %2
%38 = icmp sle i32 %36, %37
br i1 %38, label %39, label %55
39: ; preds = %35
%40 = load i32, i32* %3
%41 = load i32, i32* %3
%42 = mul nsw i32 %40, %41
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %18, i64 %44
store i32 %42, i32* %45
%46 = load i32, i32* %3
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %18, i64 %48
%50 = load i32, i32* %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %50)
br label %52
52: ; preds = %39
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %35
55: ; preds = %35
%56 = load i8*, i8** %4
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"The Number you inputted was: %d \0A\00"
@.str.3 = [29 x i8] c"Spot %d in the array is: %d\0A\00"
@.str.4 = [33 x i8] c"Spot %d in the array is now: %d\0A\00"
@str = [47 x i8] c"Enter positive number to calculate squares to:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
br label %3
3: ; preds = %0, %3
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 1
br i1 %9, label %3, label %10
10: ; preds = %3
%11 = call i8* @llvm.stacksave()
%12 = load i32, i32* %1
%13 = icmp slt i32 %12, 0
br i1 %13, label %29, label %16
14: ; preds = %16
%15 = icmp slt i32 %20, 0
br i1 %15, label %29, label %22
16: ; preds = %10, %16
%17 = phi i32 [ %19, %16 ], [ 0, %10 ]
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 %17)
%19 = add nuw nsw i32 %17, 1
%20 = load i32, i32* %1
%21 = icmp slt i32 %17, %20
br i1 %21, label %16, label %14
22: ; preds = %14, %22
%23 = phi i32 [ %26, %22 ], [ 0, %14 ]
%24 = mul nsw i32 %23, %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %23, i32 %24)
%26 = add nuw nsw i32 %23, 1
%27 = load i32, i32* %1
%28 = icmp slt i32 %23, %27
br i1 %28, label %22, label %29
29: ; preds = %22, %10, %14
ret i32 0
}