#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 */
typedef int /*<<< orphan*/ testArray2;
typedef int /*<<< orphan*/ testArray1;
typedef int /*<<< orphan*/ testArray;

/* Variables and functions */
int /*<<< orphan*/ arrayPrint(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int search(int *, int /*<<< orphan*/, int, int);
int main(void) {
  printf("Test case 1:\n");
  int x = 5;
  int testArray[] = {4, 5, 6, 7, 1, 2, 3};
  arrayPrint(testArray, sizeof(testArray) / sizeof(int));
  printf("Index of element %i is %i\n", x,
         search(testArray, 0, sizeof(testArray) / sizeof(int) - 1, x));
  printf("\nTest case 2:\n");
  x = 4;
  int testArray1[] = {3, 3, 3, 4, 5, 3};
  arrayPrint(testArray1, sizeof(testArray1) / sizeof(int));
  printf("Index of element %i is %i\n", x,
         search(testArray1, 0, sizeof(testArray1) / sizeof(int) - 1, x));
  printf("\nTest case 3:\n");
  x = 10;
  int testArray2[] = {20, 30, 40, 50, 60, 10};
  arrayPrint(testArray2, sizeof(testArray2) / sizeof(int));
  printf("Index of element %i is %i\n", x,
         search(testArray2, 0, sizeof(testArray2) / sizeof(int) - 1, x));
  x = 20;
  printf("Index of element %i is %i\n", x,
         search(testArray2, 0, sizeof(testArray2) / sizeof(int) - 1, x));
  x = 30;
  printf("Index of element %i is %i\n", x,
         search(testArray2, 0, sizeof(testArray2) / sizeof(int) - 1, x));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x5,-0x8(%rbp)
mov    0xef2(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeef(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeec(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeea(%rip),%eax
mov    %eax,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x7,%esi
call   1030 <arrayPrint@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x84(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%ecx
xor    %esi,%esi
mov    $0x6,%edx
call   1050 <search@plt>
mov    -0x84(%rbp),%esi
mov    %eax,%edx
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x4,-0x8(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe90(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe8d(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x6,%esi
call   1030 <arrayPrint@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x80(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%ecx
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <search@plt>
mov    -0x80(%rbp),%esi
mov    %eax,%edx
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xa,-0x8(%rbp)
mov    0xe43(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0xe40(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    0xe3d(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x6,%esi
call   1030 <arrayPrint@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x7c(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%ecx
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <search@plt>
mov    -0x7c(%rbp),%esi
mov    %eax,%edx
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x14,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%ecx
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <search@plt>
mov    -0x78(%rbp),%esi
mov    %eax,%edx
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1e,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%ecx
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <search@plt>
mov    -0x74(%rbp),%esi
mov    %eax,%edx
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xf25(%rip),%rdi
call   1030 <puts@plt>
movups 0xeb2(%rip),%xmm0
movups %xmm0,0x4c(%rsp)
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1040 <arrayPrint@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x6,%edx
mov    $0x5,%ecx
call   1060 <search@plt>
lea    0xec0(%rip),%r14
mov    %r14,%rdi
mov    $0x5,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed0(%rip),%rdi
call   1030 <puts@plt>
mov    0xe74(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xe58(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x6,%esi
call   1040 <arrayPrint@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
mov    $0x4,%ecx
call   1060 <search@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    0xe39(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0xe1d(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x6,%esi
call   1040 <arrayPrint@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
mov    $0xa,%ecx
call   1060 <search@plt>
mov    %r14,%rdi
mov    $0xa,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
mov    $0x14,%ecx
call   1060 <search@plt>
mov    %r14,%rdi
mov    $0x14,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
mov    $0x1e,%ecx
call   1060 <search@plt>
mov    %r14,%rdi
mov    $0x1e,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Test case 1:\0A\00"
@__const.main.testArray = [7 x i32] [i32 4, i32 5, i32 6, i32 7, i32 1, i32 2, i32 3]
@.str.1 = [27 x i8] c"Index of element %i is %i\0A\00"
@.str.2 = [15 x i8] c"\0ATest case 2:\0A\00"
@__const.main.testArray1 = [6 x i32] [i32 3, i32 3, i32 3, i32 4, i32 5, i32 3]
@.str.3 = [15 x i8] c"\0ATest case 3:\0A\00"
@__const.main.testArray2 = [6 x i32] [i32 20, i32 30, i32 40, i32 50, i32 60, i32 10]
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [7 x i32]
%4 = alloca [6 x i32]
%5 = alloca [6 x i32]
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 5, i32* %2
%7 = bitcast [7 x i32]* %3 to i8*
%8 = getelementptr inbounds [7 x i32], [7 x i32]* %3, i64 0, i64 0
%9 = call i32 @arrayPrint(i32* %8, i32 7)
%10 = load i32, i32* %2
%11 = getelementptr inbounds [7 x i32], [7 x i32]* %3, i64 0, i64 0
%12 = load i32, i32* %2
%13 = call i32 @search(i32* %11, i32 0, i32 6, i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 4, i32* %2
%16 = bitcast [6 x i32]* %4 to i8*
%17 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%18 = call i32 @arrayPrint(i32* %17, i32 6)
%19 = load i32, i32* %2
%20 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%21 = load i32, i32* %2
%22 = call i32 @search(i32* %20, i32 0, i32 5, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 10, i32* %2
%25 = bitcast [6 x i32]* %5 to i8*
%26 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 0
%27 = call i32 @arrayPrint(i32* %26, i32 6)
%28 = load i32, i32* %2
%29 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 0
%30 = load i32, i32* %2
%31 = call i32 @search(i32* %29, i32 0, i32 5, i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %31)
store i32 20, i32* %2
%33 = load i32, i32* %2
%34 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 0
%35 = load i32, i32* %2
%36 = call i32 @search(i32* %34, i32 0, i32 5, i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %36)
store i32 30, i32* %2
%38 = load i32, i32* %2
%39 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 0
%40 = load i32, i32* %2
%41 = call i32 @search(i32* %39, i32 0, i32 5, i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %41)
ret i32 0
}

LLVM IR (-O2):
@__const.main.testArray = [7 x i32] [i32 4, i32 5, i32 6, i32 7, i32 1, i32 2, i32 3]
@.str.1 = [27 x i8] c"Index of element %i is %i\0A\00"
@__const.main.testArray1 = [6 x i32] [i32 3, i32 3, i32 3, i32 4, i32 5, i32 3]
@__const.main.testArray2 = [6 x i32] [i32 20, i32 30, i32 40, i32 50, i32 60, i32 10]
@str = [13 x i8] c"Test case 1:\00"
@str.4 = [14 x i8] c"\0ATest case 2:\00"
@str.5 = [14 x i8] c"\0ATest case 3:\00"
define i32 @main() {
%1 = alloca [7 x i32]
%2 = alloca [6 x i32]
%3 = alloca [6 x i32]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%5 = bitcast [7 x i32]* %1 to i8*
%6 = getelementptr inbounds [7 x i32], [7 x i32]* %1, i64 0, i64 0
%7 = call i32 @arrayPrint(i32* %6, i32 7)
%8 = call i32 @search(i32* %6, i32 0, i32 6, i32 5)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 %8)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.4, i64 0, i64 0))
%11 = bitcast [6 x i32]* %2 to i8*
%12 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 0
%13 = call i32 @arrayPrint(i32* %12, i32 6)
%14 = call i32 @search(i32* %12, i32 0, i32 5, i32 4)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 %14)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
%17 = bitcast [6 x i32]* %3 to i8*
%18 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%19 = call i32 @arrayPrint(i32* %18, i32 6)
%20 = call i32 @search(i32* %18, i32 0, i32 5, i32 10)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 10, i32 %20)
%22 = call i32 @search(i32* %18, i32 0, i32 5, i32 20)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 20, i32 %22)
%24 = call i32 @search(i32* %18, i32 0, i32 5, i32 30)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 30, i32 %24)
ret i32 0
}