#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, char **grid) {
  for (int i = 0; i < x; ++i) {
    for (int j = 0; j < y; ++j) {
      if (grid[i][j] == 0) {
        printf(" . ");
      } else {
        printf(" X ");
      }
    }
    printf("\n");
  }
  printf("\n");
}


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    11af <print_grid+0x9f>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1195 <print_grid+0x85>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1176 <print_grid+0x66>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
jmp    1182 <print_grid+0x72>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
jmp    1187 <print_grid+0x77>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113c <print_grid+0x2c>
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <print_grid+0x19>
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
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    $0x18,%rsp
mov    %esi,0xc(%rsp)
test   %edi,%edi
jle    11b1 <print_grid+0x91>
mov    %rdx,%r12
mov    %edi,%eax
mov    %rax,0x10(%rsp)
mov    0xc(%rsp),%ebp
xor    %ebx,%ebx
lea    0xeb3(%rip),%r13
lea    0xeb0(%rip),%r14
jmp    1175 <print_grid+0x55>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    0x10(%rsp),%rbx
je     11b1 <print_grid+0x91>
cmpl   $0x0,0xc(%rsp)
jle    1160 <print_grid+0x40>
xor    %r15d,%r15d
jmp    119e <print_grid+0x7e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1040 <printf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
je     1160 <print_grid+0x40>
mov    (%r12,%rbx,8),%rax
cmpb   $0x0,(%rax,%r15,1)
mov    %r13,%rdi
je     1190 <print_grid+0x70>
mov    %r14,%rdi
jmp    1190 <print_grid+0x70>
mov    $0xa,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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