#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 *alloca(int);
int main() {
  int *i = alloca(sizeof(int));
  int *j = alloca(sizeof(int));
  int *n = alloca(sizeof(int));
  while (*i < *n) {
    *j = 0;
    while (*j <= *i) {
      *j = *j + 1;
    }
    *i = *i + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    119f <main+0x8f>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jg     118b <main+0x7b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1165 <main+0x55>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1149 <main+0x39>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,%r14
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    (%rbx),%ecx
cmp    (%rax),%ecx
jge    115c <main+0x4c>
xor    %ecx,%ecx
mov    %ecx,(%r14)
mov    (%rbx),%edx
lea    0x1(%rcx),%esi
cmp    %edx,%ecx
mov    %esi,%ecx
jle    1140 <main+0x30>
add    $0x1,%edx
mov    %edx,(%rbx)
mov    $0x0,%ecx
cmp    (%rax),%edx
jl     1140 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32* @alloca(i32 4)
store i32* %5, i32** %2
%6 = call i32* @alloca(i32 4)
store i32* %6, i32** %3
%7 = call i32* @alloca(i32 4)
store i32* %7, i32** %4
br label %8
8: ; preds = %27, %0
%9 = load i32*, i32** %2
%10 = load i32, i32* %9
%11 = load i32*, i32** %4
%12 = load i32, i32* %11
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %32
14: ; preds = %8
%15 = load i32*, i32** %3
store i32 0, i32* %15
br label %16
16: ; preds = %22, %14
%17 = load i32*, i32** %3
%18 = load i32, i32* %17
%19 = load i32*, i32** %2
%20 = load i32, i32* %19
%21 = icmp sle i32 %18, %20
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = load i32*, i32** %3
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
%26 = load i32*, i32** %3
store i32 %25, i32* %26
br label %16
27: ; preds = %16
%28 = load i32*, i32** %2
%29 = load i32, i32* %28
%30 = add nsw i32 %29, 1
%31 = load i32*, i32** %2
store i32 %30, i32* %31
br label %8
32: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32* @alloca(i32 4)
%2 = tail call i32* @alloca(i32 4)
%3 = tail call i32* @alloca(i32 4)
%4 = load i32, i32* %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %4, %5
br i1 %6, label %7, label %18
7: ; preds = %0, %12
%8 = phi i32 [ %13, %12 ], [ 0, %0 ]
store i32 %8, i32* %2
%9 = load i32, i32* %1
%10 = icmp sgt i32 %8, %9
%11 = add nuw nsw i32 %8, 1
br i1 %10, label %14, label %12
12: ; preds = %7, %14
%13 = phi i32 [ %11, %7 ], [ 0, %14 ]
br label %7
14: ; preds = %7
%15 = add nsw i32 %9, 1
store i32 %15, i32* %1
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %12, label %18
18: ; preds = %14, %0
ret i32 0
}