#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ process_line(char *);
char *strchr(char *, char);
int /*<<< orphan*/ trunc_str(char *, char);
int read_label_file(const char *file_name) {
  int num_labels = 0;
  FILE *fd = fopen(file_name, "r");
  char line[512];
  if (!fd) {
    return -1;
  }
  while (fgets(line, 512 - 1, fd) != NULL) {
    char *semi = strchr(line, ';');
    trunc_str(line, '\n');
    trunc_str(line, ';');
    process_line(line);
  }
  fclose(fd);
  return num_labels;
}


x86 assembly (clang, -O0):
<read_label_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a1 <read_label_file+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    121f <read_label_file+0xbf>
jmp    11a6 <read_label_file+0x46>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1ff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1210 <read_label_file+0xb0>
lea    -0x220(%rbp),%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x228(%rbp)
lea    -0x220(%rbp),%rdi
mov    $0xa,%esi
call   1060 <trunc_str@plt>
lea    -0x220(%rbp),%rdi
mov    $0x3b,%esi
call   1060 <trunc_str@plt>
lea    -0x220(%rbp),%rdi
call   1080 <process_line@plt>
jmp    11a6 <read_label_file+0x46>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_label_file>:
push   %r14
push   %rbx
sub    $0x208,%rsp
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d3 <read_label_file+0x83>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1ff,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11c7 <read_label_file+0x77>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <trunc_str@plt>
mov    %rbx,%rdi
mov    $0x3b,%esi
call   1050 <trunc_str@plt>
mov    %rbx,%rdi
call   1070 <process_line@plt>
mov    %rbx,%rdi
mov    $0x1ff,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1190 <read_label_file+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11d8 <read_label_file+0x88>
mov    $0xffffffff,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @read_label_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [512 x i8]
%7 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
%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** %5
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store i32 -1, i32* %2
br label %32
13: ; preds = %1
br label %14
14: ; preds = %19, %13
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i32* @fgets(i8* %15, i32 511, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %28
19: ; preds = %14
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%21 = call i8* @strchr(i8* %20, i8 signext 59)
store i8* %21, i8** %7
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%23 = call i32 @trunc_str(i8* %22, i8 signext 10)
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%25 = call i32 @trunc_str(i8* %24, i8 signext 59)
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%27 = call i32 @process_line(i8* %26)
br label %14
28: ; preds = %14
%29 = load i32*, i32** %5
%30 = call i32 @fclose(i32* %29)
%31 = load i32, i32* %4
store i32 %31, i32* %2
br label %32
32: ; preds = %28, %12
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @read_label_file(i8* nocapture %0) {
%2 = alloca [512 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = icmp eq i32* %3, null
br i1 %5, label %17, label %6
6: ; preds = %1
%7 = call i32* @fgets(i8* %4, i32 511, i32* %3)
%8 = icmp eq i32* %7, null
br i1 %8, label %15, label %9
9: ; preds = %6, %9
%10 = call i32 @trunc_str(i8* %4, i8 signext 10)
%11 = call i32 @trunc_str(i8* %4, i8 signext 59)
%12 = call i32 @process_line(i8* %4)
%13 = call i32* @fgets(i8* %4, i32 511, i32* %3)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %9
15: ; preds = %9, %6
%16 = call i32 @fclose(i32* %3)
br label %17
17: ; preds = %1, %15
%18 = phi i32 [ 0, %15 ], [ -1, %1 ]
ret i32 %18
}