#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*/ con_bold();
int /*<<< orphan*/ con_color(int);
int /*<<< orphan*/ con_put_char(char const);
int /*<<< orphan*/ con_unbold();
int /*<<< orphan*/ con_uncol();
int /*<<< orphan*/ con_xy(int, int);
void con_box(int x, int y, int color, char const *text) {
  con_xy(x, y);
  con_color(color);
  for (char const *i = text; *i; ++i)
    switch (*i) {
    case '\n':
      con_xy(x, ++y);
      break;
    case '[':
      con_bold();
      con_put_char(*i);
      break;
    case ']':
      con_put_char(*i);
      con_unbold();
      break;
    default:
      con_put_char(*i);
    }
  con_uncol();
}


x86 assembly (clang, -O0):
<con_box>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <con_xy@plt>
mov    -0xc(%rbp),%edi
call   1030 <con_color@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     123f <con_box+0xdf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0xa,%eax
je     11d7 <con_box+0x77>
jmp    11b5 <con_box+0x55>
mov    -0x24(%rbp),%eax
sub    $0x5b,%eax
je     11ed <con_box+0x8d>
jmp    11c6 <con_box+0x66>
mov    -0x24(%rbp),%eax
sub    $0x5d,%eax
je     1205 <con_box+0xa5>
jmp    121d <con_box+0xbd>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x8(%rbp)
call   1050 <con_xy@plt>
jmp    1229 <con_box+0xc9>
mov    $0x0,%al
call   1040 <con_bold@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1080 <con_put_char@plt>
jmp    1229 <con_box+0xc9>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1080 <con_put_char@plt>
mov    $0x0,%al
call   1060 <con_unbold@plt>
jmp    1229 <con_box+0xc9>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1080 <con_put_char@plt>
jmp    122e <con_box+0xce>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1190 <con_box+0x30>
mov    $0x0,%al
call   1070 <con_uncol@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<con_box>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%r14d
call   1050 <con_xy@plt>
mov    %r15d,%edi
call   1030 <con_color@plt>
mov    (%rbx),%al
test   %al,%al
je     11de <con_box+0x7e>
add    $0x1,%rbx
jmp    11ab <con_box+0x4b>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <con_bold@plt>
movsbl -0x1(%rbx),%edi
call   1080 <con_put_char@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11de <con_box+0x7e>
movsbl %al,%edi
cmp    $0x5d,%edi
je     11d0 <con_box+0x70>
cmp    $0x5b,%edi
je     1190 <con_box+0x30>
cmp    $0xa,%edi
jne    119b <con_box+0x3b>
add    $0x1,%ebp
mov    %r14d,%edi
mov    %ebp,%esi
call   1050 <con_xy@plt>
jmp    11a0 <con_box+0x40>
nopl   0x0(%rax)
call   1080 <con_put_char@plt>
xor    %eax,%eax
call   1060 <con_unbold@plt>
jmp    11a0 <con_box+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <con_uncol@plt>

LLVM IR (-O0):
define void @con_box(i32 %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i32 @con_xy(i32 %10, i32 %11)
%13 = load i32, i32* %7
%14 = call i32 @con_color(i32 %13)
%15 = load i8*, i8** %8
store i8* %15, i8** %9
br label %16
16: ; preds = %44, %4
%17 = load i8*, i8** %9
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %47
20: ; preds = %16
%21 = load i8*, i8** %9
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
switch i32 %23, label %39 [
i32 10, label %24
i32 91, label %29
i32 93, label %34
]
24: ; preds = %20
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
%28 = call i32 @con_xy(i32 %25, i32 %27)
br label %43
29: ; preds = %20
%30 = call i32 (...) @con_bold()
%31 = load i8*, i8** %9
%32 = load i8, i8* %31
%33 = call i32 @con_put_char(i8 signext %32)
br label %43
34: ; preds = %20
%35 = load i8*, i8** %9
%36 = load i8, i8* %35
%37 = call i32 @con_put_char(i8 signext %36)
%38 = call i32 (...) @con_unbold()
br label %43
39: ; preds = %20
%40 = load i8*, i8** %9
%41 = load i8, i8* %40
%42 = call i32 @con_put_char(i8 signext %41)
br label %43
43: ; preds = %39, %34, %29, %24
br label %44
44: ; preds = %43
%45 = load i8*, i8** %9
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %9
br label %16
47: ; preds = %16
%48 = call i32 (...) @con_uncol()
ret void
}

LLVM IR (-O2):
define void @con_box(i32 %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = tail call i32 @con_xy(i32 %0, i32 %1)
%6 = tail call i32 @con_color(i32 %2)
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %28, %4
%10 = tail call i32 (...) @con_uncol()
ret void
11: ; preds = %4, %28
%12 = phi i8 [ %31, %28 ], [ %7, %4 ]
%13 = phi i8* [ %30, %28 ], [ %3, %4 ]
%14 = phi i32 [ %29, %28 ], [ %1, %4 ]
%15 = sext i8 %12 to i32
switch i32 %15, label %26 [
i32 10, label %16
i32 91, label %19
i32 93, label %23
]
16: ; preds = %11
%17 = add nsw i32 %14, 1
%18 = tail call i32 @con_xy(i32 %0, i32 %17)
br label %28
19: ; preds = %11
%20 = tail call i32 (...) @con_bold()
%21 = load i8, i8* %13
%22 = tail call i32 @con_put_char(i8 signext %21)
br label %28
23: ; preds = %11
%24 = tail call i32 @con_put_char(i8 signext %12)
%25 = tail call i32 (...) @con_unbold()
br label %28
26: ; preds = %11
%27 = tail call i32 @con_put_char(i8 signext %12)
br label %28
28: ; preds = %16, %19, %23, %26
%29 = phi i32 [ %14, %26 ], [ %14, %23 ], [ %14, %19 ], [ %17, %16 ]
%30 = getelementptr inbounds i8, i8* %13, i64 1
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %9, label %11
}