#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 binarySearch(int *, int, int /*<<< orphan*/, int);
int binarySearchR(int *, int, int /*<<< orphan*/, int);
int findMin(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ selectSort(int *, int);
int main(void) {
  int i;
  int list[] = {3, 5, 1, 2, 9};
  int min = findMin(list, 0, 4);
  printf("The min index is %d, min value is %d\n", min, list[min]);
  selectSort(list, 5);
  for (i = 0; i < 5; i++) {
    printf("%d", list[i]);
    if (i == 4)
      puts("");
    else
      printf(" ");
  }
  int index = binarySearch(list, 5, 0, 4);
  printf("The binary search result: index %d, value:%d\n", index,
         index != -1 ? list[index] : -1);
  int indexR = binarySearchR(list, 5, 0, 4);
  printf("The binary search result: index %d, value:%d\n", indexR,
         indexR != -1 ? list[indexR] : -1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe85(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <findMin@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    $0x5,%esi
call   1080 <selectSort@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    122b <main+0xcb>
movslq -0x8(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x4,-0x8(%rbp)
jne    120a <main+0xaa>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
jmp    1218 <main+0xb8>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    121d <main+0xbd>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11cf <main+0x6f>
lea    -0x20(%rbp),%rdi
mov    $0x5,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1070 <binarySearch@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
je     1263 <main+0x103>
movslq -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
mov    %eax,-0x34(%rbp)
jmp    1270 <main+0x110>
mov    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    1270 <main+0x110>
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    $0x5,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <binarySearchR@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
je     12bc <main+0x15c>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
mov    %eax,-0x3c(%rbp)
jmp    12c9 <main+0x169>
mov    $0xffffffff,%eax
mov    %eax,-0x3c(%rbp)
jmp    12c9 <main+0x169>
mov    -0x38(%rbp),%esi
mov    -0x3c(%rbp),%edx
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0xea3(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xe88(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <findMin@plt>
movslq %eax,%rsi
mov    (%rsp,%rsi,4),%edx
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1080 <selectSort@plt>
mov    (%rsp),%esi
lea    0xe81(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    $0x5,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1070 <binarySearch@plt>
mov    $0xffffffff,%ebx
mov    $0xffffffff,%edx
cmp    $0xffffffff,%eax
je     1256 <main+0xf6>
movslq %eax,%rcx
mov    (%rsp,%rcx,4),%edx
lea    0xde0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    $0x5,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <binarySearchR@plt>
cmp    $0xffffffff,%eax
je     1285 <main+0x125>
movslq %eax,%rcx
mov    (%rsp,%rcx,4),%ebx
lea    0xdb1(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.list = [5 x i32] [i32 3, i32 5, i32 1, i32 2, i32 9]
@.str = [38 x i8] c"The min index is %d, min value is %d\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c" \00"
@.str.4 = [46 x i8] c"The binary search result: index %d, value:%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [5 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [5 x i32]* %3 to i8*
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%9 = call i32 @findMin(i32* %8, i32 0, i32 4)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %14)
%16 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%17 = call i32 @selectSort(i32* %16, i32 5)
store i32 0, i32* %2
br label %18
18: ; preds = %34, %0
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 5
br i1 %20, label %21, label %37
21: ; preds = %18
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 4
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %33
31: ; preds = %21
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
br label %34
34: ; preds = %33
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
br label %18
37: ; preds = %18
%38 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%39 = call i32 @binarySearch(i32* %38, i32 5, i32 0, i32 4)
store i32 %39, i32* %5
%40 = load i32, i32* %5
%41 = load i32, i32* %5
%42 = icmp ne i32 %41, -1
br i1 %42, label %43, label %48
43: ; preds = %37
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %45
%47 = load i32, i32* %46
br label %49
48: ; preds = %37
br label %49
49: ; preds = %48, %43
%50 = phi i32 [ %47, %43 ], [ -1, %48 ]
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %40, i32 %50)
%52 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%53 = call i32 @binarySearchR(i32* %52, i32 5, i32 0, i32 4)
store i32 %53, i32* %6
%54 = load i32, i32* %6
%55 = load i32, i32* %6
%56 = icmp ne i32 %55, -1
br i1 %56, label %57, label %62
57: ; preds = %49
%58 = load i32, i32* %6
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %59
%61 = load i32, i32* %60
br label %63
62: ; preds = %49
br label %63
63: ; preds = %62, %57
%64 = phi i32 [ %61, %57 ], [ -1, %62 ]
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %54, i32 %64)
ret i32 0
}

LLVM IR (-O2):
@__const.main.list = [5 x i32] [i32 3, i32 5, i32 1, i32 2, i32 9]
@.str = [38 x i8] c"The min index is %d, min value is %d\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [46 x i8] c"The binary search result: index %d, value:%d\0A\00"
define i32 @main() {
%1 = alloca [5 x i32]
%2 = bitcast [5 x i32]* %1 to i8*
%3 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%4 = call i32 @findMin(i32* %3, i32 0, i32 4)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %5
%7 = load i32, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %7)
%9 = call i32 @selectSort(i32* %3, i32 5)
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 @putchar(i32 32)
%13 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 @putchar(i32 32)
%17 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 2
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 @putchar(i32 32)
%21 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 3
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = call i32 @putchar(i32 32)
%25 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 4
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = call i32 @putchar(i32 10)
%29 = call i32 @binarySearch(i32* %3, i32 5, i32 0, i32 4)
%30 = icmp eq i32 %29, -1
br i1 %30, label %35, label %31
31: ; preds = %0
%32 = sext i32 %29 to i64
%33 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %32
%34 = load i32, i32* %33
br label %35
35: ; preds = %0, %31
%36 = phi i32 [ %34, %31 ], [ -1, %0 ]
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %29, i32 %36)
%38 = call i32 @binarySearchR(i32* %3, i32 5, i32 0, i32 4)
%39 = icmp eq i32 %38, -1
br i1 %39, label %44, label %40
40: ; preds = %35
%41 = sext i32 %38 to i64
%42 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %41
%43 = load i32, i32* %42
br label %44
44: ; preds = %35, %40
%45 = phi i32 [ %43, %40 ], [ -1, %35 ]
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %38, i32 %45)
ret i32 0
}