#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, char const *, char *);
scalar_t__ strcmp(char *, char *);
int checkdict(FILE *ofp, char **dictionary, char check[],
              const char *submission) {
  FILE *ifp;
  int min = 0, max, mid;
  ifp = fopen("dictionary.txt", "r");
  fscanf(ifp, "%d", &max);
  fclose(ifp);
  while (min <= max) {
    mid = (min + max) / 2;
    if (strcmp(check, dictionary[mid]) == 0) {
      printf("A permutation of %s is %s.\n", submission, dictionary[mid]);
      fprintf(ofp, "A permutation of %s is %s.\n", submission, dictionary[mid]);
      return 1;
    } else if (strcmp(check, dictionary[mid]) > 0)
      min = mid + 1;
    else if (strcmp(check, dictionary[mid]) < 0)
      max = mid - 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<checkdict>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe70(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jg     129b <checkdict+0x13b>
mov    -0x34(%rbp),%eax
add    -0x38(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1237 <checkdict+0xd7>
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xdee(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a2 <checkdict+0x142>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jle    1264 <checkdict+0x104>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1291 <checkdict+0x131>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jge    128c <checkdict+0x12c>
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1291 <checkdict+0x131>
jmp    1296 <checkdict+0x136>
jmp    11b3 <checkdict+0x53>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkdict>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,0x10(%rsp)
lea    0xe7d(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r13
lea    0xe78(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
js     121d <checkdict+0xbd>
xor    %r13d,%r13d
jmp    11cf <checkdict+0x6f>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %ebp,%r13d
mov    0xc(%rsp),%eax
cmp    %eax,%r13d
jg     121d <checkdict+0xbd>
add    %r13d,%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
movslq %ebp,%rbx
mov    (%r12,%rbx,8),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
mov    (%r12,%rbx,8),%rdx
test   %rax,%rax
je     1221 <checkdict+0xc1>
mov    %r14,%rdi
mov    %rdx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jg     11c0 <checkdict+0x60>
mov    (%r12,%rbx,8),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jns    11c6 <checkdict+0x66>
add    $0xffffffff,%ebp
mov    %ebp,0xc(%rsp)
jmp    11c6 <checkdict+0x66>
xor    %eax,%eax
jmp    124c <checkdict+0xec>
lea    0xdec(%rip),%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    (%r12,%rbx,8),%rcx
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"dictionary.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [28 x i8] c"A permutation of %s is %s.\0A\00"
define i32 @checkdict(i32* %0, i8** %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %6
store i8** %1, i8*** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 0, i32* %11
%14 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %10
%15 = load i32*, i32** %10
%16 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %12)
%17 = load i32*, i32** %10
%18 = call i32 @fclose(i32* %17)
br label %19
19: ; preds = %78, %4
%20 = load i32, i32* %11
%21 = load i32, i32* %12
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %79
23: ; preds = %19
%24 = load i32, i32* %11
%25 = load i32, i32* %12
%26 = add nsw i32 %24, %25
%27 = sdiv i32 %26, 2
store i32 %27, i32* %13
%28 = load i8*, i8** %8
%29 = load i8**, i8*** %7
%30 = load i32, i32* %13
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %28, i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %52
36: ; preds = %23
%37 = load i8*, i8** %9
%38 = load i8**, i8*** %7
%39 = load i32, i32* %13
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %37, i8* %42)
%44 = load i32*, i32** %6
%45 = load i8*, i8** %9
%46 = load i8**, i8*** %7
%47 = load i32, i32* %13
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
%50 = load i8*, i8** %49
%51 = call i32 @fprintf(i32* %44, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %45, i8* %50)
store i32 1, i32* %5
br label %80
52: ; preds = %23
%53 = load i8*, i8** %8
%54 = load i8**, i8*** %7
%55 = load i32, i32* %13
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
%58 = load i8*, i8** %57
%59 = call i64 @strcmp(i8* %53, i8* %58)
%60 = icmp sgt i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %52
%62 = load i32, i32* %13
%63 = add nsw i32 %62, 1
store i32 %63, i32* %11
br label %77
64: ; preds = %52
%65 = load i8*, i8** %8
%66 = load i8**, i8*** %7
%67 = load i32, i32* %13
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %66, i64 %68
%70 = load i8*, i8** %69
%71 = call i64 @strcmp(i8* %65, i8* %70)
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %64
%74 = load i32, i32* %13
%75 = sub nsw i32 %74, 1
store i32 %75, i32* %12
br label %76
76: ; preds = %73, %64
br label %77
77: ; preds = %76, %61
br label %78
78: ; preds = %77
br label %19
79: ; preds = %19
store i32 0, i32* %5
br label %80
80: ; preds = %79, %36
%81 = load i32, i32* %5
ret i32 %81
}

LLVM IR (-O2):
@.str = [15 x i8] c"dictionary.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [28 x i8] c"A permutation of %s is %s.\0A\00"
define i32 @checkdict(i32* nocapture %0, i8** nocapture %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%9 = call i32 @fclose(i32* %7)
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %42, label %12
12: ; preds = %4, %38
%13 = phi i32 [ %40, %38 ], [ %10, %4 ]
%14 = phi i32 [ %39, %38 ], [ 0, %4 ]
%15 = add nsw i32 %13, %14
%16 = sdiv i32 %15, 2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %2, i8* %19)
%21 = icmp eq i64 %20, 0
%22 = load i8*, i8** %18
br i1 %21, label %23, label %27
23: ; preds = %12
%24 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* %22)
%25 = load i8*, i8** %18
%26 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* %25)
br label %42
27: ; preds = %12
%28 = call i64 @strcmp(i8* %2, i8* %22)
%29 = icmp sgt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = add nsw i32 %16, 1
br label %38
32: ; preds = %27
%33 = load i8*, i8** %18
%34 = call i64 @strcmp(i8* %2, i8* %33)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = add nsw i32 %16, -1
store i32 %37, i32* %5
br label %38
38: ; preds = %30, %36, %32
%39 = phi i32 [ %31, %30 ], [ %14, %36 ], [ %14, %32 ]
%40 = load i32, i32* %5
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %12
42: ; preds = %38, %4, %23
%43 = phi i32 [ 1, %23 ], [ 0, %4 ], [ 0, %38 ]
ret i32 %43
}