#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 */
struct Node {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
struct Node *bubbleSort(struct Node *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
struct Node *getLinkedListfromFile(int /*<<< orphan*/ *);
struct Node *insertionSort(struct Node *);
int /*<<< orphan*/ printLinkedList(struct Node *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
struct Node *selectionSort(struct Node *);
int main(int argc, char **argv) {
  FILE *f;
  f = fopen(argv[1], "r");
  struct Node *head = getLinkedListfromFile(f);
  fclose(f);
  printf("Given ");
  printLinkedList(head);
  printf(
      "Sorting operation on LinkedList:\n1. Selection Sort\n2. Bubble Sort\n3. "
      "Insertion Sort\n4. Merge Sort\n5. Quick Sort\nYour choice: ");
  int choice = 0;
  scanf("%d", &choice);
  switch (choice) {
  case 1:
    head = selectionSort(head);
    break;
  case 2:
    head = bubbleSort(head);
    break;
  case 3:
    head = insertionSort(head);
    break;
  default:
    printf("Inavlid Choice");
    return 0;
  }
  printf("\nSorted ");
  printLinkedList(head);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <getLinkedListfromFile@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe27(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <printLinkedList@plt>
lea    0xe19(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
lea    0xe84(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x1,%eax
je     1242 <main+0xb2>
jmp    1220 <main+0x90>
mov    -0x28(%rbp),%eax
sub    $0x2,%eax
je     1254 <main+0xc4>
jmp    1231 <main+0xa1>
mov    -0x28(%rbp),%eax
sub    $0x3,%eax
je     1266 <main+0xd6>
jmp    1278 <main+0xe8>
mov    -0x20(%rbp),%rdi
call   1060 <selectionSort@plt>
mov    %rax,-0x20(%rbp)
jmp    1290 <main+0x100>
mov    -0x20(%rbp),%rdi
call   1070 <bubbleSort@plt>
mov    %rax,-0x20(%rbp)
jmp    1290 <main+0x100>
mov    -0x20(%rbp),%rdi
call   1080 <insertionSort@plt>
mov    %rax,-0x20(%rbp)
jmp    1290 <main+0x100>
lea    0xe0b(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ac <main+0x11c>
lea    0xe02(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <printLinkedList@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
lea    0xe61(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <getLinkedListfromFile@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe41(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   10a0 <printLinkedList@plt>
lea    0xe34(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,0x4(%rsp)
lea    0xe9e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1090 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x3,%eax
je     1210 <main+0x80>
cmp    $0x2,%eax
je     121a <main+0x8a>
cmp    $0x1,%eax
jne    123b <main+0xab>
mov    %r14,%rdi
call   1060 <selectionSort@plt>
jmp    1222 <main+0x92>
mov    %r14,%rdi
call   1080 <insertionSort@plt>
jmp    1222 <main+0x92>
mov    %r14,%rdi
call   1070 <bubbleSort@plt>
mov    %rax,%rbx
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   10a0 <printLinkedList@plt>
jmp    1247 <main+0xb7>
lea    0xe48(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.Node = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [7 x i8] c"Given \00"
@.str.2 = [126 x i8] c"Sorting operation on LinkedList:\0A1. Selection Sort\0A2. Bubble Sort\0A3. Insertion Sort\0A4. Merge Sort\0A5. Quick Sort\0AYour choice: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [15 x i8] c"Inavlid Choice\00"
@.str.5 = [9 x i8] c"\0ASorted \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.Node*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = call %struct.Node* @getLinkedListfromFile(i32* %13)
store %struct.Node* %14, %struct.Node** %7
%15 = load i32*, i32** %6
%16 = call i32 @fclose(i32* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = load %struct.Node*, %struct.Node** %7
%19 = call i32 @printLinkedList(%struct.Node* %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %8
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%22 = load i32, i32* %8
switch i32 %22, label %32 [
i32 1, label %23
i32 2, label %26
i32 3, label %29
]
23: ; preds = %2
%24 = load %struct.Node*, %struct.Node** %7
%25 = call %struct.Node* @selectionSort(%struct.Node* %24)
store %struct.Node* %25, %struct.Node** %7
br label %34
26: ; preds = %2
%27 = load %struct.Node*, %struct.Node** %7
%28 = call %struct.Node* @bubbleSort(%struct.Node* %27)
store %struct.Node* %28, %struct.Node** %7
br label %34
29: ; preds = %2
%30 = load %struct.Node*, %struct.Node** %7
%31 = call %struct.Node* @insertionSort(%struct.Node* %30)
store %struct.Node* %31, %struct.Node** %7
br label %34
32: ; preds = %2
%33 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %38
34: ; preds = %29, %26, %23
%35 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%36 = load %struct.Node*, %struct.Node** %7
%37 = call i32 @printLinkedList(%struct.Node* %36)
store i32 0, i32* %3
br label %38
38: ; preds = %34, %32
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
%struct.Node = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [7 x i8] c"Given \00"
@.str.2 = [126 x i8] c"Sorting operation on LinkedList:\0A1. Selection Sort\0A2. Bubble Sort\0A3. Insertion Sort\0A4. Merge Sort\0A5. Quick Sort\0AYour choice: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [15 x i8] c"Inavlid Choice\00"
@.str.5 = [9 x i8] c"\0ASorted \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call %struct.Node* @getLinkedListfromFile(i32* %6)
%8 = tail call i32 @fclose(i32* %6)
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @printLinkedList(%struct.Node* %7)
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([126 x i8], [126 x i8]* @.str.2, i64 0, i64 0))
%12 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%14 = load i32, i32* %3
switch i32 %14, label %21 [
i32 1, label %15
i32 2, label %17
i32 3, label %19
]
15: ; preds = %2
%16 = call %struct.Node* @selectionSort(%struct.Node* %7)
br label %23
17: ; preds = %2
%18 = call %struct.Node* @bubbleSort(%struct.Node* %7)
br label %23
19: ; preds = %2
%20 = call %struct.Node* @insertionSort(%struct.Node* %7)
br label %23
21: ; preds = %2
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %27
23: ; preds = %19, %17, %15
%24 = phi %struct.Node* [ %20, %19 ], [ %18, %17 ], [ %16, %15 ]
%25 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @printLinkedList(%struct.Node* %24)
br label %27
27: ; preds = %23, %21
ret i32 0
}