#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 */
void *lower_bound(void *, size_t, size_t, void const *,
                  int (*)(void const *, void const *));
void *binary_find(void *first, size_t nmemb, size_t size, const void *key,
                  int (*compar)(const void *v, const void *key)) {
  first = lower_bound(first, nmemb, size, key, compar);
  return (first != ((void *)0) && compar(first, key) == 0) ? first
                                                           : ((void *)0);
}


x86 assembly (clang, -O0):
<binary_find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1030 <lower_bound@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1178 <binary_find+0x68>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   *%rax
cmp    $0x0,%eax
jne    1178 <binary_find+0x68>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1183 <binary_find+0x73>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    1183 <binary_find+0x73>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary_find>:
push   %r15
push   %r14
push   %rbx
mov    %r8,%r14
mov    %rcx,%r15
call   1030 <lower_bound@plt>
test   %rax,%rax
je     113d <binary_find+0x2d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   *%r14
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
cmove  %rbx,%rax
jmp    113f <binary_find+0x2f>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @binary_find(i8* %0, i64 %1, i64 %2, i8* %3, i32 (i8*, i8*)* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32 (i8*, i8*)*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i32 (i8*, i8*)* %4, i32 (i8*, i8*)** %10
%11 = load i8*, i8** %6
%12 = load i64, i64* %7
%13 = load i64, i64* %8
%14 = load i8*, i8** %9
%15 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %10
%16 = call i8* @lower_bound(i8* %11, i64 %12, i64 %13, i8* %14, i32 (i8*, i8*)* %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %27
19: ; preds = %5
%20 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %10
%21 = load i8*, i8** %6
%22 = load i8*, i8** %9
%23 = call i32 %20(i8* %21, i8* %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i8*, i8** %6
br label %28
27: ; preds = %19, %5
br label %28
28: ; preds = %27, %25
%29 = phi i8* [ %26, %25 ], [ null, %27 ]
ret i8* %29
}

LLVM IR (-O2):
define i8* @binary_find(i8* %0, i64 %1, i64 %2, i8* %3, i32 (i8*, i8*)* %4) {
%6 = tail call i8* @lower_bound(i8* %0, i64 %1, i64 %2, i8* %3, i32 (i8*, i8*)* %4)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call i32 %4(i8* %6, i8* %3)
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i8* %6, i8* null
br label %12
12: ; preds = %8, %5
%13 = phi i8* [ null, %5 ], [ %11, %8 ]
ret i8* %13
}