#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 *, int, int, char, ...);
void draw_box(int x, int y, int row, int col, int fcolor, int bcolor, char ch) {
  int i, j;
  for (i = 0; i <= row; i++)
    for (j = 0; j <= col; j++) {
      if (i == 0 || i == row || j == 0 || j == col)
        printf("\033[%d;%dH\033[%d;%dm%c\033[0m\n", i + x, j + y, fcolor,
               bcolor, ch);
      else
        printf("\033[%d;%dH%c", i + x, j + y, ' ');
    }
}


x86 assembly (clang, -O0):
<draw_box>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x10(%rbp),%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11f4 <draw_box+0xe4>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11e1 <draw_box+0xd1>
cmpl   $0x0,-0x1c(%rbp)
je     1181 <draw_box+0x71>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1181 <draw_box+0x71>
cmpl   $0x0,-0x20(%rbp)
je     1181 <draw_box+0x71>
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11af <draw_box+0x9f>
mov    -0x1c(%rbp),%esi
add    -0x4(%rbp),%esi
mov    -0x20(%rbp),%edx
add    -0x8(%rbp),%edx
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%r8d
movsbl 0x10(%rbp),%r9d
lea    0xe60(%rip),%rdi
movsbl %al,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ce <draw_box+0xbe>
mov    -0x1c(%rbp),%esi
add    -0x4(%rbp),%esi
mov    -0x20(%rbp),%edx
add    -0x8(%rbp),%edx
lea    0xe56(%rip),%rdi
mov    $0x20,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d3 <draw_box+0xc3>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1149 <draw_box+0x39>
jmp    11e6 <draw_box+0xd6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1136 <draw_box+0x26>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_box>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,0x1c(%rsp)
mov    %rcx,0x10(%rsp)
mov    %rdi,0x20(%rsp)
mov    %edx,0xc(%rsp)
test   %edx,%edx
js     11ea <draw_box+0xda>
mov    %esi,%ebx
movsbl 0x60(%rsp),%eax
mov    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
lea    0x1(%rax),%r15d
movsbl %r8b,%r12d
xor    %r13d,%r13d
jmp    116e <draw_box+0x5e>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%r13),%eax
cmp    0xc(%rsp),%r13d
mov    %eax,%r13d
je     11ea <draw_box+0xda>
cmpl   $0x0,0x10(%rsp)
js     1160 <draw_box+0x50>
mov    0x20(%rsp),%rax
lea    (%rax,%r13,1),%r14d
xor    %ebp,%ebp
jmp    11b9 <draw_box+0xa9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rbx,%rbp,1),%edx
lea    0xe66(%rip),%rdi
mov    %r14d,%esi
mov    %r12d,%ecx
mov    0x1c(%rsp),%r8d
mov    0x18(%rsp),%r9d
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
je     1160 <draw_box+0x50>
test   %r13d,%r13d
je     1190 <draw_box+0x80>
cmp    0xc(%rsp),%r13d
je     1190 <draw_box+0x80>
test   %ebp,%ebp
je     1190 <draw_box+0x80>
cmp    %ebp,0x10(%rsp)
je     1190 <draw_box+0x80>
lea    (%rbx,%rbp,1),%edx
lea    0xe3f(%rip),%rdi
mov    %r14d,%esi
mov    $0x20,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11b1 <draw_box+0xa1>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"\1B[%d;%dH\1B[%d;%dm%c\1B[0m\0A\00"
@.str.1 = [11 x i8] c"\1B[%d;%dH%c\00"
define void @draw_box(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i8 signext %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i8 %6, i8* %14
store i32 0, i32* %15
br label %17
17: ; preds = %66, %7
%18 = load i32, i32* %15
%19 = load i32, i32* %10
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %69
21: ; preds = %17
store i32 0, i32* %16
br label %22
22: ; preds = %62, %21
%23 = load i32, i32* %16
%24 = load i32, i32* %11
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %65
26: ; preds = %22
%27 = load i32, i32* %15
%28 = icmp eq i32 %27, 0
br i1 %28, label %40, label %29
29: ; preds = %26
%30 = load i32, i32* %15
%31 = load i32, i32* %10
%32 = icmp eq i32 %30, %31
br i1 %32, label %40, label %33
33: ; preds = %29
%34 = load i32, i32* %16
%35 = icmp eq i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = load i32, i32* %16
%38 = load i32, i32* %11
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %53
40: ; preds = %36, %33, %29, %26
%41 = load i32, i32* %15
%42 = load i32, i32* %8
%43 = add nsw i32 %41, %42
%44 = load i32, i32* %16
%45 = load i32, i32* %9
%46 = add nsw i32 %44, %45
%47 = load i32, i32* %12
%48 = trunc i32 %47 to i8
%49 = load i32, i32* %13
%50 = load i8, i8* %14
%51 = sext i8 %50 to i32
%52 = call i32 (i8*, i32, i32, i8, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %43, i32 %46, i8 signext %48, i32 %49, i32 %51)
br label %61
53: ; preds = %36
%54 = load i32, i32* %15
%55 = load i32, i32* %8
%56 = add nsw i32 %54, %55
%57 = load i32, i32* %16
%58 = load i32, i32* %9
%59 = add nsw i32 %57, %58
%60 = call i32 (i8*, i32, i32, i8, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %56, i32 %59, i8 signext 32)
br label %61
61: ; preds = %53, %40
br label %62
62: ; preds = %61
%63 = load i32, i32* %16
%64 = add nsw i32 %63, 1
store i32 %64, i32* %16
br label %22
65: ; preds = %22
br label %66
66: ; preds = %65
%67 = load i32, i32* %15
%68 = add nsw i32 %67, 1
store i32 %68, i32* %15
br label %17
69: ; preds = %17
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"\1B[%d;%dH\1B[%d;%dm%c\1B[0m\0A\00"
@.str.1 = [11 x i8] c"\1B[%d;%dH%c\00"
define void @draw_box(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i8 signext %6) {
%8 = icmp slt i32 %2, 0
br i1 %8, label %38, label %9
9: ; preds = %7
%10 = icmp slt i32 %3, 0
%11 = trunc i32 %4 to i8
%12 = sext i8 %6 to i32
br label %13
13: ; preds = %9, %35
%14 = phi i32 [ 0, %9 ], [ %36, %35 ]
br i1 %10, label %35, label %15
15: ; preds = %13
%16 = icmp eq i32 %14, 0
%17 = icmp eq i32 %14, %2
%18 = add nsw i32 %14, %0
br label %19
19: ; preds = %15, %32
%20 = phi i32 [ 0, %15 ], [ %33, %32 ]
br i1 %16, label %26, label %21
21: ; preds = %19
%22 = icmp eq i32 %20, 0
%23 = select i1 %17, i1 true, i1 %22
%24 = icmp eq i32 %20, %3
%25 = select i1 %23, i1 true, i1 %24
br i1 %25, label %26, label %29
26: ; preds = %21, %19
%27 = add nsw i32 %20, %1
%28 = tail call i32 (i8*, i32, i32, i8, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %27, i8 signext %11, i32 %5, i32 %12)
br label %32
29: ; preds = %21
%30 = add nsw i32 %20, %1
%31 = tail call i32 (i8*, i32, i32, i8, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %30, i8 signext 32)
br label %32
32: ; preds = %26, %29
%33 = add nuw i32 %20, 1
%34 = icmp eq i32 %20, %3
br i1 %34, label %35, label %19
35: ; preds = %32, %13
%36 = add nuw i32 %14, 1
%37 = icmp eq i32 %14, %2
br i1 %37, label %38, label %13
38: ; preds = %35, %7
ret void
}