#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*/ assert(int);
int interpolation_search(int *, size_t, int);
int /*<<< orphan*/ printf(char *, int, int);
size_t random();
int test(int *array, size_t len) {
  int key, skey;
  key = random() % len;
  printf("array[%d] = %d\n", key, array[key]);
  skey = interpolation_search(array, len, array[key]);
  printf("array[%d] = %d\n", skey, array[skey]);
  assert(-1 == skey || array[skey] == array[key]);
  return 0;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <random@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %edx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
call   1040 <interpolation_search@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%al
mov    $0xffffffff,%ecx
cmp    -0x18(%rbp),%ecx
mov    %al,-0x19(%rbp)
je     11e2 <test+0xa2>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1060 <random@plt>
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
je     1169 <test+0x29>
xor    %edx,%edx
div    %r14
jmp    116e <test+0x2e>
xor    %edx,%edx
div    %r14d
movslq %edx,%r12
mov    (%r15,%r12,4),%edx
lea    0xe84(%rip),%r13
mov    %r13,%rdi
mov    %r12d,%esi
call   1030 <printf@plt>
mov    (%r15,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <interpolation_search@plt>
movslq %eax,%rbx
mov    (%r15,%rbx,4),%edx
mov    %r13,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
cmp    $0xffffffff,%ebx
je     11bc <test+0x7c>
mov    (%r15,%rbx,4),%eax
xor    %edi,%edi
cmp    (%r15,%r12,4),%eax
sete   %dil
jmp    11c1 <test+0x81>
mov    $0x1,%edi
call   1050 <assert@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"array[%d] = %d\0A\00"
define i32 @test(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
%7 = call i64 (...) @random()
%8 = load i64, i64* %4
%9 = urem i64 %7, %8
%10 = trunc i64 %9 to i32
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = load i32*, i32** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %16)
%18 = load i32*, i32** %3
%19 = load i64, i64* %4
%20 = load i32*, i32** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = call i32 @interpolation_search(i32* %18, i64 %19, i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = load i32*, i32** %3
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %31)
%33 = load i32, i32* %6
%34 = icmp eq i32 -1, %33
br i1 %34, label %47, label %35
35: ; preds = %2
%36 = load i32*, i32** %3
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = load i32*, i32** %3
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = icmp eq i32 %40, %45
br label %47
47: ; preds = %35, %2
%48 = phi i1 [ true, %2 ], [ %46, %35 ]
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"array[%d] = %d\0A\00"
define i32 @test(i32* %0, i64 %1) {
%3 = tail call i64 (...) @random()
%4 = urem i64 %3, %1
%5 = trunc i64 %4 to i32
%6 = shl i64 %4, 32
%7 = ashr exact i64 %6, 32
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = load i32, i32* %8
%10 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %9)
%11 = load i32, i32* %8
%12 = tail call i32 @interpolation_search(i32* %0, i64 %1, i32 %11)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %15)
%17 = icmp eq i32 %12, -1
br i1 %17, label %23, label %18
18: ; preds = %2
%19 = load i32, i32* %14
%20 = load i32, i32* %8
%21 = icmp eq i32 %19, %20
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %18, %2
%24 = phi i32 [ 1, %2 ], [ %22, %18 ]
%25 = tail call i32 @assert(i32 %24)
ret i32 0
}