#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*/ gets(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(void) {
  static char buf[32];
  puts("Hello World!\n");
  while (1) {
    puts("> ");
    gets(buf);
    if (!strncmp(buf, "echo", 4)) {
      puts(buf + 4);
      puts("\n");
    } else if (!strcmp(buf, "exit")) {
      break;
    } else {
      puts("unknown.\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <puts@plt>
lea    0xeac(%rip),%rdi
call   1040 <puts@plt>
lea    0x2ee2(%rip),%rdi
call   1060 <gets@plt>
lea    0x2ed6(%rip),%rdi
lea    0xe90(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11b5 <main+0x75>
lea    0x2eb5(%rip),%rdi
add    $0x4,%rdi
call   1040 <puts@plt>
lea    0xe61(%rip),%rdi
call   1040 <puts@plt>
jmp    11e7 <main+0xa7>
lea    0x2e94(%rip),%rdi
lea    0xe53(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11d6 <main+0x96>
jmp    11ec <main+0xac>
lea    0xe3e(%rip),%rdi
call   1040 <puts@plt>
jmp    11e7 <main+0xa7>
jmp    115b <main+0x1b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
lea    0xec5(%rip),%r14
lea    0x2f00(%rip),%rbx
lea    0xeba(%rip),%r15
lea    0xeae(%rip),%r13
mov    $0x74697865,%ebp
lea    0xeb1(%rip),%r12
jmp    117f <main+0x4f>
nopl   0x0(%rax)
lea    0x2edd(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <gets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1170 <main+0x40>
mov    0x2ea2(%rip),%eax
xor    %ebp,%eax
movzbl 0x2e9d(%rip),%ecx
or     %eax,%ecx
mov    %r12,%rdi
jne    117f <main+0x4f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.buf = internal global [32 x i8] zeroinitializer
@.str = [14 x i8] c"Hello World!\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [5 x i8] c"echo\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [5 x i8] c"exit\00"
@.str.5 = [10 x i8] c"unknown.\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %0, %18
%4 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @gets(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.buf, i64 0, i64 0))
%6 = call i32 @strncmp(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.buf, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%7 = icmp ne i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.buf, i64 0, i64 4))
%10 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %18
11: ; preds = %3
%12 = call i32 @strcmp(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.buf, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %11
br label %19
15: ; preds = %11
%16 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %17
17: ; preds = %15
br label %18
18: ; preds = %17, %8
br label %3
19: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@main.buf = internal global [32 x i8] zeroinitializer
@.str = [14 x i8] c"Hello World!\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [5 x i8] c"echo\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [5 x i8] c"exit\00"
@.str.5 = [10 x i8] c"unknown.\0A\00"
define i32 @main() {
br label %1
1: ; preds = %13, %0
%2 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %0 ], [ %14, %13 ]
%3 = tail call i32 @puts(i8* dereferenceable(1) %2)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @gets(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.buf, i64 0, i64 0))
%6 = tail call i32 @strncmp(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.buf, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @main.buf, i64 0, i64 4))
br label %13
10: ; preds = %1
%11 = tail call i32 @bcmp(i8* dereferenceable(5) getelementptr inbounds ([32 x i8], [32 x i8]* @main.buf, i64 0, i64 0), i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10, %8
%14 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %8 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), %10 ]
br label %1
15: ; preds = %10
ret i32 0
}