#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*/ bubble_sort(int *, int /*<<< orphan*/);
int /*<<< orphan*/ merge_sort(int *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ quick_sort(int *, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char const *argv[]) {
  printf("Given N number: ");
  int N;
  scanf("%d", &N);
  int num[1000];
  printf("Input: ");
  int i;
  for (i = 0; i < N; ++i)
    scanf("%d", num + i);
  printf("0: bubble, 1: quick, 2: merge : ");
  int way;
  scanf("%d", &way);
  switch (way) {
  case 0:
    printf("Bubble sort\n");
    bubble_sort(num, num + N - 1);
    break;
  case 1:
    printf("Quick sort\n");
    quick_sort(num, num + N - 1);
    break;
  case 2:
    printf("Merge sort\n");
    merge_sort(num, num + N - 1);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
lea    0xe95(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xfc4(%rbp)
mov    -0xfc4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11df <main+0x8f>
lea    -0xfc0(%rbp),%rsi
movslq -0xfc4(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe4b(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xfc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfc4(%rbp)
jmp    119b <main+0x4b>
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
lea    0xe1f(%rip),%rdi
lea    -0xfc8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xfc8(%rbp),%eax
mov    %eax,-0xfcc(%rbp)
test   %eax,%eax
je     123f <main+0xef>
jmp    1217 <main+0xc7>
mov    -0xfcc(%rbp),%eax
sub    $0x1,%eax
je     1274 <main+0x124>
jmp    122b <main+0xdb>
mov    -0xfcc(%rbp),%eax
sub    $0x2,%eax
je     12a9 <main+0x159>
jmp    12d9 <main+0x189>
lea    0xdf7(%rip),%rdi
call   1030 <printf@plt>
lea    -0xfc0(%rbp),%rdi
lea    -0xfc0(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
add    $0xfffffffffffffffc,%rax
mov    %eax,%esi
call   1070 <bubble_sort@plt>
jmp    12d9 <main+0x189>
lea    0xdcf(%rip),%rdi
call   1030 <printf@plt>
lea    -0xfc0(%rbp),%rdi
lea    -0xfc0(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
add    $0xfffffffffffffffc,%rax
mov    %eax,%esi
call   1060 <quick_sort@plt>
jmp    12d9 <main+0x189>
lea    0xda6(%rip),%rdi
call   1030 <printf@plt>
lea    -0xfc0(%rbp),%rdi
lea    -0xfc0(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
add    $0xfffffffffffffffc,%rax
mov    %eax,%esi
call   1040 <merge_sort@plt>
xor    %eax,%eax
add    $0xfd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xfb0,%rsp
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe92(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11cd <main+0x6d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe67(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     11b0 <main+0x50>
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
lea    0xe31(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
je     121e <main+0xbe>
cmp    $0x1,%eax
je     1240 <main+0xe0>
test   %eax,%eax
jne    1260 <main+0x100>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%eax
lea    0x10(%rsp),%rdi
lea    (%rdi,%rax,4),%esi
add    $0xfffffffc,%esi
call   1080 <bubble_sort@plt>
jmp    1260 <main+0x100>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%eax
lea    0x10(%rsp),%rdi
lea    (%rdi,%rax,4),%esi
add    $0xfffffffc,%esi
call   1050 <merge_sort@plt>
jmp    1260 <main+0x100>
lea    0xe01(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%eax
lea    0x10(%rsp),%rdi
lea    (%rdi,%rax,4),%esi
add    $0xfffffffc,%esi
call   1070 <quick_sort@plt>
xor    %eax,%eax
add    $0xfb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Given N number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"Input: \00"
@.str.3 = [33 x i8] c"0: bubble, 1: quick, 2: merge : \00"
@.str.4 = [13 x i8] c"Bubble sort\0A\00"
@.str.5 = [12 x i8] c"Quick sort\0A\00"
@.str.6 = [12 x i8] c"Merge sort\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1000 x i32]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%12 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %8
br label %13
13: ; preds = %23, %2
%14 = load i32, i32* %8
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 0
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %21)
br label %23
23: ; preds = %17
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %13
26: ; preds = %13
%27 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%29 = load i32, i32* %9
switch i32 %29, label %60 [
i32 0, label %30
i32 1, label %40
i32 2, label %50
]
30: ; preds = %26
%31 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%32 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 0
%33 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 0
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = getelementptr inbounds i32, i32* %36, i64 -1
%38 = ptrtoint i32* %37 to i32
%39 = call i32 @bubble_sort(i32* %32, i32 %38)
br label %60
40: ; preds = %26
%41 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%42 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 0
%43 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 0
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = getelementptr inbounds i32, i32* %46, i64 -1
%48 = ptrtoint i32* %47 to i32
%49 = call i32 @quick_sort(i32* %42, i32 %48)
br label %60
50: ; preds = %26
%51 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%52 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 0
%53 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 0
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = getelementptr inbounds i32, i32* %56, i64 -1
%58 = ptrtoint i32* %57 to i32
%59 = call i32 @merge_sort(i32* %52, i32 %58)
br label %60
60: ; preds = %26, %50, %40, %30
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"Given N number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"Input: \00"
@.str.3 = [33 x i8] c"0: bubble, 1: quick, 2: merge : \00"
@str = [11 x i8] c"Merge sort\00"
@str.7 = [11 x i8] c"Quick sort\00"
@str.8 = [12 x i8] c"Bubble sort\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [1000 x i32]
%5 = alloca i32
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = bitcast i32* %3 to i8*
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = bitcast [1000 x i32]* %4 to i8*
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %2, %13
%14 = phi i64 [ %17, %13 ], [ 0, %2 ]
%15 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %14
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%17 = add nuw nsw i64 %14, 1
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %13, label %21
21: ; preds = %13, %2
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%23 = bitcast i32* %5 to i8*
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%25 = load i32, i32* %5
switch i32 %25, label %56 [
i32 0, label %26
i32 1, label %36
i32 2, label %46
]
26: ; preds = %21
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
%28 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 0
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %30
%32 = getelementptr inbounds i32, i32* %31, i64 -1
%33 = ptrtoint i32* %32 to i64
%34 = trunc i64 %33 to i32
%35 = call i32 @bubble_sort(i32* %28, i32 %34)
br label %56
36: ; preds = %21
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.7, i64 0, i64 0))
%38 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 0
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %40
%42 = getelementptr inbounds i32, i32* %41, i64 -1
%43 = ptrtoint i32* %42 to i64
%44 = trunc i64 %43 to i32
%45 = call i32 @quick_sort(i32* %38, i32 %44)
br label %56
46: ; preds = %21
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%48 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 0
%49 = load i32, i32* %3
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %50
%52 = getelementptr inbounds i32, i32* %51, i64 -1
%53 = ptrtoint i32* %52 to i64
%54 = trunc i64 %53 to i32
%55 = call i32 @merge_sort(i32* %48, i32 %54)
br label %56
56: ; preds = %21, %46, %36, %26
ret i32 0
}