int main() {
  unsigned long sp;
  __asm__ volatile("mov %%esp,%0\n" : "=m"(sp) :);
  printf("\n############################\n");
  printf("####### Hello World! #######\n");
  printf("############################\n\n");
  while (1) {
    printf("$ ");
    char buffer[80];
    read(buffer);
    if (buffer[0] == 't')
      sleep_test();
    else if (buffer[0] == 'm')
      mem_test();
    else if (buffer[0] == 'r') {
      int ret = read(buffer);
      printf("\n%i\n", ret);
    } else
      printf("\n%s\n", buffer);
  }
  for (;;)
    ;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %esp,-0x10(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x0,%al
call   1050 <read@plt>
movsbl -0x60(%rbp),%eax
cmp    $0x74,%eax
jne    11ae <main+0x6e>
mov    $0x0,%al
call   1060 <sleep_test@plt>
jmp    1214 <main+0xd4>
movsbl -0x60(%rbp),%eax
cmp    $0x6d,%eax
jne    11c7 <main+0x87>
mov    $0x0,%al
call   1030 <mem_test@plt>
jmp    120f <main+0xcf>
movsbl -0x60(%rbp),%eax
cmp    $0x72,%eax
jne    11f8 <main+0xb8>
lea    -0x60(%rbp),%rdi
mov    $0x0,%al
call   1050 <read@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120a <main+0xca>
lea    -0x60(%rbp),%rsi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120f <main+0xcf>
jmp    1214 <main+0xd4>
jmp    117c <main+0x3c>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %esp,0x8(%rsp)
lea    0xea7(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb9(%rip),%rdi
call   1040 <puts@plt>
lea    0xeca(%rip),%rdi
call   1040 <puts@plt>
lea    0xe76(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe6d(%rip),%r15
lea    0xe6b(%rip),%r12
jmp    11b6 <main+0x66>
nop
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <read@plt>
movzbl 0x10(%rsp),%eax
cmp    $0x6d,%al
je     11f0 <main+0xa0>
cmp    $0x72,%al
je     11a0 <main+0x50>
cmp    $0x74,%al
jne    1200 <main+0xb0>
xor    %eax,%eax
call   1070 <sleep_test@plt>
jmp    11b6 <main+0x66>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <mem_test@plt>
jmp    11b6 <main+0x66>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11b6 <main+0x66>

LLVM IR (-O0):
@.str = [31 x i8] c"\0A############################\0A\00"
@.str.1 = [30 x i8] c"####### Hello World! #######\0A\00"
@.str.2 = [31 x i8] c"############################\0A\0A\00"
@.str.3 = [3 x i8] c"$ \00"
@.str.4 = [5 x i8] c"\0A%i\0A\00"
@.str.5 = [5 x i8] c"\0A%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [80 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %0, %40
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @read to i32 (i8*, ...)*)(i8* %10)
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 116
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 (...) @sleep_test()
br label %40
18: ; preds = %8
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 109
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 (...) @mem_test()
br label %39
25: ; preds = %18
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 114
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%32 = call i32 (i8*, ...) bitcast (i32 (...)* @read to i32 (i8*, ...)*)(i8* %31)
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %33)
br label %38
35: ; preds = %25
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %35, %30
br label %39
39: ; preds = %38, %23
br label %40
40: ; preds = %39, %16
br label %8
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"$ \00"
@.str.4 = [5 x i8] c"\0A%i\0A\00"
@.str.5 = [5 x i8] c"\0A%s\0A\00"
@str = [30 x i8] c"\0A############################\00"
@str.6 = [29 x i8] c"####### Hello World! #######\00"
@str.7 = [30 x i8] c"############################\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [80 x i8]
%3 = bitcast i64* %1 to i8*
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.6, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.7, i64 0, i64 0))
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
br label %8
8: ; preds = %21, %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 (i8*, ...) bitcast (i32 (...)* @read to i32 (i8*, ...)*)(i8* %7)
%11 = load i8, i8* %7
switch i8 %11, label %19 [
i8 116, label %12
i8 109, label %14
i8 114, label %16
]
12: ; preds = %8
%13 = call i32 (...) @sleep_test()
br label %21
14: ; preds = %8
%15 = call i32 (...) @mem_test()
br label %21
16: ; preds = %8
%17 = call i32 (i8*, ...) bitcast (i32 (...)* @read to i32 (i8*, ...)*)(i8* %7)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %17)
br label %21
19: ; preds = %8
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %7)
br label %21
21: ; preds = %14, %19, %16, %12
br label %8
}