#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*/ _IONBF;
int /*<<< orphan*/ corrupted_consolidate_backward();
int /*<<< orphan*/ corrupted_unsorted_chunks();
int /*<<< orphan*/ double_free_fastbin();
int /*<<< orphan*/ double_free_or_corruption_out();
int /*<<< orphan*/ double_free_or_corruption_prev();
int /*<<< orphan*/ double_free_or_corruption_top();
int /*<<< orphan*/ double_free_tcache();
int /*<<< orphan*/ invalid_fastbin_entry();
int /*<<< orphan*/ invalid_next_size_fast();
int /*<<< orphan*/ invalid_next_size_normal();
int /*<<< orphan*/ invalid_pointer_misaligned();
int /*<<< orphan*/ invalid_pointer_overflow();
int /*<<< orphan*/ invalid_size_minsize();
int /*<<< orphan*/ invalid_size_misaligned();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char const *, char *, int *);
int /*<<< orphan*/ stdout;
int main(int argc, char const *argv[]) {
  setvbuf(stdout, NULL, _IONBF, 0);
  if (argc < 2) {
    printf("Usage: %s bug_to_trigger\n", argv[0]);
    return 1;
  }
  int choice;
  sscanf(argv[1], "%d", &choice);
  switch (choice) {
  case 1:
    invalid_pointer_overflow();
    break;
  case 2:
    invalid_pointer_misaligned();
    break;
  case 3:
    invalid_size_minsize();
    break;
  case 4:
    invalid_size_misaligned();
    break;
  case 5:
    double_free_tcache();
    break;
  case 6:
    invalid_next_size_fast();
    break;
  case 7:
    double_free_fastbin();
    break;
  case 8:
    invalid_fastbin_entry();
    break;
  case 9:
    double_free_or_corruption_top();
    break;
  case 10:
    double_free_or_corruption_out();
    break;
  case 11:
    double_free_or_corruption_prev();
    break;
  case 12:
    invalid_next_size_normal();
    break;
  case 13:
    corrupted_consolidate_backward();
    break;
  case 14:
    corrupted_unsorted_chunks();
    break;
  default:
    printf("Unknown\n");
  }
  puts("END");
  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)
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1110 <setvbuf@plt>
cmpl   $0x2,-0x8(%rbp)
jge    127e <main+0x5e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1388 <main+0x168>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc5(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   10f0 <sscanf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0xd,%eax
ja     1367 <main+0x147>
mov    -0x20(%rbp),%rax
lea    0xd4a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   10a0 <invalid_pointer_overflow@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   10d0 <invalid_pointer_misaligned@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   1030 <invalid_size_minsize@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   10b0 <invalid_size_misaligned@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   1090 <double_free_tcache@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   10c0 <invalid_next_size_fast@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   10e0 <double_free_fastbin@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   1070 <invalid_fastbin_entry@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   1050 <double_free_or_corruption_top@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   1080 <double_free_or_corruption_out@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   1100 <double_free_or_corruption_prev@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   1130 <invalid_next_size_normal@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   1140 <corrupted_consolidate_backward@plt>
jmp    1375 <main+0x155>
mov    $0x0,%al
call   1120 <corrupted_unsorted_chunks@plt>
jmp    1375 <main+0x155>
lea    0xce7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xce2(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1110 <setvbuf@plt>
cmp    $0x1,%ebp
jg     1263 <main+0x43>
mov    (%rbx),%rsi
lea    0xde6(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%eax
jmp    132f <main+0x10f>
mov    0x8(%rbx),%rdi
lea    0xde4(%rip),%rsi
lea    0x4(%rsp),%rdx
call   10f0 <sscanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0xd,%eax
ja     12a0 <main+0x80>
lea    0xd75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
call   10a0 <invalid_pointer_overflow@plt>
jmp    1321 <main+0x101>
lea    0xdb2(%rip),%rdi
call   1040 <puts@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   10d0 <invalid_pointer_misaligned@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   1030 <invalid_size_minsize@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   10b0 <invalid_size_misaligned@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   1090 <double_free_tcache@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   10c0 <invalid_next_size_fast@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   10e0 <double_free_fastbin@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   1070 <invalid_fastbin_entry@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   1050 <double_free_or_corruption_top@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   1080 <double_free_or_corruption_out@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   1100 <double_free_or_corruption_prev@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   1130 <invalid_next_size_normal@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   1140 <corrupted_consolidate_backward@plt>
jmp    1321 <main+0x101>
xor    %eax,%eax
call   1120 <corrupted_unsorted_chunks@plt>
lea    0xd2d(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [26 x i8] c"Usage: %s bug_to_trigger\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"Unknown\0A\00"
@.str.3 = [4 x i8] c"END\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @stdout
%8 = load i32, i32* @_IONBF
%9 = call i32 @setvbuf(i32 %7, i32* null, i32 %8, i32 0)
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %55
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%22 = load i32, i32* %6
switch i32 %22, label %51 [
i32 1, label %23
i32 2, label %25
i32 3, label %27
i32 4, label %29
i32 5, label %31
i32 6, label %33
i32 7, label %35
i32 8, label %37
i32 9, label %39
i32 10, label %41
i32 11, label %43
i32 12, label %45
i32 13, label %47
i32 14, label %49
]
23: ; preds = %17
%24 = call i32 (...) @invalid_pointer_overflow()
br label %53
25: ; preds = %17
%26 = call i32 (...) @invalid_pointer_misaligned()
br label %53
27: ; preds = %17
%28 = call i32 (...) @invalid_size_minsize()
br label %53
29: ; preds = %17
%30 = call i32 (...) @invalid_size_misaligned()
br label %53
31: ; preds = %17
%32 = call i32 (...) @double_free_tcache()
br label %53
33: ; preds = %17
%34 = call i32 (...) @invalid_next_size_fast()
br label %53
35: ; preds = %17
%36 = call i32 (...) @double_free_fastbin()
br label %53
37: ; preds = %17
%38 = call i32 (...) @invalid_fastbin_entry()
br label %53
39: ; preds = %17
%40 = call i32 (...) @double_free_or_corruption_top()
br label %53
41: ; preds = %17
%42 = call i32 (...) @double_free_or_corruption_out()
br label %53
43: ; preds = %17
%44 = call i32 (...) @double_free_or_corruption_prev()
br label %53
45: ; preds = %17
%46 = call i32 (...) @invalid_next_size_normal()
br label %53
47: ; preds = %17
%48 = call i32 (...) @corrupted_consolidate_backward()
br label %53
49: ; preds = %17
%50 = call i32 (...) @corrupted_unsorted_chunks()
br label %53
51: ; preds = %17
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %53
53: ; preds = %51, %49, %47, %45, %43, %41, %39, %37, %35, %33, %31, %29, %27, %25, %23
%54 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %55
55: ; preds = %53, %12
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [26 x i8] c"Usage: %s bug_to_trigger\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"END\00"
@str = [8 x i8] c"Unknown\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = load i32, i32* @stdout
%5 = load i32, i32* @_IONBF
%6 = tail call i32 @setvbuf(i32 %4, i32* null, i32 %5, i32 0)
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %49
11: ; preds = %2
%12 = bitcast i32* %3 to i8*
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
switch i32 %16, label %45 [
i32 1, label %17
i32 2, label %19
i32 3, label %21
i32 4, label %23
i32 5, label %25
i32 6, label %27
i32 7, label %29
i32 8, label %31
i32 9, label %33
i32 10, label %35
i32 11, label %37
i32 12, label %39
i32 13, label %41
i32 14, label %43
]
17: ; preds = %11
%18 = call i32 (...) @invalid_pointer_overflow()
br label %47
19: ; preds = %11
%20 = call i32 (...) @invalid_pointer_misaligned()
br label %47
21: ; preds = %11
%22 = call i32 (...) @invalid_size_minsize()
br label %47
23: ; preds = %11
%24 = call i32 (...) @invalid_size_misaligned()
br label %47
25: ; preds = %11
%26 = call i32 (...) @double_free_tcache()
br label %47
27: ; preds = %11
%28 = call i32 (...) @invalid_next_size_fast()
br label %47
29: ; preds = %11
%30 = call i32 (...) @double_free_fastbin()
br label %47
31: ; preds = %11
%32 = call i32 (...) @invalid_fastbin_entry()
br label %47
33: ; preds = %11
%34 = call i32 (...) @double_free_or_corruption_top()
br label %47
35: ; preds = %11
%36 = call i32 (...) @double_free_or_corruption_out()
br label %47
37: ; preds = %11
%38 = call i32 (...) @double_free_or_corruption_prev()
br label %47
39: ; preds = %11
%40 = call i32 (...) @invalid_next_size_normal()
br label %47
41: ; preds = %11
%42 = call i32 (...) @corrupted_consolidate_backward()
br label %47
43: ; preds = %11
%44 = call i32 (...) @corrupted_unsorted_chunks()
br label %47
45: ; preds = %11
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %47
47: ; preds = %45, %43, %41, %39, %37, %35, %33, %31, %29, %27, %25, %23, %21, %19, %17
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %8
%50 = phi i32 [ 1, %8 ], [ 0, %47 ]
ret i32 %50
}