#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*/ insert(int *, int *, int);
int /*<<< orphan*/ insert_recursive(int *, int *, int);
int /*<<< orphan*/ printArray(char *, int *);
int /*<<< orphan*/ printf(char *, int);
int search(int *, int, int);
int searchR(int *, int, int);
int search_from_tail(int *, int, int, int);
void test_sorted() {
  int array[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 12};
  int tam = 10;
  printArray("Original Array: ", array);
  insert(array, &tam, 11);
  printArray("added 11 to array: ", array);
  insert_recursive(array, &tam, 10);
  printArray("added 10 to array: ", array);
  printf(("[search] Looking for 11, returned: %d\n"), search(array, tam, 11));
  printf(("[search] Looking for 1, returned: %d\n"), search(array, tam, 1));
  printf(("[search] Looking for 10, returned: %d\n"), search(array, tam, 10));
  printf(("[recursive search] Looking for 11, returned: %d\n"),
         searchR(array, tam, 11));
  printf(("[recursive search] Looking for 1, returned: %d\n"),
         searchR(array, tam, 1));
  printf(("[recursive search] Looking for 10, returned: %d\n"),
         searchR(array, tam, 10));
  printf(("[search recursive from tail] Looking for 11, returned: %d\n"),
         search_from_tail(array, tam, tam, 11));
  printf(("[search recursive from tail] Looking for 1, returned: %d\n"),
         search_from_tail(array, tam, tam, 1));
  printf(("[search recursive from tail] Looking for 10, returned: %d\n"),
         search_from_tail(array, tam, tam, 10));
}


