#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*/ append_and_sort(int **, int *, int);
int /*<<< orphan*/ insertion_sort_from_front(int **, int *, int);
int /*<<< orphan*/ insertion_sort_from_tail(int **, int *, int /*<<< orphan*/);
int /*<<< orphan*/ insertion_sort_full_array(int *);
int /*<<< orphan*/ insertion_sort_partial_array(int *, int);
int /*<<< orphan*/ printArray(char *, int *);
int /*<<< orphan*/ printf(char *, int);
int remove_element(int **, int *, int /*<<< orphan*/);
int main() {
  int array[20] = {19, 18, 17, 16, 15, 14, 13, 12, 11, 20,
                   1,  2,  3,  4,  5,  6,  7,  8,  9,  10};
  int array2[20] = {19, 18, 15, 13, 20, 1, 3, 4, 7, 8, 9, 10};
  int tam = 12;
  printArray("[full] Original Array: ", array);
  insertion_sort_full_array(array);
  printArray("[full] sorted Array: ", array);
  printArray("[partial] Original Array: ", array2);
  insertion_sort_partial_array(array2, tam);
  printArray("[partial] sorted Array: ", array2);
  append_and_sort(&array2, &tam, 99);
  printArray("added 99 to Array: ", array2);
  insertion_sort_from_tail(&array2, &tam, 0);
  printArray("added 0 to Array: ", array2);
  insertion_sort_from_front(&array2, &tam, 100);
  printArray("added 100 to Array: ", array2);
  printf(("Removed 0 from i[%d]"), remove_element(&array2, &tam, 0));
  printArray("Removed 0 from Array: ", array2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe53(%rip),%rsi
mov    $0x50,%edx
call   1060 <memcpy@plt>
lea    -0xb0(%rbp),%rdi
lea    0xe8b(%rip),%rsi
mov    $0x50,%edx
call   1060 <memcpy@plt>
movl   $0xc,-0xb4(%rbp)
lea    -0x60(%rbp),%rsi
lea    0xebc(%rip),%rdi
call   10a0 <printArray@plt>
lea    -0x60(%rbp),%rdi
call   1080 <insertion_sort_full_array@plt>
lea    -0x60(%rbp),%rsi
lea    0xebb(%rip),%rdi
call   10a0 <printArray@plt>
lea    -0xb0(%rbp),%rsi
lea    0xebe(%rip),%rdi
call   10a0 <printArray@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
call   1030 <insertion_sort_partial_array@plt>
lea    -0xb0(%rbp),%rsi
lea    0xeb4(%rip),%rdi
call   10a0 <printArray@plt>
lea    -0xb0(%rbp),%rdi
lea    -0xb4(%rbp),%rsi
mov    $0x63,%edx
call   1070 <append_and_sort@plt>
lea    -0xb0(%rbp),%rsi
lea    0xea2(%rip),%rdi
call   10a0 <printArray@plt>
lea    -0xb0(%rbp),%rdi
lea    -0xb4(%rbp),%rsi
xor    %edx,%edx
call   1050 <insertion_sort_from_tail@plt>
lea    -0xb0(%rbp),%rsi
lea    0xe8e(%rip),%rdi
call   10a0 <printArray@plt>
lea    -0xb0(%rbp),%rdi
lea    -0xb4(%rbp),%rsi
mov    $0x64,%edx
call   1090 <insertion_sort_from_front@plt>
lea    -0xb0(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   10a0 <printArray@plt>
lea    -0xb0(%rbp),%rdi
lea    -0xb4(%rbp),%rsi
xor    %edx,%edx
call   10b0 <remove_element@plt>
mov    %eax,%esi
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   10a0 <printArray@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xb8,%rsp
movaps 0xeaf(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xe90(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xe71(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe52(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe36(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe9e(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe82(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe66(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe4a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0xc,0xc(%rsp)
lea    0xe86(%rip),%rdi
lea    0x60(%rsp),%rbx
mov    %rbx,%rsi
call   1090 <printArray@plt>
mov    %rbx,%rdi
call   1070 <insertion_sort_full_array@plt>
lea    0xe82(%rip),%rdi
mov    %rbx,%rsi
call   1090 <printArray@plt>
lea    0xe89(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1090 <printArray@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1030 <insertion_sort_partial_array@plt>
lea    0xe83(%rip),%rdi
mov    %rbx,%rsi
call   1090 <printArray@plt>
lea    0xc(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x63,%edx
call   1060 <append_and_sort@plt>
lea    0xe78(%rip),%rdi
mov    %rbx,%rsi
call   1090 <printArray@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <insertion_sort_from_tail@plt>
lea    0xe70(%rip),%rdi
mov    %rbx,%rsi
call   1090 <printArray@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x64,%edx
call   1080 <insertion_sort_from_front@plt>
lea    0xe64(%rip),%rdi
mov    %rbx,%rsi
call   1090 <printArray@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   10a0 <remove_element@plt>
lea    0xe5d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xe64(%rip),%rdi
mov    %rbx,%rsi
call   1090 <printArray@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.array = [20 x i32] [i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 20, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
@__const.main.array2 = <{ [12 x i32], [8 x i32] }> <{ [12 x i32] [i32 19, i32 18, i32 15, i32 13, i32 20, i32 1, i32 3, i32 4, i32 7, i32 8, i32 9, i32 10], [8 x i32] zeroinitializer }>
@.str = [24 x i8] c"[full] Original Array: \00"
@.str.1 = [22 x i8] c"[full] sorted Array: \00"
@.str.2 = [27 x i8] c"[partial] Original Array: \00"
@.str.3 = [25 x i8] c"[partial] sorted Array: \00"
@.str.4 = [20 x i8] c"added 99 to Array: \00"
@.str.5 = [19 x i8] c"added 0 to Array: \00"
@.str.6 = [21 x i8] c"added 100 to Array: \00"
@.str.7 = [21 x i8] c"Removed 0 from i[%d]\00"
@.str.8 = [23 x i8] c"Removed 0 from Array: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = alloca [20 x i32]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [20 x i32]* %2 to i8*
%6 = bitcast [20 x i32]* %3 to i8*
store i32 12, i32* %4
%7 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%8 = call i32 @printArray(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32* %7)
%9 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%10 = call i32 @insertion_sort_full_array(i32* %9)
%11 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%12 = call i32 @printArray(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32* %11)
%13 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%14 = call i32 @printArray(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32* %13)
%15 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%16 = load i32, i32* %4
%17 = call i32 @insertion_sort_partial_array(i32* %15, i32 %16)
%18 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%19 = call i32 @printArray(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32* %18)
%20 = bitcast [20 x i32]* %3 to i32**
%21 = call i32 @append_and_sort(i32** %20, i32* %4, i32 99)
%22 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%23 = call i32 @printArray(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32* %22)
%24 = bitcast [20 x i32]* %3 to i32**
%25 = call i32 @insertion_sort_from_tail(i32** %24, i32* %4, i32 0)
%26 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%27 = call i32 @printArray(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32* %26)
%28 = bitcast [20 x i32]* %3 to i32**
%29 = call i32 @insertion_sort_from_front(i32** %28, i32* %4, i32 100)
%30 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%31 = call i32 @printArray(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32* %30)
%32 = bitcast [20 x i32]* %3 to i32**
%33 = call i32 @remove_element(i32** %32, i32* %4, i32 0)
%34 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%36 = call i32 @printArray(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32* %35)
ret i32 0
}

LLVM IR (-O2):
@__const.main.array = [20 x i32] [i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 20, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
@__const.main.array2 = <{ [12 x i32], [8 x i32] }> <{ [12 x i32] [i32 19, i32 18, i32 15, i32 13, i32 20, i32 1, i32 3, i32 4, i32 7, i32 8, i32 9, i32 10], [8 x i32] zeroinitializer }>
@.str = [24 x i8] c"[full] Original Array: \00"
@.str.1 = [22 x i8] c"[full] sorted Array: \00"
@.str.2 = [27 x i8] c"[partial] Original Array: \00"
@.str.3 = [25 x i8] c"[partial] sorted Array: \00"
@.str.4 = [20 x i8] c"added 99 to Array: \00"
@.str.5 = [19 x i8] c"added 0 to Array: \00"
@.str.6 = [21 x i8] c"added 100 to Array: \00"
@.str.7 = [21 x i8] c"Removed 0 from i[%d]\00"
@.str.8 = [23 x i8] c"Removed 0 from Array: \00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = alloca [20 x i32]
%3 = alloca i32
%4 = bitcast [20 x i32]* %1 to i8*
%5 = bitcast [20 x i32]* %2 to i8*
%6 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%7 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%8 = call i32 @printArray(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32* %7)
%9 = call i32 @insertion_sort_full_array(i32* %7)
%10 = call i32 @printArray(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%11 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%12 = call i32 @printArray(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32* %11)
%13 = call i32 @insertion_sort_partial_array(i32* %11, i32 12)
%14 = call i32 @printArray(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32* %11)
%15 = bitcast [20 x i32]* %2 to i32**
%16 = call i32 @append_and_sort(i32** %15, i32* %3, i32 99)
%17 = call i32 @printArray(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32* %11)
%18 = call i32 @insertion_sort_from_tail(i32** %15, i32* %3, i32 0)
%19 = call i32 @printArray(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32* %11)
%20 = call i32 @insertion_sort_from_front(i32** %15, i32* %3, i32 100)
%21 = call i32 @printArray(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32* %11)
%22 = call i32 @remove_element(i32** %15, i32* %3, i32 0)
%23 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %22)
%24 = call i32 @printArray(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32* %11)
ret i32 0
}