#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 atoi(char *);
int /*<<< orphan*/ double_free();
int /*<<< orphan*/ glob_buff_overrun();
int /*<<< orphan*/ mem_leak();
int /*<<< orphan*/ memcpy_overlapping_src_dst();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rw_after_free();
int /*<<< orphan*/ rw_bad_stk_location();
int /*<<< orphan*/ rw_malloc_overrun();
int /*<<< orphan*/ stk_overrun();
int /*<<< orphan*/ systemcall_unaddressable_bytes();
int /*<<< orphan*/ test_6();
int /*<<< orphan*/ unintialized_use();
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("Syntax:");
    printf("  %s <test-number> <test-number> <test-number> . . .\r\n", argv[0]);
    return -1;
  }
  int ctr;
  for (ctr = 1; ctr < argc; ctr++) {
    int test_number = atoi(argv[ctr]);
    switch (test_number) {
    case 1:
      unintialized_use();
      break;
    case 2:
      rw_after_free();
      break;
    case 3:
      rw_malloc_overrun();
      break;
    case 4:
      rw_bad_stk_location();
      break;
    case 5:
      mem_leak();
      break;
    case 6:
      test_6();
      break;
    case 7:
      memcpy_overlapping_src_dst();
      break;
    case 8:
      double_free();
      break;
    case 9:
      systemcall_unaddressable_bytes();
      break;
    case 10:
      stk_overrun();
      break;
    case 11:
      glob_buff_overrun();
      break;
    default:
      printf("No test or invalid test specified (only 1--9 are valid).");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    121f <main+0x4f>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1327 <main+0x157>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1320 <main+0x150>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0xa,%eax
ja     12f3 <main+0x123>
mov    -0x20(%rbp),%rax
lea    0xd9a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1070 <unintialized_use@plt>
jmp    130d <main+0x13d>
mov    $0x0,%al
call   1090 <rw_after_free@plt>
jmp    130d <main+0x13d>
mov    $0x0,%al
call   1040 <rw_malloc_overrun@plt>
jmp    130d <main+0x13d>
mov    $0x0,%al
call   10d0 <rw_bad_stk_location@plt>
jmp    130d <main+0x13d>
mov    $0x0,%al
call   10b0 <mem_leak@plt>
jmp    130d <main+0x13d>
mov    $0x0,%al
call   10a0 <test_6@plt>
jmp    130d <main+0x13d>
mov    $0x0,%al
call   10c0 <memcpy_overlapping_src_dst@plt>
jmp    130d <main+0x13d>
mov    $0x0,%al
call   10f0 <double_free@plt>
jmp    130d <main+0x13d>
mov    $0x0,%al
call   1080 <systemcall_unaddressable_bytes@plt>
jmp    130d <main+0x13d>
mov    $0x0,%al
call   1060 <stk_overrun@plt>
jmp    130d <main+0x13d>
mov    $0x0,%al
call   1030 <glob_buff_overrun@plt>
jmp    130d <main+0x13d>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1327 <main+0x157>
jmp    1312 <main+0x142>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1226 <main+0x56>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
jge    1209 <main+0x39>
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%rsi
lea    0xe3c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
jmp    12af <main+0xdf>
mov    %edi,%r15d
mov    $0x1,%ebx
lea    0xde8(%rip),%r12
jmp    1239 <main+0x69>
xor    %eax,%eax
call   1070 <unintialized_use@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r15
je     12ad <main+0xdd>
mov    (%r14,%rbx,8),%rdi
call   10e0 <atoi@plt>
add    $0xffffffff,%eax
cmp    $0xa,%eax
ja     12bb <main+0xeb>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
xor    %eax,%eax
call   1090 <rw_after_free@plt>
jmp    1230 <main+0x60>
xor    %eax,%eax
call   1040 <rw_malloc_overrun@plt>
jmp    1230 <main+0x60>
xor    %eax,%eax
call   10d0 <rw_bad_stk_location@plt>
jmp    1230 <main+0x60>
xor    %eax,%eax
call   10b0 <mem_leak@plt>
jmp    1230 <main+0x60>
xor    %eax,%eax
call   10a0 <test_6@plt>
jmp    1230 <main+0x60>
xor    %eax,%eax
call   10c0 <memcpy_overlapping_src_dst@plt>
jmp    1230 <main+0x60>
xor    %eax,%eax
call   10f0 <double_free@plt>
jmp    1230 <main+0x60>
xor    %eax,%eax
call   1080 <systemcall_unaddressable_bytes@plt>
jmp    1230 <main+0x60>
xor    %eax,%eax
call   1060 <stk_overrun@plt>
jmp    1230 <main+0x60>
xor    %eax,%eax
call   1030 <glob_buff_overrun@plt>
jmp    1230 <main+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xda9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
jmp    12af <main+0xdf>

LLVM IR (-O0):
@.str = [8 x i8] c"Syntax:\00"
@.str.1 = [55 x i8] c" %s <test-number> <test-number> <test-number> . . .\0D\0A\00"
@.str.2 = [57 x i8] c"No test or invalid test specified (only 1--9 are valid).\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %58
16: ; preds = %2
store i32 1, i32* %6
br label %17
17: ; preds = %54, %16
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %57
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
switch i32 %28, label %51 [
i32 1, label %29
i32 2, label %31
i32 3, label %33
i32 4, label %35
i32 5, label %37
i32 6, label %39
i32 7, label %41
i32 8, label %43
i32 9, label %45
i32 10, label %47
i32 11, label %49
]
29: ; preds = %21
%30 = call i32 (...) @unintialized_use()
br label %53
31: ; preds = %21
%32 = call i32 (...) @rw_after_free()
br label %53
33: ; preds = %21
%34 = call i32 (...) @rw_malloc_overrun()
br label %53
35: ; preds = %21
%36 = call i32 (...) @rw_bad_stk_location()
br label %53
37: ; preds = %21
%38 = call i32 (...) @mem_leak()
br label %53
39: ; preds = %21
%40 = call i32 (...) @test_6()
br label %53
41: ; preds = %21
%42 = call i32 (...) @memcpy_overlapping_src_dst()
br label %53
43: ; preds = %21
%44 = call i32 (...) @double_free()
br label %53
45: ; preds = %21
%46 = call i32 (...) @systemcall_unaddressable_bytes()
br label %53
47: ; preds = %21
%48 = call i32 (...) @stk_overrun()
br label %53
49: ; preds = %21
%50 = call i32 (...) @glob_buff_overrun()
br label %53
51: ; preds = %21
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %58
53: ; preds = %49, %47, %45, %43, %41, %39, %37, %35, %33, %31, %29
br label %54
54: ; preds = %53
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %17
57: ; preds = %17
store i32 0, i32* %3
br label %58
58: ; preds = %57, %51, %10
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [8 x i8] c"Syntax:\00"
@.str.1 = [55 x i8] c" %s <test-number> <test-number> <test-number> . . .\0D\0A\00"
@.str.2 = [57 x i8] c"No test or invalid test specified (only 1--9 are valid).\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %10
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %42
10: ; preds = %4, %39
%11 = phi i64 [ 1, %4 ], [ %40, %39 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
switch i32 %14, label %37 [
i32 1, label %15
i32 2, label %17
i32 3, label %19
i32 4, label %21
i32 5, label %23
i32 6, label %25
i32 7, label %27
i32 8, label %29
i32 9, label %31
i32 10, label %33
i32 11, label %35
]
15: ; preds = %10
%16 = tail call i32 (...) @unintialized_use()
br label %39
17: ; preds = %10
%18 = tail call i32 (...) @rw_after_free()
br label %39
19: ; preds = %10
%20 = tail call i32 (...) @rw_malloc_overrun()
br label %39
21: ; preds = %10
%22 = tail call i32 (...) @rw_bad_stk_location()
br label %39
23: ; preds = %10
%24 = tail call i32 (...) @mem_leak()
br label %39
25: ; preds = %10
%26 = tail call i32 (...) @test_6()
br label %39
27: ; preds = %10
%28 = tail call i32 (...) @memcpy_overlapping_src_dst()
br label %39
29: ; preds = %10
%30 = tail call i32 (...) @double_free()
br label %39
31: ; preds = %10
%32 = tail call i32 (...) @systemcall_unaddressable_bytes()
br label %39
33: ; preds = %10
%34 = tail call i32 (...) @stk_overrun()
br label %39
35: ; preds = %10
%36 = tail call i32 (...) @glob_buff_overrun()
br label %39
37: ; preds = %10
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0))
br label %42
39: ; preds = %35, %33, %31, %29, %27, %25, %23, %21, %19, %17, %15
%40 = add nuw nsw i64 %11, 1
%41 = icmp eq i64 %40, %5
br i1 %41, label %42, label %10
42: ; preds = %39, %37, %6
%43 = phi i32 [ -1, %6 ], [ -1, %37 ], [ 0, %39 ]
ret i32 %43
}