#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 */
struct io_file {
  int dummy;
};

/* Variables and functions */
scalar_t__ io_in(struct io_file *, int const, char *, int);
scalar_t__ strncasecmp(char const *, char *, unsigned int);
int find_name(struct io_file *index, int begin, int end, char type,
              const char *name, unsigned int name_len) {
  const int size = 45;
  const int count = (end - begin) / size;
  const int mid = begin + size * (count / 2);
  char test[41];
  if (count <= 1)
    return begin;
  if (io_in(index, mid - size, test, sizeof test) < 0)
    return -1;
  if (name_len > sizeof test - 1)
    name_len = sizeof test - 1;
  if (type > test[0] ||
      (type == test[0] && strncasecmp(name, test + 1, name_len) > 0))
    return find_name(index, mid, end, type, name, name_len);
  else
    return find_name(index, begin, mid, type, name, name_len);
}


x86 assembly (clang, -O0):
<find_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %cl,%al
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x2d,-0x30(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    $0x2d,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x34(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
imul   $0x2d,%ecx,%ecx
add    %ecx,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x34(%rbp)
jg     119d <find_name+0x6d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1262 <find_name+0x132>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%esi
sub    $0x2d,%esi
lea    -0x70(%rbp),%rdx
mov    $0x29,%ecx
call   1030 <io_in@plt>
cmp    $0x0,%rax
jge    11cb <find_name+0x9b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1262 <find_name+0x132>
mov    -0x2c(%rbp),%eax
cmp    $0x28,%rax
jbe    11df <find_name+0xaf>
movl   $0x28,-0x2c(%rbp)
movsbl -0x19(%rbp),%eax
movsbl -0x70(%rbp),%ecx
cmp    %ecx,%eax
jg     121d <find_name+0xed>
movsbl -0x19(%rbp),%eax
movsbl -0x70(%rbp),%ecx
cmp    %ecx,%eax
jne    1242 <find_name+0x112>
mov    -0x28(%rbp),%rdi
lea    -0x70(%rbp),%rsi
add    $0x1,%rsi
mov    -0x2c(%rbp),%edx
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jle    1242 <find_name+0x112>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x19(%rbp),%al
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
movsbl %al,%ecx
call   1040 <find_name@plt>
mov    %eax,-0x4(%rbp)
jmp    1262 <find_name+0x132>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    -0x19(%rbp),%al
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
movsbl %al,%ecx
call   1040 <find_name@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %esi,%ebx
mov    %edx,%eax
sub    %esi,%eax
cmp    $0x5a,%eax
jl     11fd <find_name+0xcd>
mov    %r9d,%r14d
mov    %r8,%r15
mov    %edx,%r13d
mov    %rdi,%r12
mov    %ecx,0x4(%rsp)
movslq %eax,%rcx
imul   $0xffffffffb60b60b7,%rcx,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x6,%ecx
add    %eax,%ecx
lea    (%rcx,%rcx,8),%eax
lea    (%rax,%rax,4),%ebp
add    %ebx,%ebp
lea    -0x2d(%rbp),%esi
lea    0x10(%rsp),%rdx
mov    $0x29,%ecx
call   1030 <io_in@plt>
test   %rax,%rax
js     11dd <find_name+0xad>
mov    %r15,0x8(%rsp)
cmp    $0x28,%r14d
mov    $0x28,%r15d
cmovb  %r14d,%r15d
mov    0x4(%rsp),%ecx
cmp    %cl,0x10(%rsp)
jl     11d0 <find_name+0xa0>
jne    11e4 <find_name+0xb4>
lea    0x11(%rsp),%rsi
mov    0x8(%rsp),%rdi
mov    %r15d,%edx
call   1050 <strncasecmp@plt>
mov    0x4(%rsp),%ecx
test   %rax,%rax
jle    11e4 <find_name+0xb4>
movsbl %cl,%ecx
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
jmp    11ee <find_name+0xbe>
mov    $0xffffffff,%ebx
jmp    11fd <find_name+0xcd>
movsbl %cl,%ecx
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    0x8(%rsp),%r8
mov    %r15d,%r9d
call   1040 <find_name@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.io_file = type { i32 }
define i32 @find_name(%struct.io_file* %0, i32 %1, i32 %2, i8 signext %3, i8* %4, i32 %5) {
%7 = alloca i32
%8 = alloca %struct.io_file*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca [41 x i8]
store %struct.io_file* %0, %struct.io_file** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i8 %3, i8* %11
store i8* %4, i8** %12
store i32 %5, i32* %13
store i32 45, i32* %14
%18 = load i32, i32* %10
%19 = load i32, i32* %9
%20 = sub nsw i32 %18, %19
%21 = sdiv i32 %20, 45
store i32 %21, i32* %15
%22 = load i32, i32* %9
%23 = load i32, i32* %15
%24 = sdiv i32 %23, 2
%25 = mul nsw i32 45, %24
%26 = add nsw i32 %22, %25
store i32 %26, i32* %16
%27 = load i32, i32* %15
%28 = icmp sle i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %6
%30 = load i32, i32* %9
store i32 %30, i32* %7
br label %81
31: ; preds = %6
%32 = load %struct.io_file*, %struct.io_file** %8
%33 = load i32, i32* %16
%34 = sub nsw i32 %33, 45
%35 = getelementptr inbounds [41 x i8], [41 x i8]* %17, i64 0, i64 0
%36 = call i64 @io_in(%struct.io_file* %32, i32 %34, i8* %35, i32 41)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %31
store i32 -1, i32* %7
br label %81
39: ; preds = %31
%40 = load i32, i32* %13
%41 = zext i32 %40 to i64
%42 = icmp ugt i64 %41, 40
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 40, i32* %13
br label %44
44: ; preds = %43, %39
%45 = load i8, i8* %11
%46 = sext i8 %45 to i32
%47 = getelementptr inbounds [41 x i8], [41 x i8]* %17, i64 0, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp sgt i32 %46, %49
br i1 %50, label %65, label %51
51: ; preds = %44
%52 = load i8, i8* %11
%53 = sext i8 %52 to i32
%54 = getelementptr inbounds [41 x i8], [41 x i8]* %17, i64 0, i64 0
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %53, %56
br i1 %57, label %58, label %73
58: ; preds = %51
%59 = load i8*, i8** %12
%60 = getelementptr inbounds [41 x i8], [41 x i8]* %17, i64 0, i64 0
%61 = getelementptr inbounds i8, i8* %60, i64 1
%62 = load i32, i32* %13
%63 = call i64 @strncasecmp(i8* %59, i8* %61, i32 %62)
%64 = icmp sgt i64 %63, 0
br i1 %64, label %65, label %73
65: ; preds = %58, %44
%66 = load %struct.io_file*, %struct.io_file** %8
%67 = load i32, i32* %16
%68 = load i32, i32* %10
%69 = load i8, i8* %11
%70 = load i8*, i8** %12
%71 = load i32, i32* %13
%72 = call i32 @find_name(%struct.io_file* %66, i32 %67, i32 %68, i8 signext %69, i8* %70, i32 %71)
store i32 %72, i32* %7
br label %81
73: ; preds = %58, %51
%74 = load %struct.io_file*, %struct.io_file** %8
%75 = load i32, i32* %9
%76 = load i32, i32* %16
%77 = load i8, i8* %11
%78 = load i8*, i8** %12
%79 = load i32, i32* %13
%80 = call i32 @find_name(%struct.io_file* %74, i32 %75, i32 %76, i8 signext %77, i8* %78, i32 %79)
store i32 %80, i32* %7
br label %81
81: ; preds = %73, %65, %38, %29
%82 = load i32, i32* %7
ret i32 %82
}

LLVM IR (-O2):
%struct.io_file = type { i32 }
define i32 @find_name(%struct.io_file* %0, i32 %1, i32 %2, i8 signext %3, i8* %4, i32 %5) {
%7 = alloca [41 x i8]
%8 = sub nsw i32 %2, %1
%9 = sdiv i32 %8, 90
%10 = mul nsw i32 %9, 45
%11 = add nsw i32 %10, %1
%12 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 0
%13 = icmp slt i32 %8, 90
br i1 %13, label %33, label %14
14: ; preds = %6
%15 = add nsw i32 %11, -45
%16 = call i64 @io_in(%struct.io_file* %0, i32 %15, i8* %12, i32 41)
%17 = icmp slt i64 %16, 0
br i1 %17, label %33, label %18
18: ; preds = %14
%19 = icmp ult i32 %5, 40
%20 = select i1 %19, i32 %5, i32 40
%21 = load i8, i8* %12
%22 = icmp slt i8 %21, %3
br i1 %22, label %29, label %23
23: ; preds = %18
%24 = icmp eq i8 %21, %3
br i1 %24, label %25, label %31
25: ; preds = %23
%26 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 1
%27 = call i64 @strncasecmp(i8* %4, i8* %26, i32 %20)
%28 = icmp sgt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25, %18
%30 = call i32 @find_name(%struct.io_file* %0, i32 %11, i32 %2, i8 signext %3, i8* %4, i32 %20)
br label %33
31: ; preds = %25, %23
%32 = call i32 @find_name(%struct.io_file* %0, i32 %1, i32 %11, i8 signext %3, i8* %4, i32 %20)
br label %33
33: ; preds = %14, %6, %31, %29
%34 = phi i32 [ %30, %29 ], [ %32, %31 ], [ %1, %6 ], [ -1, %14 ]
ret i32 %34
}