#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 midpoint(int *, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int interpolation_search_recursive(int s[], int key, int l, int r) {
  if (r < l) {
    printf("isr no exist\n");
    return -1;
  }
  int m = midpoint(s, key, l, r);
  if (key < s[m]) {
    printf("isr <- %d %d\n", l, m - 1);
    return interpolation_search_recursive(s, key, l, m - 1);
  } else if (s[m] < key) {
    printf("isr -> %d %d\n", m + 1, r);
    return interpolation_search_recursive(s, key, m + 1, r);
  } else {
    printf("isr found %d\n", m);
    return m;
  }
}


x86 assembly (clang, -O0):
<interpolation_search_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    116b <interpolation_search_recursive+0x3b>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <interpolation_search_recursive+0xf7>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1050 <midpoint@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    11c8 <interpolation_search_recursive+0x98>
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%edx
sub    $0x1,%edx
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
call   1030 <interpolation_search_recursive@plt>
mov    %eax,-0x4(%rbp)
jmp    1227 <interpolation_search_recursive+0xf7>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
jge    1210 <interpolation_search_recursive+0xe0>
mov    -0x20(%rbp),%esi
add    $0x1,%esi
mov    -0x1c(%rbp),%edx
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
mov    -0x1c(%rbp),%ecx
call   1030 <interpolation_search_recursive@plt>
mov    %eax,-0x4(%rbp)
jmp    1227 <interpolation_search_recursive+0xf7>
mov    -0x20(%rbp),%esi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interpolation_search_recursive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %edx,%ecx
jge    1163 <interpolation_search_recursive+0x33>
lea    0xee4(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ecx,%ebp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0xe8c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1050 <midpoint@plt>
mov    %eax,%r13d
cltq
cmp    %r14d,(%r15,%rax,4)
jle    11b3 <interpolation_search_recursive+0x83>
lea    -0x1(%r13),%ebp
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %ebx,%r13d
jg     1180 <interpolation_search_recursive+0x50>
jmp    113f <interpolation_search_recursive+0xf>
jge    11d5 <interpolation_search_recursive+0xa5>
lea    0x1(%r13),%ebx
lea    0xe4e(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r13d,%ebp
jg     1180 <interpolation_search_recursive+0x50>
jmp    113f <interpolation_search_recursive+0xf>
lea    0xe40(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1151 <interpolation_search_recursive+0x21>

LLVM IR (-O0):
@.str = [14 x i8] c"isr no exist\0A\00"
@.str.1 = [14 x i8] c"isr <- %d %d\0A\00"
@.str.2 = [14 x i8] c"isr -> %d %d\0A\00"
@.str.3 = [14 x i8] c"isr found %d\0A\00"
define i32 @interpolation_search_recursive(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i32, i32* %9
%12 = load i32, i32* %8
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %63
16: ; preds = %4
%17 = load i32*, i32** %6
%18 = load i32, i32* %7
%19 = load i32, i32* %8
%20 = load i32, i32* %9
%21 = call i32 @midpoint(i32* %17, i32 %18, i32 %19, i32 %20)
store i32 %21, i32* %10
%22 = load i32, i32* %7
%23 = load i32*, i32** %6
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = icmp slt i32 %22, %27
br i1 %28, label %29, label %40
29: ; preds = %16
%30 = load i32, i32* %8
%31 = load i32, i32* %10
%32 = sub nsw i32 %31, 1
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %32)
%34 = load i32*, i32** %6
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = load i32, i32* %10
%38 = sub nsw i32 %37, 1
%39 = call i32 @interpolation_search_recursive(i32* %34, i32 %35, i32 %36, i32 %38)
store i32 %39, i32* %5
br label %63
40: ; preds = %16
%41 = load i32*, i32** %6
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = load i32, i32* %7
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %59
48: ; preds = %40
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
%51 = load i32, i32* %9
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %50, i32 %51)
%53 = load i32*, i32** %6
%54 = load i32, i32* %7
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
%57 = load i32, i32* %9
%58 = call i32 @interpolation_search_recursive(i32* %53, i32 %54, i32 %56, i32 %57)
store i32 %58, i32* %5
br label %63
59: ; preds = %40
%60 = load i32, i32* %10
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %10
store i32 %62, i32* %5
br label %63
63: ; preds = %59, %48, %29, %14
%64 = load i32, i32* %5
ret i32 %64
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"isr <- %d %d\0A\00"
@.str.2 = [14 x i8] c"isr -> %d %d\0A\00"
@.str.3 = [14 x i8] c"isr found %d\0A\00"
@str = [13 x i8] c"isr no exist\00"
define i32 @interpolation_search_recursive(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp slt i32 %3, %2
br i1 %5, label %9, label %6
6: ; preds = %4, %24
%7 = phi i32 [ %12, %24 ], [ %3, %4 ]
%8 = phi i32 [ %25, %24 ], [ %2, %4 ]
br label %11
9: ; preds = %24, %18, %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %30
11: ; preds = %6, %18
%12 = phi i32 [ %7, %6 ], [ %19, %18 ]
%13 = tail call i32 @midpoint(i32* %0, i32 %1, i32 %8, i32 %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = load i32, i32* %15
%17 = icmp sgt i32 %16, %1
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = add nsw i32 %13, -1
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %19)
%21 = icmp sgt i32 %13, %8
br i1 %21, label %11, label %9
22: ; preds = %11
%23 = icmp slt i32 %16, %1
br i1 %23, label %24, label %28
24: ; preds = %22
%25 = add nsw i32 %13, 1
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %12)
%27 = icmp sgt i32 %12, %13
br i1 %27, label %6, label %9
28: ; preds = %22
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %13)
br label %30
30: ; preds = %28, %9
%31 = phi i32 [ -1, %9 ], [ %13, %28 ]
ret i32 %31
}