#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 *, ...);
void nested_loops(void) {
  int x, y, width = 3, height = 3;
  printf("nested loops example: %d x %d grid\n", width, height);
  for (x = 0; x < width; x++) {
    for (y = 0; y < height; y++) {
      printf("[%d,%d]", x, y);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<nested_loops>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x3,-0xc(%rbp)
movl   $0x3,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119e <nested_loops+0x8e>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1182 <nested_loops+0x72>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1154 <nested_loops+0x44>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1141 <nested_loops+0x31>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nested_loops>:
push   %rbx
lea    0xed8(%rip),%rdi
mov    $0x3,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee4(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"nested loops example: %d x %d grid\0A\00"
@.str.1 = [8 x i8] c"[%d,%d]\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @nested_loops() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 3, i32* %3
store i32 3, i32* %4
%5 = load i32, i32* %3
%6 = load i32, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
store i32 0, i32* %1
br label %8
8: ; preds = %26, %0
%9 = load i32, i32* %1
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %29
12: ; preds = %8
store i32 0, i32* %2
br label %13
13: ; preds = %21, %12
%14 = load i32, i32* %2
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = load i32, i32* %1
%19 = load i32, i32* %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %19)
br label %21
21: ; preds = %17
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
br label %13
24: ; preds = %13
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24
%27 = load i32, i32* %1
%28 = add nsw i32 %27, 1
store i32 %28, i32* %1
br label %8
29: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [36 x i8] c"nested loops example: %d x %d grid\0A\00"
@.str.1 = [8 x i8] c"[%d,%d]\00"
define void @nested_loops() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 3, i32 3)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 1)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 2)
%5 = tail call i32 @putchar(i32 10)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 0)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 1)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 2)
%9 = tail call i32 @putchar(i32 10)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 0)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 1)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 2)
%13 = tail call i32 @putchar(i32 10)
ret void
}