#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int FileSize(int /*<<< orphan*/ *);
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char, int);
int /*<<< orphan*/ stderr;
int strncmp(char const *, char *, int);
int CheckOnDisk(const char *aword, int buflen) {
  char filestr[20 + 1];
  char tfname[16];
  long lwr, upr, cur;
  int cmp;
  FILE *fin;
  sprintf(tfname, "dict%cword%02d.txt", '/', buflen);
  tfname[15] = '\0';
  if ((fin = fopen(tfname, "r")) == NULL) {
    fprintf(stderr, "%s : Error opening dictionary file '%s'%s", "randword",
            tfname, "\n");
    exit(1);
  }
  lwr = -1;
  upr = (FileSize(fin) / (buflen + 2)) + 1;
  cur = (upr + lwr) / 2;
  while ((cur != upr) && (cur != lwr)) {
    fseek(fin, cur * (buflen + 2), SEEK_SET);
    fread(filestr, buflen, 1, fin);
    filestr[buflen] = '\0';
    cmp = strncmp(aword, filestr, buflen);
    if (cmp == 0) {
      fclose(fin);
      return 1;
    } else if (cmp > 0)
      lwr = cur;
    else
      upr = cur;
    cur = (lwr + upr) / 2;
  }
  fclose(fin);
  return 0;
}


