#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*/ 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_desordered_elements() {
  int array[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  int tam = 10;
  printArray("Original 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_desordered_elements>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x50(%rbp),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x50,%edx
call   1050 <memcpy@plt>
movl   $0xa,-0x54(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xec1(%rip),%rdi
call   1070 <printArray@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    $0xb,%edx
call   1040 <search@plt>
mov    %eax,%esi
lea    0xeb3(%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    0xebb(%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    0xec2(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    $0xb,%edx
call   1060 <searchR@plt>
mov    %eax,%esi
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    $0x1,%edx
call   1060 <searchR@plt>
mov    %eax,%esi
lea    0xedc(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    $0xa,%edx
call   1060 <searchR@plt>
mov    %eax,%esi
lea    0xeed(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x54(%rbp),%edx
mov    $0xb,%ecx
call   1080 <search_from_tail@plt>
mov    %eax,%esi
lea    0xefc(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x54(%rbp),%edx
mov    $0x1,%ecx
call   1080 <search_from_tail@plt>
mov    %eax,%esi
lea    0xf15(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x54(%rbp),%edx
mov    $0xa,%ecx
call   1080 <search_from_tail@plt>
mov    %eax,%esi
lea    0xf2d(%rip),%rdi
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_desordered_elements>:
push   %rbx
sub    $0x50,%rsp
movaps 0xee4(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe90(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe74(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeb9(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1060 <printArray@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0xb,%edx
call   1040 <search@plt>
lea    0xea6(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x1,%edx
call   1040 <search@plt>
lea    0xead(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0xa,%edx
call   1040 <search@plt>
lea    0xeb3(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0xb,%edx
call   1050 <searchR@plt>
lea    0xeba(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x1,%edx
call   1050 <searchR@plt>
lea    0xecb(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0xa,%edx
call   1050 <searchR@plt>
lea    0xedb(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0xa,%edx
mov    $0xb,%ecx
call   1070 <search_from_tail@plt>
lea    0xee7(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0xa,%edx
mov    $0x1,%ecx
call   1070 <search_from_tail@plt>
lea    0xefd(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0xa,%edx
mov    $0xa,%ecx
call   1070 <search_from_tail@plt>
lea    0xf12(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_desordered_elements.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 10], [10 x i32] zeroinitializer }>
@.str = [17 x i8] c"Original Array: \00"
@.str.1 = [39 x i8] c"[search] Looking for 11, returned: %d\0A\00"
@.str.2 = [38 x i8] c"[search] Looking for 1, returned: %d\0A\00"
@.str.3 = [39 x i8] c"[search] Looking for 10, returned: %d\0A\00"
@.str.4 = [49 x i8] c"[recursive search] Looking for 11, returned: %d\0A\00"
@.str.5 = [48 x i8] c"[recursive search] Looking for 1, returned: %d\0A\00"
@.str.6 = [49 x i8] c"[recursive search] Looking for 10, returned: %d\0A\00"
@.str.7 = [59 x i8] c"[search recursive from tail] Looking for 11, returned: %d\0A\00"
@.str.8 = [58 x i8] c"[search recursive from tail] Looking for 1, returned: %d\0A\00"
@.str.9 = [59 x i8] c"[search recursive from tail] Looking for 10, returned: %d\0A\00"
define void @test_desordered_elements() {
%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 = load i32, i32* %2
%8 = call i32 @search(i32* %6, i32 %7, i32 11)
%9 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 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 = load i32, i32* %2
%12 = call i32 @search(i32* %10, i32 %11, i32 1)
%13 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 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 10)
%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 @searchR(i32* %18, i32 %19, i32 11)
%21 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 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 @searchR(i32* %22, i32 %23, i32 1)
%25 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 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 10)
%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 = load i32, i32* %2
%33 = call i32 @search_from_tail(i32* %30, i32 %31, i32 %32, i32 11)
%34 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.7, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%36 = load i32, i32* %2
%37 = load i32, i32* %2
%38 = call i32 @search_from_tail(i32* %35, i32 %36, i32 %37, i32 1)
%39 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.8, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%41 = load i32, i32* %2
%42 = load i32, i32* %2
%43 = call i32 @search_from_tail(i32* %40, i32 %41, i32 %42, i32 10)
%44 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.9, i64 0, i64 0), i32 %43)
ret void
}

LLVM IR (-O2):
@__const.test_desordered_elements.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 10], [10 x i32] zeroinitializer }>
@.str = [17 x i8] c"Original Array: \00"
@.str.1 = [39 x i8] c"[search] Looking for 11, returned: %d\0A\00"
@.str.2 = [38 x i8] c"[search] Looking for 1, returned: %d\0A\00"
@.str.3 = [39 x i8] c"[search] Looking for 10, returned: %d\0A\00"
@.str.4 = [49 x i8] c"[recursive search] Looking for 11, returned: %d\0A\00"
@.str.5 = [48 x i8] c"[recursive search] Looking for 1, returned: %d\0A\00"
@.str.6 = [49 x i8] c"[recursive search] Looking for 10, returned: %d\0A\00"
@.str.7 = [59 x i8] c"[search recursive from tail] Looking for 11, returned: %d\0A\00"
@.str.8 = [58 x i8] c"[search recursive from tail] Looking for 1, returned: %d\0A\00"
@.str.9 = [59 x i8] c"[search recursive from tail] Looking for 10, returned: %d\0A\00"
define void @test_desordered_elements() {
%1 = alloca [20 x i32]
%2 = bitcast [20 x i32]* %1 to i8*
%3 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%4 = call i32 @printArray(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %3)
%5 = call i32 @search(i32* %3, i32 10, i32 11)
%6 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = call i32 @search(i32* %3, i32 10, i32 1)
%8 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = call i32 @search(i32* %3, i32 10, i32 10)
%10 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = call i32 @searchR(i32* %3, i32 10, i32 11)
%12 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = call i32 @searchR(i32* %3, i32 10, i32 1)
%14 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 %13)
%15 = call i32 @searchR(i32* %3, i32 10, i32 10)
%16 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i32 %15)
%17 = call i32 @search_from_tail(i32* %3, i32 10, i32 10, i32 11)
%18 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.7, i64 0, i64 0), i32 %17)
%19 = call i32 @search_from_tail(i32* %3, i32 10, i32 10, i32 1)
%20 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.8, i64 0, i64 0), i32 %19)
%21 = call i32 @search_from_tail(i32* %3, i32 10, i32 10, i32 10)
%22 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.9, i64 0, i64 0), i32 %21)
ret void
}