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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
char *strerror(int /*<<< orphan*/);
int tagfile_add_tag(struct tagfile *, char *);
int tagfile_load(struct tagfile *tf, const char *filename) {
  FILE *f = fopen(filename, "r");
  char line[2048];
  int ret = 0;
  char *tab;
  if (f == NULL) {
    fprintf(stderr, "Could not open file '%s': %s\n", filename,
            strerror(errno));
    return -1;
  }
  while (!feof(f)) {
    tab = fgets(line, sizeof(line), f);
    if (tab == NULL)
      break;
    if (line[0] == '!')
      continue;
    tab = strchr(line, '\t');
    if (tab == NULL)
      continue;
    *tab = 0;
    ret = tagfile_add_tag(tf, line);
    if (ret != 0)
      break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<tagfile_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x824(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fc <tagfile_load+0x8c>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x83c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x838(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x83c(%rbp),%edi
mov    -0x838(%rbp),%rdx
mov    %rax,%rcx
lea    0xe17(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ce <tagfile_load+0x15e>
jmp    1201 <tagfile_load+0x91>
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    121f <tagfile_load+0xaf>
jmp    12c5 <tagfile_load+0x155>
lea    -0x820(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x800,%esi
call   1040 <fgets@plt>
mov    %rax,-0x830(%rbp)
cmpq   $0x0,-0x830(%rbp)
jne    124e <tagfile_load+0xde>
jmp    12c5 <tagfile_load+0x155>
movsbl -0x820(%rbp),%eax
cmp    $0x21,%eax
jne    1263 <tagfile_load+0xf3>
jmp    1201 <tagfile_load+0x91>
lea    -0x820(%rbp),%rdi
mov    $0x9,%esi
call   1030 <strchr@plt>
mov    %rax,-0x830(%rbp)
cmpq   $0x0,-0x830(%rbp)
jne    128e <tagfile_load+0x11e>
jmp    1201 <tagfile_load+0x91>
mov    -0x830(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1080 <tagfile_add_tag@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0x0,-0x824(%rbp)
je     12c0 <tagfile_load+0x150>
jmp    12c5 <tagfile_load+0x155>
jmp    1201 <tagfile_load+0x91>
mov    -0x824(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tagfile_load>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe76(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1210 <tagfile_load+0xa0>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
xor    %r15d,%r15d
test   %eax,%eax
jne    1241 <tagfile_load+0xd1>
mov    %rsp,%rbp
jmp    11cc <tagfile_load+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1241 <tagfile_load+0xd1>
mov    %rbp,%rdi
mov    $0x800,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1241 <tagfile_load+0xd1>
cmpb   $0x21,(%rsp)
je     11c0 <tagfile_load+0x50>
mov    %rbp,%rdi
mov    $0x9,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11c0 <tagfile_load+0x50>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1080 <tagfile_add_tag@plt>
test   %eax,%eax
je     11c0 <tagfile_load+0x50>
mov    %eax,%r15d
jmp    1241 <tagfile_load+0xd1>
mov    0x2dc9(%rip),%rax
mov    (%rax),%ebx
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdd4(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tagfile = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Could not open file '%s': %s\0A\00"
@errno = global i32 0
define i32 @tagfile_load(%struct.tagfile* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.tagfile*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [2048 x i8]
%8 = alloca i32
%9 = alloca i8*
store %struct.tagfile* %0, %struct.tagfile** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
store i32 0, i32* %8
%12 = load i32*, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %5
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %18)
store i32 -1, i32* %3
br label %56
20: ; preds = %2
br label %21
21: ; preds = %53, %44, %38, %20
%22 = load i32*, i32** %6
%23 = call i32 @feof(i32* %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %54
26: ; preds = %21
%27 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%28 = load i32*, i32** %6
%29 = call i8* @fgets(i8* %27, i32 2048, i32* %28)
store i8* %29, i8** %9
%30 = load i8*, i8** %9
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %26
br label %54
33: ; preds = %26
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 33
br i1 %37, label %38, label %39
38: ; preds = %33
br label %21
39: ; preds = %33
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%41 = call i8* @strchr(i8* %40, i8 signext 9)
store i8* %41, i8** %9
%42 = load i8*, i8** %9
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %45
44: ; preds = %39
br label %21
45: ; preds = %39
%46 = load i8*, i8** %9
store i8 0, i8* %46
%47 = load %struct.tagfile*, %struct.tagfile** %4
%48 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%49 = call i32 @tagfile_add_tag(%struct.tagfile* %47, i8* %48)
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %45
br label %54
53: ; preds = %45
br label %21
54: ; preds = %52, %32, %21
%55 = load i32, i32* %8
store i32 %55, i32* %3
br label %56
56: ; preds = %54, %14
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
%struct.tagfile = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Could not open file '%s': %s\0A\00"
@errno = global i32 0
define i32 @tagfile_load(%struct.tagfile* %0, i8* %1) {
%3 = alloca [2048 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 [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%6 = icmp eq i32* %4, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32 @feof(i32* %4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %15, label %30
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %13)
br label %30
15: ; preds = %7, %21
%16 = call i8* @fgets(i8* %5, i32 2048, i32* %4)
%17 = icmp eq i8* %16, null
br i1 %17, label %30, label %18
18: ; preds = %15
%19 = load i8, i8* %5
%20 = icmp eq i8 %19, 33
br i1 %20, label %21, label %24
21: ; preds = %18, %24, %27
%22 = call i32 @feof(i32* %4)
%23 = icmp eq i32 %22, 0
br i1 %23, label %15, label %30
24: ; preds = %18
%25 = call i8* @strchr(i8* %5, i8 signext 9)
%26 = icmp eq i8* %25, null
br i1 %26, label %21, label %27
27: ; preds = %24
store i8 0, i8* %25
%28 = call i32 @tagfile_add_tag(%struct.tagfile* %0, i8* %5)
%29 = icmp eq i32 %28, 0
br i1 %29, label %21, label %30
30: ; preds = %27, %15, %21, %7, %10
%31 = phi i32 [ -1, %10 ], [ 0, %7 ], [ %28, %27 ], [ 0, %15 ], [ 0, %21 ]
ret i32 %31
}