x86 assembly (clang, -O0):
<CheckOnDisk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%ecx
lea    0xe53(%rip),%rsi
mov    $0x2f,%edx
call   10a0 <sprintf@plt>
movb   $0x0,-0x31(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jne    120a <CheckOnDisk+0x7a>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rcx
lea    0xe28(%rip),%rsi
lea    0xe4b(%rip),%rdx
lea    0xe4d(%rip),%r8
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movq   $0xffffffffffffffff,-0x48(%rbp)
ff
mov    -0x68(%rbp),%rdi
call   1060 <FileSize@plt>
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
cltq
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
add    -0x48(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rcx
xor    %eax,%eax
cmp    -0x50(%rbp),%rcx
mov    %al,-0x69(%rbp)
je     1264 <CheckOnDisk+0xd4>
mov    -0x58(%rbp),%rax
cmp    -0x48(%rbp),%rax
setne  %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    1274 <CheckOnDisk+0xe4>
jmp    1325 <CheckOnDisk+0x195>
mov    -0x68(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x14(%rbp),%eax
add    $0x2,%eax
cltq
imul   %rax,%rsi
mov    0x2d49(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
lea    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x68(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncmp@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    12e6 <CheckOnDisk+0x156>
mov    -0x68(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1335 <CheckOnDisk+0x1a5>
cmpl   $0x0,-0x5c(%rbp)
jle    12fd <CheckOnDisk+0x16d>
mov    -0x58(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1305 <CheckOnDisk+0x175>
mov    -0x58(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    130a <CheckOnDisk+0x17a>
mov    -0x48(%rbp),%rax
add    -0x50(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x58(%rbp)
jmp    1243 <CheckOnDisk+0xb3>
mov    -0x68(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CheckOnDisk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %esi,%ebp
mov    %rdi,0x20(%rsp)
lea    0xe54(%rip),%rsi
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2f,%edx
mov    %ebp,%ecx
call   10a0 <sprintf@plt>
movb   $0x0,0x3f(%rsp)
lea    0xe47(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ee <CheckOnDisk+0x15e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <FileSize@plt>
lea    0x2(%rbp),%ecx
cltd
idiv   %ecx
lea    0x1(%rax),%edx
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
cmp    %edx,%esi
mov    %rbx,(%rsp)
je     12d2 <CheckOnDisk+0x142>
cmp    $0xfffffffd,%edx
ja     12d2 <CheckOnDisk+0x142>
movslq %edx,%r12
movslq %esi,%r14
movslq %ecx,%rax
mov    %rax,0x18(%rsp)
mov    %rbp,0x8(%rsp)
movslq %ebp,%rax
mov    %rax,0x10(%rsp)
mov    $0xffffffffffffffff,%rcx
mov    (%rsp),%rbx
mov    $0x1,%ebp
mov    0x8(%rsp),%r13
nop
mov    %rcx,0x28(%rsp)
mov    %r14,%rsi
imul   0x18(%rsp),%rsi
mov    0x2d83(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1080 <fseek@plt>
lea    0x40(%rsp),%r15
mov    %r15,%rdi
mov    %r13d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    0x10(%rsp),%rax
movb   $0x0,0x40(%rsp,%rax,1)
mov    0x20(%rsp),%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     12d4 <CheckOnDisk+0x144>
jg     12b0 <CheckOnDisk+0x120>
mov    %r14,%r12
mov    0x28(%rsp),%rcx
jmp    12b3 <CheckOnDisk+0x123>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rcx
lea    (%rcx,%r12,1),%rax
mov    %rax,%r14
shr    $0x3f,%r14
add    %rax,%r14
sar    %r14
cmp    %r12,%r14
je     12d2 <CheckOnDisk+0x142>
cmp    %rcx,%r14
jne    1240 <CheckOnDisk+0xb0>
xor    %ebp,%ebp
mov    (%rsp),%rdi
call   1050 <fclose@plt>
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xd17(%rip),%rsi
lea    0xd3a(%rip),%rdx
lea    0xd3c(%rip),%r8
lea    0x30(%rsp),%rcx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"dict%cword%02d.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [42 x i8] c"%s : Error opening dictionary file '%s'%s\00"
@.str.3 = [9 x i8] c"randword\00"
@.str.4 = [2 x i8] c"\0A\00"
@SEEK_SET = global i32 0
define i32 @CheckOnDisk(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [21 x i8]
%7 = alloca [16 x i8]
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%14 = load i32, i32* %5
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8 signext 47, i32 %14)
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 15
store i8 0, i8* %16
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %12
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
store i64 -1, i64* %8
%26 = load i32*, i32** %12
%27 = call i32 @FileSize(i32* %26)
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 2
%30 = sdiv i32 %27, %29
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
store i64 %32, i64* %9
%33 = load i64, i64* %9
%34 = load i64, i64* %8
%35 = add nsw i64 %33, %34
%36 = sdiv i64 %35, 2
store i64 %36, i64* %10
br label %37
37: ; preds = %80, %25
%38 = load i64, i64* %10
%39 = load i64, i64* %9
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i64, i64* %10
%43 = load i64, i64* %8
%44 = icmp ne i64 %42, %43
br label %45
45: ; preds = %41, %37
%46 = phi i1 [ false, %37 ], [ %44, %41 ]
br i1 %46, label %47, label %85
47: ; preds = %45
%48 = load i32*, i32** %12
%49 = load i64, i64* %10
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 2
%52 = sext i32 %51 to i64
%53 = mul nsw i64 %49, %52
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @fseek(i32* %48, i64 %53, i32 %54)
%56 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%57 = load i32, i32* %5
%58 = load i32*, i32** %12
%59 = call i32 @fread(i8* %56, i32 %57, i32 1, i32* %58)
%60 = load i32, i32* %5
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 %61
store i8 0, i8* %62
%63 = load i8*, i8** %4
%64 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%65 = load i32, i32* %5
%66 = call i32 @strncmp(i8* %63, i8* %64, i32 %65)
store i32 %66, i32* %11
%67 = load i32, i32* %11
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %47
%70 = load i32*, i32** %12
%71 = call i32 @fclose(i32* %70)
store i32 1, i32* %3
br label %88
72: ; preds = %47
%73 = load i32, i32* %11
%74 = icmp sgt i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = load i64, i64* %10
store i64 %76, i64* %8
br label %79
77: ; preds = %72
%78 = load i64, i64* %10
store i64 %78, i64* %9
br label %79
79: ; preds = %77, %75
br label %80
80: ; preds = %79
%81 = load i64, i64* %8
%82 = load i64, i64* %9
%83 = add nsw i64 %81, %82
%84 = sdiv i64 %83, 2
store i64 %84, i64* %10
br label %37
85: ; preds = %45
%86 = load i32*, i32** %12
%87 = call i32 @fclose(i32* %86)
store i32 0, i32* %3
br label %88
88: ; preds = %85, %69
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str = [19 x i8] c"dict%cword%02d.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [42 x i8] c"%s : Error opening dictionary file '%s'%s\00"
@.str.3 = [9 x i8] c"randword\00"
@.str.4 = [2 x i8] c"\0A\00"
@SEEK_SET = global i32 0
define i32 @CheckOnDisk(i8* %0, i32 %1) {
%3 = alloca [21 x i8]
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8 signext 47, i32 %1)
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 15
store i8 0, i8* %8
%9 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = tail call i32 @FileSize(i32* %9)
%17 = add nsw i32 %1, 2
%18 = sdiv i32 %16, %17
%19 = add nsw i32 %18, 1
%20 = sdiv i32 %18, 2
%21 = icmp ne i32 %20, %19
%22 = icmp ult i32 %19, -2
%23 = and i1 %21, %22
br i1 %23, label %24, label %49
24: ; preds = %15
%25 = sext i32 %19 to i64
%26 = sext i32 %20 to i64
%27 = sext i32 %17 to i64
%28 = sext i32 %1 to i64
%29 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 %28
br label %30
30: ; preds = %24, %40
%31 = phi i64 [ %26, %24 ], [ %45, %40 ]
%32 = phi i64 [ -1, %24 ], [ %43, %40 ]
%33 = phi i64 [ %25, %24 ], [ %42, %40 ]
%34 = mul nsw i64 %31, %27
%35 = load i32, i32* @SEEK_SET
%36 = call i32 @fseek(i32* %9, i64 %34, i32 %35)
%37 = call i32 @fread(i8* %5, i32 %1, i32 1, i32* %9)
store i8 0, i8* %29
%38 = call i32 @strncmp(i8* %0, i8* %5, i32 %1)
%39 = icmp eq i32 %38, 0
br i1 %39, label %49, label %40
40: ; preds = %30
%41 = icmp sgt i32 %38, 0
%42 = select i1 %41, i64 %33, i64 %31
%43 = select i1 %41, i64 %31, i64 %32
%44 = add nsw i64 %43, %42
%45 = sdiv i64 %44, 2
%46 = icmp ne i64 %45, %42
%47 = icmp ne i64 %45, %43
%48 = select i1 %46, i1 %47, i1 false
br i1 %48, label %30, label %49
49: ; preds = %40, %30, %15
%50 = phi i32 [ 0, %15 ], [ 1, %30 ], [ 0, %40 ]
%51 = call i32 @fclose(i32* %9)
ret i32 %50
}