#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 /*<<< orphan*/ sleep(int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ test_function();
int main(int argc, char **argv) {
  int a = 0;
  int *b = NULL;
  int c = 0, d = 0, e = 0;
  if (argc > 1 && strcmp(argv[1], "sleep") == 0) {
    printf("*** Sleeping for 5 seconds\n");
    sleep(5);
  } else if (argc > 1 && strcmp(argv[1], "loop") == 0) {
    printf("*** Looping forever()\n");
    while (1) {
      c++;
      d += 2;
      e += 3;
    }
    sleep(1);
  } else if (argc > 1 && strcmp(argv[1], "function") == 0) {
    printf("*** Calling test_function()\n");
    test_function();
  } else if (argc > 1 && strcmp(argv[1], "crash") == 0) {
    printf("*** Crashing\n");
    a = *b;
  } else {
    printf("Usage: inferior < sleep | loop | function | crash >\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11bd <main+0x7d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11bd <main+0x7d>
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
jmp    12b7 <main+0x177>
cmpl   $0x1,-0x8(%rbp)
jle    121a <main+0xda>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    121a <main+0xda>
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x30(%rbp)
mov    %eax,-0x2c(%rbp)
jmp    11f1 <main+0xb1>
cmpl   $0x1,-0x8(%rbp)
jle    125a <main+0x11a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    125a <main+0x11a>
lea    0xdfe(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <test_function@plt>
jmp    12ad <main+0x16d>
cmpl   $0x1,-0x8(%rbp)
jle    129c <main+0x15c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf1(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    129c <main+0x15c>
lea    0xde1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12a8 <main+0x168>
lea    0xdd5(%rip),%rdi
call   1030 <printf@plt>
jmp    12ad <main+0x16d>
jmp    12b2 <main+0x172>
jmp    12b7 <main+0x177>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jl     119d <main+0x5d>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xeac(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11ab <main+0x6b>
mov    0x8(%rbx),%rdi
lea    0xe9d(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11c3 <main+0x83>
mov    0x8(%rbx),%rdi
lea    0xe8d(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11d2 <main+0x92>
mov    0x8(%rbx),%rdi
lea    0xe81(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e9 <main+0xa9>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
jmp    11e5 <main+0xa5>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
jmp    11e5 <main+0xa5>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
nop
jmp    11d0 <main+0x90>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <test_function@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe5e(%rip),%rdi
jmp    11a4 <main+0x64>

LLVM IR (-O0):
@.str = [6 x i8] c"sleep\00"
@.str.1 = [28 x i8] c"*** Sleeping for 5 seconds\0A\00"
@.str.2 = [5 x i8] c"loop\00"
@.str.3 = [23 x i8] c"*** Looping forever()\0A\00"
@.str.4 = [9 x i8] c"function\00"
@.str.5 = [29 x i8] c"*** Calling test_function()\0A\00"
@.str.6 = [6 x i8] c"crash\00"
@.str.7 = [14 x i8] c"*** Crashing\0A\00"
@.str.8 = [53 x i8] c"Usage: inferior < sleep | loop | function | crash >\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32* null, i32** %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @sleep(i32 5)
br label %70
22: ; preds = %13, %2
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 1
br i1 %24, label %25, label %40
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %25
%32 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %33
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 2
store i32 %37, i32* %9
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 3
store i32 %39, i32* %10
br label %33
40: ; preds = %25, %22
%41 = load i32, i32* %4
%42 = icmp sgt i32 %41, 1
br i1 %42, label %43, label %52
43: ; preds = %40
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 (...) @test_function()
br label %68
52: ; preds = %43, %40
%53 = load i32, i32* %4
%54 = icmp sgt i32 %53, 1
br i1 %54, label %55, label %65
55: ; preds = %52
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %55
%62 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%63 = load i32*, i32** %7
%64 = load i32, i32* %63
store i32 %64, i32* %6
br label %67
65: ; preds = %55, %52
%66 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.8, i64 0, i64 0))
br label %67
67: ; preds = %65, %61
br label %68
68: ; preds = %67, %49
br label %69
69: ; preds = %68
br label %70
70: ; preds = %69, %19
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"sleep\00"
@.str.2 = [5 x i8] c"loop\00"
@.str.4 = [9 x i8] c"function\00"
@.str.6 = [6 x i8] c"crash\00"
@str = [52 x i8] c"Usage: inferior < sleep | loop | function | crash >\00"
@str.9 = [13 x i8] c"*** Crashing\00"
@str.10 = [28 x i8] c"*** Calling test_function()\00"
@str.11 = [22 x i8] c"*** Looping forever()\00"
@str.12 = [27 x i8] c"*** Sleeping for 5 seconds\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %32
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.12, i64 0, i64 0))
%11 = tail call i32 @sleep(i32 5)
br label %34
12: ; preds = %4
%13 = load i8*, i8** %5
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.11, i64 0, i64 0))
br label %18
18: ; preds = %18, %16
br label %18
19: ; preds = %12
%20 = load i8*, i8** %5
%21 = tail call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.10, i64 0, i64 0))
%25 = tail call i32 (...) @test_function()
br label %34
26: ; preds = %19
%27 = load i8*, i8** %5
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0))
br label %34
32: ; preds = %2, %26
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %30, %32, %23, %9
ret i32 0
}