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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
char *strchr(char *, char);
int xdict_addword(struct xdict *, char *, int);
int /*<<< orphan*/ xdict_sort(struct xdict *);
int xdict_load(struct xdict *d, const char *fname) {
  FILE *in = fopen(fname, "r");
  char buffer[16 + 25];
  int rc = 0;
  if (in == NULL)
    return -1;
  while (fgets(buffer, (sizeof buffer) - 5, in) != NULL) {
    char *p = strchr(buffer, '\n');
    int rc;
    if (p == NULL) {
      rc = -2;
      goto done;
    }
    *p = '\0';
    rc = xdict_addword(d, buffer, p - buffer);
    if (rc < -1)
      goto done;
  }
done:
  fclose(in);
  xdict_sort(d);
  return rc;
}


x86 assembly (clang, -O0):
<xdict_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x54(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a2 <xdict_load+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <xdict_load+0xe1>
jmp    11a7 <xdict_load+0x47>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x24,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1224 <xdict_load+0xc4>
lea    -0x50(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    11ec <xdict_load+0x8c>
movl   $0xfffffffe,-0x64(%rbp)
jmp    1229 <xdict_load+0xc9>
mov    -0x60(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x60(%rbp),%rax
lea    -0x50(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1080 <xdict_addword@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jge    121f <xdict_load+0xbf>
jmp    1229 <xdict_load+0xc9>
jmp    11a7 <xdict_load+0x47>
jmp    1229 <xdict_load+0xc9>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1040 <xdict_sort@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xdict_load>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe8a(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e2 <xdict_load+0x82>
mov    %rax,%r15
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x24,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11ce <xdict_load+0x6e>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11ce <xdict_load+0x6e>
movb   $0x0,(%rax)
sub    %ebx,%eax
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1080 <xdict_addword@plt>
cmp    $0xfffffffe,%eax
jg     1190 <xdict_load+0x30>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1040 <xdict_sort@plt>
xor    %eax,%eax
jmp    11e7 <xdict_load+0x87>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.xdict = type { i32 }
@.str = [2 x i8] c"r\00"
define i32 @xdict_load(%struct.xdict* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.xdict*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [41 x i8]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store %struct.xdict* %0, %struct.xdict** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
store i32 0, i32* %8
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %50
16: ; preds = %2
br label %17
17: ; preds = %42, %16
%18 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 0
%19 = load i32*, i32** %6
%20 = call i32* @fgets(i8* %18, i32 36, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %43
22: ; preds = %17
%23 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 0
%24 = call i8* @strchr(i8* %23, i8 signext 10)
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 -2, i32* %10
br label %44
28: ; preds = %22
%29 = load i8*, i8** %9
store i8 0, i8* %29
%30 = load %struct.xdict*, %struct.xdict** %4
%31 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 0
%32 = load i8*, i8** %9
%33 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 0
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = trunc i64 %36 to i32
%38 = call i32 @xdict_addword(%struct.xdict* %30, i8* %31, i32 %37)
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp slt i32 %39, -1
br i1 %40, label %41, label %42
41: ; preds = %28
br label %44
42: ; preds = %28
br label %17
43: ; preds = %17
br label %44
44: ; preds = %43, %41, %27
%45 = load i32*, i32** %6
%46 = call i32 @fclose(i32* %45)
%47 = load %struct.xdict*, %struct.xdict** %4
%48 = call i32 @xdict_sort(%struct.xdict* %47)
%49 = load i32, i32* %8
store i32 %49, i32* %3
br label %50
50: ; preds = %44, %15
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
%struct.xdict = type { i32 }
@.str = [2 x i8] c"r\00"
define i32 @xdict_load(%struct.xdict* %0, i8* nocapture %1) {
%3 = alloca [41 x i8]
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 0
%6 = icmp eq i32* %4, null
br i1 %6, label %24, label %7
7: ; preds = %2
%8 = ptrtoint [41 x i8]* %3 to i64
br label %9
9: ; preds = %7, %15
%10 = call i32* @fgets(i8* %5, i32 36, i32* %4)
%11 = icmp eq i32* %10, null
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = call i8* @strchr(i8* %5, i8 signext 10)
%14 = icmp eq i8* %13, null
br i1 %14, label %21, label %15
15: ; preds = %12
store i8 0, i8* %13
%16 = ptrtoint i8* %13 to i64
%17 = sub i64 %16, %8
%18 = trunc i64 %17 to i32
%19 = call i32 @xdict_addword(%struct.xdict* %0, i8* %5, i32 %18)
%20 = icmp slt i32 %19, -1
br i1 %20, label %21, label %9
21: ; preds = %15, %12, %9
%22 = call i32 @fclose(i32* %4)
%23 = call i32 @xdict_sort(%struct.xdict* %0)
br label %24
24: ; preds = %2, %21
%25 = phi i32 [ 0, %21 ], [ -1, %2 ]
ret i32 %25
}