#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 strcmp(char const *, char const *);
unsigned int order_by_string(const void *__key, const void *const *__base,
                             unsigned int __count, int __lr, int *__found) {
  unsigned int __start = 0;
  while (__count) {
    unsigned int __middle = __count >> 1;
    const char *a = (const char *)__key;
    const char *b = (const char *)__base[__start + __middle];
    {
      int c = strcmp(a, b);
      if (c == 0)
        goto __equals;
      if (c < 0)
        goto __lessthan;
    }
  __greaterthan:
    __start += __middle + 1;
    __count -= __middle + 1;
    continue;
  __equals:
    *__found = 1;
    if (__lr)
      goto __greaterthan;
  __lessthan:
    __count = __middle;
    continue;
  }
  return __start;
}


x86 assembly (clang, -O0):
<order_by_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11db <order_by_string+0xcb>
mov    -0x14(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <strcmp@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    117f <order_by_string+0x6f>
jmp    11b2 <order_by_string+0xa2>
cmpl   $0x0,-0x3c(%rbp)
jge    118e <order_by_string+0x7e>
jmp    11d0 <order_by_string+0xc0>
jmp    1193 <order_by_string+0x83>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <order_by_string+0x21>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
cmpl   $0x0,-0x18(%rbp)
je     11cb <order_by_string+0xbb>
jmp    1193 <order_by_string+0x83>
jmp    11d0 <order_by_string+0xc0>
mov    -0x28(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <order_by_string+0x21>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<order_by_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %ecx,0xc(%rsp)
test   %edx,%edx
je     119f <order_by_string+0x8f>
mov    %edx,%ebx
mov    %rsi,%r12
mov    %rdi,%r13
xor    %ebp,%ebp
mov    $0x4,%r14d
jmp    116b <order_by_string+0x5b>
nopl   (%rax)
mov    0x10(%rsp),%rax
movl   $0x1,(%rax)
cmpl   $0x0,0xc(%rsp)
je     1163 <order_by_string+0x53>
add    %r15d,%ebp
add    $0x1,%ebp
mov    %r15d,%eax
add    $0x1,%eax
sub    %eax,%ebx
mov    %ebx,%r15d
mov    %r15d,%ebx
test   %r15d,%r15d
je     11a1 <order_by_string+0x91>
mov    %ebx,%r15d
shr    %r15d
lea    (%r15,%rbp,1),%eax
mov    (%r12,%rax,8),%rsi
mov    %r13,%rdi
call   1030 <strcmp@plt>
mov    %eax,%ecx
sar    $0x1f,%ecx
and    $0x5,%ecx
test   %eax,%eax
cmove  %r14d,%ecx
cmp    $0x5,%ecx
je     1163 <order_by_string+0x53>
cmp    $0x4,%ecx
je     1140 <order_by_string+0x30>
test   %ecx,%ecx
je     1152 <order_by_string+0x42>
jmp    1160 <order_by_string+0x50>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @order_by_string(i8* %0, i8** %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32* %4, i32** %10
store i32 0, i32* %11
br label %16
16: ; preds = %56, %41, %5
%17 = load i32, i32* %8
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %58
19: ; preds = %16
%20 = load i32, i32* %8
%21 = lshr i32 %20, 1
store i32 %21, i32* %12
%22 = load i8*, i8** %6
store i8* %22, i8** %13
%23 = load i8**, i8*** %7
%24 = load i32, i32* %11
%25 = load i32, i32* %12
%26 = add i32 %24, %25
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %23, i64 %27
%29 = load i8*, i8** %28
store i8* %29, i8** %14
%30 = load i8*, i8** %13
%31 = load i8*, i8** %14
%32 = call i32 @strcmp(i8* %30, i8* %31)
store i32 %32, i32* %15
%33 = load i32, i32* %15
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %19
br label %50
36: ; preds = %19
%37 = load i32, i32* %15
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %36
br label %56
40: ; preds = %36
br label %41
41: ; preds = %54, %40
%42 = load i32, i32* %12
%43 = add i32 %42, 1
%44 = load i32, i32* %11
%45 = add i32 %44, %43
store i32 %45, i32* %11
%46 = load i32, i32* %12
%47 = add i32 %46, 1
%48 = load i32, i32* %8
%49 = sub i32 %48, %47
store i32 %49, i32* %8
br label %16
50: ; preds = %35
%51 = load i32*, i32** %10
store i32 1, i32* %51
%52 = load i32, i32* %9
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %50
br label %41
55: ; preds = %50
br label %56
56: ; preds = %55, %39
%57 = load i32, i32* %12
store i32 %57, i32* %8
br label %16
58: ; preds = %16
%59 = load i32, i32* %11
ret i32 %59
}

LLVM IR (-O2):
define i32 @order_by_string(i8* nocapture %0, i8** nocapture %1, i32 %2, i32 %3, i32* nocapture writeonly %4) {
%6 = icmp eq i32 %2, 0
br i1 %6, label %32, label %7
7: ; preds = %5
%8 = icmp eq i32 %3, 0
br label %9
9: ; preds = %7, %28
%10 = phi i32 [ %2, %7 ], [ %30, %28 ]
%11 = phi i32 [ 0, %7 ], [ %29, %28 ]
%12 = lshr i32 %10, 1
%13 = add i32 %12, %11
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %16)
%18 = icmp eq i32 %17, 0
%19 = icmp slt i32 %17, 0
%20 = select i1 %19, i32 5, i32 0
%21 = select i1 %18, i32 4, i32 %20
switch i32 %21, label %28 [
i32 0, label %22
i32 4, label %26
i32 5, label %27
]
22: ; preds = %26, %9
%23 = add nuw i32 %12, 1
%24 = add i32 %23, %11
%25 = sub i32 %10, %23
br label %28
26: ; preds = %9
store i32 1, i32* %4
br i1 %8, label %27, label %22
27: ; preds = %26, %9
br label %28
28: ; preds = %27, %22, %9
%29 = phi i32 [ %11, %9 ], [ %11, %27 ], [ %24, %22 ]
%30 = phi i32 [ %10, %9 ], [ %12, %27 ], [ %25, %22 ]
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %9
32: ; preds = %28, %5
%33 = phi i32 [ 0, %5 ], [ %29, %28 ]
ret i32 %33
}