#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 print_grid(int x, int y, int *vals) {
  for (int i = 0; i < x; ++i) {
    if (i)
      printf("; ");
    for (int j = 0; j < y; ++j) {
      if (j)
        printf(" ");
      printf("%d", vals[i * y + j]);
    }
  }
}


x86 assembly (clang, -O0):
<print_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11bb <print_grid+0xab>
cmpl   $0x0,-0x14(%rbp)
je     114d <print_grid+0x3d>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a8 <print_grid+0x98>
cmpl   $0x0,-0x18(%rbp)
je     1178 <print_grid+0x68>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1154 <print_grid+0x44>
jmp    11ad <print_grid+0x9d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <print_grid+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_grid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x8(%rsp)
test   %edi,%edi
jle    11e3 <print_grid+0xc3>
mov    %esi,%ebp
movslq %esi,%rax
mov    %edi,%ecx
mov    %rcx,0x20(%rsp)
mov    %eax,%r15d
mov    %rax,0x10(%rsp)
lea    0x0(,%rax,4),%rax
mov    %rax,0x18(%rsp)
lea    0xea0(%rip),%rbx
mov    0x8(%rsp),%r12
xor    %r13d,%r13d
jmp    1180 <print_grid+0x60>
nopl   (%rax)
add    $0x1,%r13
add    0x18(%rsp),%r12
cmp    0x20(%rsp),%r13
je     11e3 <print_grid+0xc3>
test   %r13,%r13
je     1193 <print_grid+0x73>
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    1170 <print_grid+0x50>
mov    %r13,%rax
imul   0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
mov    (%rcx,%rax,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%ebp
je     1170 <print_grid+0x50>
mov    $0x1,%r14d
nopl   (%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    (%r12,%r14,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14
cmp    %r14,%r15
jne    11c0 <print_grid+0xa0>
jmp    1170 <print_grid+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"; \00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [3 x i8] c"%d\00"
define void @print_grid(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
br label %9
9: ; preds = %43, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %46
13: ; preds = %9
%14 = load i32, i32* %7
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
store i32 0, i32* %8
br label %19
19: ; preds = %39, %18
%20 = load i32, i32* %8
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %42
23: ; preds = %19
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
%29 = load i32*, i32** %6
%30 = load i32, i32* %7
%31 = load i32, i32* %5
%32 = mul nsw i32 %30, %31
%33 = load i32, i32* %8
%34 = add nsw i32 %32, %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %29, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %28
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %19
42: ; preds = %19
br label %43
43: ; preds = %42
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %9
46: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"; \00"
@.str.2 = [3 x i8] c"%d\00"
define void @print_grid(i32 %0, i32 %1, i32* nocapture %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %11
5: ; preds = %3
%6 = icmp sgt i32 %1, 0
%7 = sext i32 %1 to i64
%8 = zext i32 %0 to i64
%9 = zext i32 %1 to i64
%10 = icmp eq i32 %1, 1
br label %12
11: ; preds = %23, %3
ret void
12: ; preds = %5, %23
%13 = phi i64 [ 0, %5 ], [ %24, %23 ]
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
br i1 %6, label %18, label %23
18: ; preds = %17
%19 = mul nsw i64 %13, %7
%20 = getelementptr inbounds i32, i32* %2, i64 %19
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br i1 %10, label %23, label %26
23: ; preds = %26, %18, %17
%24 = add nuw nsw i64 %13, 1
%25 = icmp eq i64 %24, %8
br i1 %25, label %11, label %12
26: ; preds = %18, %26
%27 = phi i64 [ %33, %26 ], [ 1, %18 ]
%28 = tail call i32 @putchar(i32 32)
%29 = add nsw i64 %27, %19
%30 = getelementptr inbounds i32, i32* %2, i64 %29
%31 = load i32, i32* %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i64 %27, 1
%34 = icmp eq i64 %33, %9
br i1 %34, label %23, label %26
}