#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 */
struct grid {
  int dummy;
};

/* Variables and functions */
scalar_t__ grid_at(struct grid *, int, int);
int /*<<< orphan*/ printf(char *);
void draw_grid(struct grid *grid, const int from_x, const int from_y,
               const int to_x, const int to_y) {
  int x, y;
  for (y = from_y; y <= to_y; ++y) {
    for (x = from_x; x <= to_x; ++x)
      if (grid_at(grid, x, y))
        printf("*");
      else
        printf(" ");
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<draw_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11c0 <draw_grid+0xa0>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11a6 <draw_grid+0x86>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1040 <grid_at@plt>
cmp    $0x0,%rax
je     1187 <draw_grid+0x67>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
jmp    1193 <draw_grid+0x73>
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
jmp    1198 <draw_grid+0x78>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1151 <draw_grid+0x31>
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113f <draw_grid+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_grid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x10(%rsp)
mov    %r8d,0xc(%rsp)
cmp    %r8d,%edx
jle    114c <draw_grid+0x2c>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edx,%ebx
mov    %esi,%r12d
mov    %rdi,%r13
mov    0x10(%rsp),%rax
lea    0x1(%rax),%r14d
mov    $0x20,%r15d
jmp    1185 <draw_grid+0x65>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1(%rbx),%eax
cmp    0xc(%rsp),%ebx
mov    %eax,%ebx
je     113d <draw_grid+0x1d>
cmp    0x10(%rsp),%r12d
jg     1170 <draw_grid+0x50>
mov    %r12d,%ebp
nop
mov    %r13,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <grid_at@plt>
test   %rax,%rax
mov    $0x2a,%edi
cmove  %r15d,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1190 <draw_grid+0x70>
jmp    1170 <draw_grid+0x50>

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

LLVM IR (-O2):
%struct.grid = type { i32 }
define void @draw_grid(%struct.grid* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %2, %4
br i1 %6, label %23, label %7
7: ; preds = %5
%8 = icmp sgt i32 %1, %3
br label %9
9: ; preds = %7, %19
%10 = phi i32 [ %2, %7 ], [ %21, %19 ]
br i1 %8, label %19, label %11
11: ; preds = %9, %11
%12 = phi i32 [ %17, %11 ], [ %1, %9 ]
%13 = tail call i64 @grid_at(%struct.grid* %0, i32 %12, i32 %10)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i32 32, i32 42
%16 = tail call i32 @putchar(i32 %15)
%17 = add i32 %12, 1
%18 = icmp eq i32 %12, %3
br i1 %18, label %19, label %11
19: ; preds = %11, %9
%20 = tail call i32 @putchar(i32 10)
%21 = add i32 %10, 1
%22 = icmp eq i32 %10, %4
br i1 %22, label %23, label %9
23: ; preds = %19, %5
ret void
}