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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, int *);
int /*<<< orphan*/ insert(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ strlen(char *);
int build_table_from_file(const char *file_name) {
  FILE *fp;
  char str[23];
  int val, cnt = 0;
  fp = fopen(file_name, "r");
  if (fp == NULL) {
    printf("File not found.\n");
    return -1;
  }
  while (fscanf(fp, "%s %d", str, &val) == 2) {
    insert(str, (uint)strlen(str), (uint)val);
    ++cnt;
  }
  fclose(fp);
  return cnt;
}


x86 assembly (clang, -O0):
<build_table_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11aa <build_table_from_file+0x4a>
lea    0xe69(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <build_table_from_file+0xac>
jmp    11af <build_table_from_file+0x4f>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe55(%rip),%rsi
lea    -0x34(%rbp),%rcx
call   1060 <fscanf@plt>
cmp    $0x2,%eax
jne    11fd <build_table_from_file+0x9d>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    -0x34(%rbp),%edx
call   1070 <insert@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11af <build_table_from_file+0x4f>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_table_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
lea    0xe8d(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f9 <build_table_from_file+0x99>
mov    %rax,%r14
lea    0xe7b(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rax,%rdi
call   1060 <fscanf@plt>
xor    %ebp,%ebp
cmp    $0x2,%eax
jne    11ef <build_table_from_file+0x8f>
xor    %ebp,%ebp
lea    0x10(%rsp),%rbx
lea    0xe54(%rip),%r15
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <insert@plt>
add    $0x1,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1060 <fscanf@plt>
cmp    $0x2,%eax
je     11c0 <build_table_from_file+0x60>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    120a <build_table_from_file+0xaa>
lea    0xe08(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [17 x i8] c"File not found.\0A\00"
@.str.2 = [6 x i8] c"%s %d\00"
define i32 @build_table_from_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [23 x i8]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %33
14: ; preds = %1
br label %15
15: ; preds = %20, %14
%16 = load i32*, i32** %4
%17 = getelementptr inbounds [23 x i8], [23 x i8]* %5, i64 0, i64 0
%18 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32* %6)
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %29
20: ; preds = %15
%21 = getelementptr inbounds [23 x i8], [23 x i8]* %5, i64 0, i64 0
%22 = getelementptr inbounds [23 x i8], [23 x i8]* %5, i64 0, i64 0
%23 = call i64 @strlen(i8* %22)
%24 = trunc i64 %23 to i32
%25 = load i32, i32* %6
%26 = call i32 @insert(i8* %21, i32 %24, i32 %25)
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %15
29: ; preds = %15
%30 = load i32*, i32** %4
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %7
store i32 %32, i32* %2
br label %33
33: ; preds = %29, %12
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%s %d\00"
@str = [16 x i8] c"File not found.\00"
define i32 @build_table_from_file(i8* nocapture %0) {
%2 = alloca [23 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32* %3)
%10 = icmp eq i32 %9, 2
br i1 %10, label %13, label %22
11: ; preds = %1
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %25
13: ; preds = %8, %13
%14 = phi i32 [ %19, %13 ], [ 0, %8 ]
%15 = call i64 @strlen(i8* %4)
%16 = trunc i64 %15 to i32
%17 = load i32, i32* %3
%18 = call i32 @insert(i8* %4, i32 %16, i32 %17)
%19 = add nuw nsw i32 %14, 1
%20 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32* %3)
%21 = icmp eq i32 %20, 2
br i1 %21, label %13, label %22
22: ; preds = %13, %8
%23 = phi i32 [ 0, %8 ], [ %19, %13 ]
%24 = call i32 @fclose(i32* %6)
br label %25
25: ; preds = %22, %11
%26 = phi i32 [ -1, %11 ], [ %23, %22 ]
ret i32 %26
}