#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*/ atoi(char *);
int b_rsearch(int *, int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ insert_sort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int data[] = {1, 4, 6, 8, 11, 12, 16};
  int dat[] = {9, 4, 6, 2, 4, 1, 0, 7};
  int idx = b_rsearch(data, 0, 6, atoi(argv[1]));
  printf("idx=%d, data[%d]=%d\n", idx, idx, data[idx]);
  insert_sort(dat, 0, 7);
  for (int i = 0; i < 8; i++) {
    printf("%d ", dat[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xea3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea0(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe9d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe9b(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xe99(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe96(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe90(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%ecx
xor    %esi,%esi
mov    $0x6,%edx
call   1040 <b_rsearch@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%esi
mov    -0x54(%rbp),%edx
movslq -0x54(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%ecx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1060 <insert_sort@plt>
movl   $0x0,-0x58(%rbp)
cmpl   $0x8,-0x58(%rbp)
jge    1237 <main+0xf7>
movslq -0x58(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%esi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1209 <main+0xc9>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
movups 0xeb0(%rip),%xmm0
movups %xmm0,0x2c(%rsp)
movaps 0xe98(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xea0(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
mov    %eax,%ecx
call   1050 <b_rsearch@plt>
movslq %eax,%rdx
mov    0x20(%rsp,%rdx,4),%ecx
lea    0xe92(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1070 <insert_sort@plt>
mov    (%rsp),%esi
lea    0xe85(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.data = [7 x i32] [i32 1, i32 4, i32 6, i32 8, i32 11, i32 12, i32 16]
@__const.main.dat = [8 x i32] [i32 9, i32 4, i32 6, i32 2, i32 4, i32 1, i32 0, i32 7]
@.str = [21 x i8] c"idx=%d, data[%d]=%d\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [7 x i32]
%7 = alloca [8 x i32]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [7 x i32]* %6 to i8*
%11 = bitcast [8 x i32]* %7 to i8*
%12 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 0
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
%17 = call i32 @b_rsearch(i32* %12, i32 0, i32 6, i32 %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = load i32, i32* %8
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19, i32 %23)
%25 = getelementptr inbounds [8 x i32], [8 x i32]* %7, i64 0, i64 0
%26 = call i32 @insert_sort(i32* %25, i32 0, i32 7)
store i32 0, i32* %9
br label %27
27: ; preds = %36, %2
%28 = load i32, i32* %9
%29 = icmp slt i32 %28, 8
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [8 x i32], [8 x i32]* %7, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %30
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %27
39: ; preds = %27
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.data = [7 x i32] [i32 1, i32 4, i32 6, i32 8, i32 11, i32 12, i32 16]
@__const.main.dat = [8 x i32] [i32 9, i32 4, i32 6, i32 2, i32 4, i32 1, i32 0, i32 7]
@.str = [21 x i8] c"idx=%d, data[%d]=%d\0A\00"
@.str.1 = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [7 x i32]
%4 = alloca [8 x i32]
%5 = bitcast [7 x i32]* %3 to i8*
%6 = bitcast [8 x i32]* %4 to i8*
%7 = getelementptr inbounds [7 x i32], [7 x i32]* %3, i64 0, i64 0
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = call i32 @b_rsearch(i32* %7, i32 0, i32 6, i32 %10)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [7 x i32], [7 x i32]* %3, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %11, i32 %14)
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 0
%17 = call i32 @insert_sort(i32* %16, i32 0, i32 7)
%18 = load i32, i32* %16
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 2
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 3
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 4
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 5
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 6
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 7
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = call i32 @putchar(i32 10)
ret i32 0
}