x86 assembly (clang, -O0):
<test_sorted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x50(%rbp),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x50,%edx
call   1050 <memcpy@plt>
movl   $0xa,-0x54(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xea1(%rip),%rdi
call   1080 <printArray@plt>
lea    -0x50(%rbp),%rdi
lea    -0x54(%rbp),%rsi
mov    $0xb,%edx
call   1060 <insert@plt>
lea    -0x50(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1080 <printArray@plt>
lea    -0x50(%rbp),%rdi
lea    -0x54(%rbp),%rsi
mov    $0xa,%edx
call   10a0 <insert_recursive@plt>
lea    -0x50(%rbp),%rsi
lea    0xe82(%rip),%rdi
call   1080 <printArray@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    $0xb,%edx
call   1040 <search@plt>
mov    %eax,%esi
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    $0x1,%edx
call   1040 <search@plt>
mov    %eax,%esi
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    $0xa,%edx
call   1040 <search@plt>
mov    %eax,%esi
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    $0xb,%edx
call   1070 <searchR@plt>
mov    %eax,%esi
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    $0x1,%edx
call   1070 <searchR@plt>
mov    %eax,%esi
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    $0xa,%edx
call   1070 <searchR@plt>
mov    %eax,%esi
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x54(%rbp),%edx
mov    $0xb,%ecx
call   1090 <search_from_tail@plt>
mov    %eax,%esi
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x54(%rbp),%edx
mov    $0x1,%ecx
call   1090 <search_from_tail@plt>
mov    %eax,%esi
lea    0xed9(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x54(%rbp),%edx
mov    $0xa,%ecx
call   1090 <search_from_tail@plt>
mov    %eax,%esi
lea    0xef1(%rip),%rdi
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sorted>:
push   %r14
push   %rbx
sub    $0x68,%rsp
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe8a(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe6e(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe52(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0xa,0xc(%rsp)
lea    0xe8e(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1070 <printArray@plt>
lea    0xc(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xb,%edx
call   1050 <insert@plt>
lea    0xe76(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printArray@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1090 <insert_recursive@plt>
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printArray@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0xb,%edx
call   1040 <search@plt>
lea    0xe5f(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1040 <search@plt>
lea    0xe67(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <search@plt>
lea    0xe6e(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0xb,%edx
call   1060 <searchR@plt>
lea    0xe76(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1060 <searchR@plt>
lea    0xe88(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1060 <searchR@plt>
lea    0xe99(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %edx,%esi
mov    $0xb,%ecx
call   1080 <search_from_tail@plt>
lea    0xea9(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %edx,%esi
mov    $0x1,%ecx
call   1080 <search_from_tail@plt>
lea    0xec3(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %edx,%esi
mov    $0xa,%ecx
call   1080 <search_from_tail@plt>
lea    0xedc(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.test_sorted.array = <{ [10 x i32], [10 x i32] }> <{ [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 12], [10 x i32] zeroinitializer }>
@.str = [17 x i8] c"Original Array: \00"
@.str.1 = [20 x i8] c"added 11 to array: \00"
@.str.2 = [20 x i8] c"added 10 to array: \00"
@.str.3 = [39 x i8] c"[search] Looking for 11, returned: %d\0A\00"
@.str.4 = [38 x i8] c"[search] Looking for 1, returned: %d\0A\00"
@.str.5 = [39 x i8] c"[search] Looking for 10, returned: %d\0A\00"
@.str.6 = [49 x i8] c"[recursive search] Looking for 11, returned: %d\0A\00"
@.str.7 = [48 x i8] c"[recursive search] Looking for 1, returned: %d\0A\00"
@.str.8 = [49 x i8] c"[recursive search] Looking for 10, returned: %d\0A\00"
@.str.9 = [59 x i8] c"[search recursive from tail] Looking for 11, returned: %d\0A\00"
@.str.10 = [58 x i8] c"[search recursive from tail] Looking for 1, returned: %d\0A\00"
@.str.11 = [59 x i8] c"[search recursive from tail] Looking for 10, returned: %d\0A\00"
define void @test_sorted() {
%1 = alloca [20 x i32]
%2 = alloca i32
%3 = bitcast [20 x i32]* %1 to i8*
store i32 10, i32* %2
%4 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%5 = call i32 @printArray(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %4)
%6 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%7 = call i32 @insert(i32* %6, i32* %2, i32 11)
%8 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%9 = call i32 @printArray(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%10 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%11 = call i32 @insert_recursive(i32* %10, i32* %2, i32 10)
%12 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%13 = call i32 @printArray(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32* %12)
%14 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%15 = load i32, i32* %2
%16 = call i32 @search(i32* %14, i32 %15, i32 11)
%17 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%19 = load i32, i32* %2
%20 = call i32 @search(i32* %18, i32 %19, i32 1)
%21 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%23 = load i32, i32* %2
%24 = call i32 @search(i32* %22, i32 %23, i32 10)
%25 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%27 = load i32, i32* %2
%28 = call i32 @searchR(i32* %26, i32 %27, i32 11)
%29 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%31 = load i32, i32* %2
%32 = call i32 @searchR(i32* %30, i32 %31, i32 1)
%33 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.7, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%35 = load i32, i32* %2
%36 = call i32 @searchR(i32* %34, i32 %35, i32 10)
%37 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%39 = load i32, i32* %2
%40 = load i32, i32* %2
%41 = call i32 @search_from_tail(i32* %38, i32 %39, i32 %40, i32 11)
%42 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.9, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%44 = load i32, i32* %2
%45 = load i32, i32* %2
%46 = call i32 @search_from_tail(i32* %43, i32 %44, i32 %45, i32 1)
%47 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.10, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%49 = load i32, i32* %2
%50 = load i32, i32* %2
%51 = call i32 @search_from_tail(i32* %48, i32 %49, i32 %50, i32 10)
%52 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.11, i64 0, i64 0), i32 %51)
ret void
}

LLVM IR (-O2):
@__const.test_sorted.array = <{ [10 x i32], [10 x i32] }> <{ [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 12], [10 x i32] zeroinitializer }>
@.str = [17 x i8] c"Original Array: \00"
@.str.1 = [20 x i8] c"added 11 to array: \00"
@.str.2 = [20 x i8] c"added 10 to array: \00"
@.str.3 = [39 x i8] c"[search] Looking for 11, returned: %d\0A\00"
@.str.4 = [38 x i8] c"[search] Looking for 1, returned: %d\0A\00"
@.str.5 = [39 x i8] c"[search] Looking for 10, returned: %d\0A\00"
@.str.6 = [49 x i8] c"[recursive search] Looking for 11, returned: %d\0A\00"
@.str.7 = [48 x i8] c"[recursive search] Looking for 1, returned: %d\0A\00"
@.str.8 = [49 x i8] c"[recursive search] Looking for 10, returned: %d\0A\00"
@.str.9 = [59 x i8] c"[search recursive from tail] Looking for 11, returned: %d\0A\00"
@.str.10 = [58 x i8] c"[search recursive from tail] Looking for 1, returned: %d\0A\00"
@.str.11 = [59 x i8] c"[search recursive from tail] Looking for 10, returned: %d\0A\00"
define void @test_sorted() {
%1 = alloca [20 x i32]
%2 = alloca i32
%3 = bitcast [20 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 10, i32* %2
%5 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%6 = call i32 @printArray(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %5)
%7 = call i32 @insert(i32* %5, i32* %2, i32 11)
%8 = call i32 @printArray(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%9 = call i32 @insert_recursive(i32* %5, i32* %2, i32 10)
%10 = call i32 @printArray(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%11 = load i32, i32* %2
%12 = call i32 @search(i32* %5, i32 %11, i32 11)
%13 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %2
%15 = call i32 @search(i32* %5, i32 %14, i32 1)
%16 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %2
%18 = call i32 @search(i32* %5, i32 %17, i32 10)
%19 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %2
%21 = call i32 @searchR(i32* %5, i32 %20, i32 11)
%22 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @searchR(i32* %5, i32 %23, i32 1)
%25 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.7, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %2
%27 = call i32 @searchR(i32* %5, i32 %26, i32 10)
%28 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %2
%30 = call i32 @search_from_tail(i32* %5, i32 %29, i32 %29, i32 11)
%31 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.9, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %2
%33 = call i32 @search_from_tail(i32* %5, i32 %32, i32 %32, i32 1)
%34 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.10, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %2
%36 = call i32 @search_from_tail(i32* %5, i32 %35, i32 %35, i32 10)
%37 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.11, i64 0, i64 0), i32 %36)
ret void
}