#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*/ M_CHECK_ACTION;
int atoi(char *);
int /*<<< orphan*/ double_free();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ glob_buff_overrun();
int mallopt(int /*<<< orphan*/, int);
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*/ stderr;
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;
  }
  if (mallopt(M_CHECK_ACTION, 7) != 1) {
    fprintf(stderr, "mallopt() failed");
    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    123f <main+0x4f>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1384 <main+0x194>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    $0x7,%esi
call   1030 <mallopt@plt>
cmp    $0x1,%eax
je     127c <main+0x8c>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1384 <main+0x194>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    137d <main+0x18d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0xa,%eax
ja     1350 <main+0x160>
mov    -0x20(%rbp),%rax
lea    0xd3d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1080 <unintialized_use@plt>
jmp    136a <main+0x17a>
mov    $0x0,%al
call   10b0 <rw_after_free@plt>
jmp    136a <main+0x17a>
mov    $0x0,%al
call   1050 <rw_malloc_overrun@plt>
jmp    136a <main+0x17a>
mov    $0x0,%al
call   10f0 <rw_bad_stk_location@plt>
jmp    136a <main+0x17a>
mov    $0x0,%al
call   10d0 <mem_leak@plt>
jmp    136a <main+0x17a>
mov    $0x0,%al
call   10c0 <test_6@plt>
jmp    136a <main+0x17a>
mov    $0x0,%al
call   10e0 <memcpy_overlapping_src_dst@plt>
jmp    136a <main+0x17a>
mov    $0x0,%al
call   1110 <double_free@plt>
jmp    136a <main+0x17a>
mov    $0x0,%al
call   10a0 <systemcall_unaddressable_bytes@plt>
jmp    136a <main+0x17a>
mov    $0x0,%al
call   1070 <stk_overrun@plt>
jmp    136a <main+0x17a>
mov    $0x0,%al
call   1040 <glob_buff_overrun@plt>
jmp    136a <main+0x17a>
lea    0xd25(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1384 <main+0x194>
jmp    136f <main+0x17f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1283 <main+0x93>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jg     1228 <main+0x38>
lea    0xe26(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r14),%rsi
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%eax
jmp    1307 <main+0x117>
mov    %edi,%ebp
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    $0x7,%esi
call   1030 <mallopt@plt>
cmp    $0x1,%eax
jne    12e9 <main+0xf9>
mov    %ebp,%r15d
mov    $0x1,%ebx
lea    0xdab(%rip),%rbp
jmp    126d <main+0x7d>
xor    %eax,%eax
call   1080 <unintialized_use@plt>
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%r15
je     1305 <main+0x115>
mov    (%r14,%rbx,8),%rdi
call   1100 <atoi@plt>
add    $0xffffffff,%eax
cmp    $0xa,%eax
ja     1312 <main+0x122>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
xor    %eax,%eax
call   10b0 <rw_after_free@plt>
jmp    1260 <main+0x70>
xor    %eax,%eax
call   1050 <rw_malloc_overrun@plt>
jmp    1260 <main+0x70>
xor    %eax,%eax
call   10f0 <rw_bad_stk_location@plt>
jmp    1260 <main+0x70>
xor    %eax,%eax
call   10d0 <mem_leak@plt>
jmp    1260 <main+0x70>
xor    %eax,%eax
call   10c0 <test_6@plt>
jmp    1260 <main+0x70>
xor    %eax,%eax
call   10e0 <memcpy_overlapping_src_dst@plt>
jmp    1260 <main+0x70>
xor    %eax,%eax
call   1110 <double_free@plt>
jmp    1260 <main+0x70>
xor    %eax,%eax
call   10a0 <systemcall_unaddressable_bytes@plt>
jmp    1260 <main+0x70>
xor    %eax,%eax
call   1070 <stk_overrun@plt>
jmp    1260 <main+0x70>
xor    %eax,%eax
call   1040 <glob_buff_overrun@plt>
jmp    1260 <main+0x70>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1307 <main+0x117>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd63(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%eax
jmp    1307 <main+0x117>

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"
@M_CHECK_ACTION = global i32 0
@stderr = global i32 0
@.str.2 = [17 x i8] c"mallopt() failed\00"
@.str.3 = [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 %65
16: ; preds = %2
%17 = load i32, i32* @M_CHECK_ACTION
%18 = call i32 @mallopt(i32 %17, i32 7)
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %65
23: ; preds = %16
store i32 1, i32* %6
br label %24
24: ; preds = %61, %23
%25 = load i32, i32* %6
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %64
28: ; preds = %24
%29 = load i8**, i8*** %5
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
switch i32 %35, label %58 [
i32 1, label %36
i32 2, label %38
i32 3, label %40
i32 4, label %42
i32 5, label %44
i32 6, label %46
i32 7, label %48
i32 8, label %50
i32 9, label %52
i32 10, label %54
i32 11, label %56
]
36: ; preds = %28
%37 = call i32 (...) @unintialized_use()
br label %60
38: ; preds = %28
%39 = call i32 (...) @rw_after_free()
br label %60
40: ; preds = %28
%41 = call i32 (...) @rw_malloc_overrun()
br label %60
42: ; preds = %28
%43 = call i32 (...) @rw_bad_stk_location()
br label %60
44: ; preds = %28
%45 = call i32 (...) @mem_leak()
br label %60
46: ; preds = %28
%47 = call i32 (...) @test_6()
br label %60
48: ; preds = %28
%49 = call i32 (...) @memcpy_overlapping_src_dst()
br label %60
50: ; preds = %28
%51 = call i32 (...) @double_free()
br label %60
52: ; preds = %28
%53 = call i32 (...) @systemcall_unaddressable_bytes()
br label %60
54: ; preds = %28
%55 = call i32 (...) @stk_overrun()
br label %60
56: ; preds = %28
%57 = call i32 (...) @glob_buff_overrun()
br label %60
58: ; preds = %28
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %65
60: ; preds = %56, %54, %52, %50, %48, %46, %44, %42, %40, %38, %36
br label %61
61: ; preds = %60
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %24
64: ; preds = %24
store i32 0, i32* %3
br label %65
65: ; preds = %64, %58, %20, %10
%66 = load i32, i32* %3
ret i32 %66
}

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"
@M_CHECK_ACTION = global i32 0
@stderr = global i32 0
@.str.2 = [17 x i8] c"mallopt() failed\00"
@.str.3 = [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 %4, label %8
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %49
8: ; preds = %2
%9 = load i32, i32* @M_CHECK_ACTION
%10 = tail call i32 @mallopt(i32 %9, i32 7)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = zext i32 %0 to i64
br label %17
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %49
17: ; preds = %12, %46
%18 = phi i64 [ 1, %12 ], [ %47, %46 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
switch i32 %21, label %44 [
i32 1, label %22
i32 2, label %24
i32 3, label %26
i32 4, label %28
i32 5, label %30
i32 6, label %32
i32 7, label %34
i32 8, label %36
i32 9, label %38
i32 10, label %40
i32 11, label %42
]
22: ; preds = %17
%23 = tail call i32 (...) @unintialized_use()
br label %46
24: ; preds = %17
%25 = tail call i32 (...) @rw_after_free()
br label %46
26: ; preds = %17
%27 = tail call i32 (...) @rw_malloc_overrun()
br label %46
28: ; preds = %17
%29 = tail call i32 (...) @rw_bad_stk_location()
br label %46
30: ; preds = %17
%31 = tail call i32 (...) @mem_leak()
br label %46
32: ; preds = %17
%33 = tail call i32 (...) @test_6()
br label %46
34: ; preds = %17
%35 = tail call i32 (...) @memcpy_overlapping_src_dst()
br label %46
36: ; preds = %17
%37 = tail call i32 (...) @double_free()
br label %46
38: ; preds = %17
%39 = tail call i32 (...) @systemcall_unaddressable_bytes()
br label %46
40: ; preds = %17
%41 = tail call i32 (...) @stk_overrun()
br label %46
42: ; preds = %17
%43 = tail call i32 (...) @glob_buff_overrun()
br label %46
44: ; preds = %17
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0))
br label %49
46: ; preds = %42, %40, %38, %36, %34, %32, %30, %28, %26, %24, %22
%47 = add nuw nsw i64 %18, 1
%48 = icmp eq i64 %47, %13
br i1 %48, label %49, label %17
49: ; preds = %46, %44, %14, %4
%50 = phi i32 [ -1, %4 ], [ -1, %14 ], [ -1, %44 ], [ 0, %46 ]
ret i32 %50
}