#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*/ breakpoint();
unsigned char inbyte();
int /*<<< orphan*/ outbyte(unsigned char);
int /*<<< orphan*/ print(char *);
int /*<<< orphan*/ set_debug_traps();
main() {
  unsigned char c;
  int num;
  char foo[100];
  set_debug_traps();
  breakpoint();
  print("Got to here\r\n");
  while (1) {
    c = inbyte();
    if (c == 'c')
      break;
    if (c == 'd') {
      set_debug_traps();
      breakpoint();
      break;
    }
    print("echo ");
    outbyte(c);
    print("\r\n");
  }
  print("Hello world\r\n");
  while (1) {
    c = inbyte();
    if ((c & 0x7f) == 4)
      break;
    print("Char is ");
    outbyte(c);
    print("\r\n");
  }
  print("I escaped!\r\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <set_debug_traps@plt>
mov    $0x0,%al
call   1040 <breakpoint@plt>
lea    0xe8c(%rip),%rdi
call   1030 <print@plt>
mov    $0x0,%al
call   1060 <inbyte@plt>
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0x63,%eax
jne    1195 <main+0x45>
jmp    11db <main+0x8b>
movzbl -0x5(%rbp),%eax
cmp    $0x64,%eax
jne    11b5 <main+0x65>
mov    $0x0,%al
call   1050 <set_debug_traps@plt>
mov    $0x0,%al
call   1040 <breakpoint@plt>
jmp    11db <main+0x8b>
lea    0xe52(%rip),%rdi
call   1030 <print@plt>
movzbl -0x5(%rbp),%edi
call   1070 <outbyte@plt>
lea    0xe64(%rip),%rdi
call   1030 <print@plt>
jmp    1179 <main+0x29>
lea    0xe32(%rip),%rdi
call   1030 <print@plt>
mov    $0x0,%al
call   1060 <inbyte@plt>
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
and    $0x7f,%eax
cmp    $0x4,%eax
jne    1206 <main+0xb6>
jmp    122c <main+0xdc>
lea    0xe15(%rip),%rdi
call   1030 <print@plt>
movzbl -0x5(%rbp),%edi
call   1070 <outbyte@plt>
lea    0xe13(%rip),%rdi
call   1030 <print@plt>
jmp    11e7 <main+0x97>
lea    0xdf8(%rip),%rdi
call   1030 <print@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <set_debug_traps@plt>
xor    %eax,%eax
call   1040 <breakpoint@plt>
lea    0xe96(%rip),%rdi
lea    0xe9d(%rip),%r14
lea    0xebd(%rip),%r15
nopl   0x0(%rax,%rax,1)
call   1030 <print@plt>
xor    %eax,%eax
call   1060 <inbyte@plt>
cmp    $0x63,%al
je     11b9 <main+0x69>
mov    %eax,%ebx
cmp    $0x64,%al
je     11ab <main+0x5b>
mov    %r14,%rdi
call   1030 <print@plt>
movzbl %bl,%edi
call   1070 <outbyte@plt>
mov    %r15,%rdi
jmp    1180 <main+0x30>
xor    %eax,%eax
call   1050 <set_debug_traps@plt>
xor    %eax,%eax
call   1040 <breakpoint@plt>
lea    0xe54(%rip),%rdi
call   1030 <print@plt>
xor    %eax,%eax
call   1060 <inbyte@plt>
mov    %eax,%ebx
and    $0x7f,%al
cmp    $0x4,%al
je     1217 <main+0xc7>
lea    0xe47(%rip),%r14
lea    0xe53(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <print@plt>
movzbl %bl,%edi
call   1070 <outbyte@plt>
mov    %r15,%rdi
call   1030 <print@plt>
xor    %eax,%eax
call   1060 <inbyte@plt>
mov    %eax,%ebx
and    $0x7f,%al
cmp    $0x4,%al
jne    11f0 <main+0xa0>
lea    0xe0d(%rip),%rdi
call   1030 <print@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Got to here\0D\0A\00"
@.str.1 = [6 x i8] c"echo \00"
@.str.2 = [3 x i8] c"\0D\0A\00"
@.str.3 = [14 x i8] c"Hello world\0D\0A\00"
@.str.4 = [9 x i8] c"Char is \00"
@.str.5 = [13 x i8] c"I escaped!\0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = call i32 (...) @set_debug_traps()
%6 = call i32 (...) @breakpoint()
%7 = call i32 @print(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %0, %21
%9 = call zeroext i8 (...) @inbyte()
store i8 %9, i8* %2
%10 = load i8, i8* %2
%11 = zext i8 %10 to i32
%12 = icmp eq i32 %11, 99
br i1 %12, label %13, label %14
13: ; preds = %8
br label %26
14: ; preds = %8
%15 = load i8, i8* %2
%16 = zext i8 %15 to i32
%17 = icmp eq i32 %16, 100
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 (...) @set_debug_traps()
%20 = call i32 (...) @breakpoint()
br label %26
21: ; preds = %14
%22 = call i32 @print(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%23 = load i8, i8* %2
%24 = call i32 @outbyte(i8 zeroext %23)
%25 = call i32 @print(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %8
26: ; preds = %18, %13
%27 = call i32 @print(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %35
%29 = call zeroext i8 (...) @inbyte()
store i8 %29, i8* %2
%30 = load i8, i8* %2
%31 = zext i8 %30 to i32
%32 = and i32 %31, 127
%33 = icmp eq i32 %32, 4
br i1 %33, label %34, label %35
34: ; preds = %28
br label %40
35: ; preds = %28
%36 = call i32 @print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%37 = load i8, i8* %2
%38 = call i32 @outbyte(i8 zeroext %37)
%39 = call i32 @print(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %28
40: ; preds = %34
%41 = call i32 @print(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [14 x i8] c"Got to here\0D\0A\00"
@.str.1 = [6 x i8] c"echo \00"
@.str.2 = [3 x i8] c"\0D\0A\00"
@.str.3 = [14 x i8] c"Hello world\0D\0A\00"
@.str.4 = [9 x i8] c"Char is \00"
@.str.5 = [13 x i8] c"I escaped!\0D\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @set_debug_traps()
%2 = tail call i32 (...) @breakpoint()
br label %3
3: ; preds = %10, %0
%4 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %10 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %0 ]
%5 = tail call i32 @print(i8* %4)
%6 = tail call zeroext i8 (...) @inbyte()
switch i8 %6, label %10 [
i8 99, label %13
i8 100, label %7
]
7: ; preds = %3
%8 = tail call i32 (...) @set_debug_traps()
%9 = tail call i32 (...) @breakpoint()
br label %13
10: ; preds = %3
%11 = tail call i32 @print(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @outbyte(i8 zeroext %6)
br label %3
13: ; preds = %3, %7
%14 = tail call i32 @print(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call zeroext i8 (...) @inbyte()
%16 = and i8 %15, 127
%17 = icmp eq i8 %16, 4
br i1 %17, label %26, label %18
18: ; preds = %13, %18
%19 = phi i8 [ %23, %18 ], [ %15, %13 ]
%20 = tail call i32 @print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 @outbyte(i8 zeroext %19)
%22 = tail call i32 @print(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call zeroext i8 (...) @inbyte()
%24 = and i8 %23, 127
%25 = icmp eq i8 %24, 4
br i1 %25, label %26, label %18
26: ; preds = %18, %13
%27 = tail call i32 @print(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}