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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int opt_parse_line(char *, char **);
int opt_loadfile(const char *fname, int *lineno) {
  char buffer[4096], *group;
  FILE *fp;
  int istat;
  if (lineno)
    *lineno = 0;
  if (!fname)
    return (1);
  fp = fopen(fname, "r");
  if (!fp)
    return (5);
  group = NULL;
  while (fgets(buffer, sizeof(buffer), fp) != NULL) {
    if (lineno)
      *lineno += 1;
    if ((istat = opt_parse_line(buffer, &group)))
      break;
  }
  if (ferror(fp))
    istat = 6;
  if (group)
    free(group);
  if (fp != NULL)
    fclose(fp);
  return (istat);
}


x86 assembly (clang, -O0):
<opt_loadfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1188 <opt_loadfile+0x28>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    119f <opt_loadfile+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    129c <opt_loadfile+0x13c>
mov    -0x10(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x1030(%rbp)
cmpq   $0x0,-0x1030(%rbp)
jne    11d0 <opt_loadfile+0x70>
movl   $0x5,-0x4(%rbp)
jmp    129c <opt_loadfile+0x13c>
movq   $0x0,-0x1028(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x1030(%rbp),%rdx
mov    $0x1000,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     123f <opt_loadfile+0xdf>
cmpq   $0x0,-0x18(%rbp)
je     1213 <opt_loadfile+0xb3>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
lea    -0x1020(%rbp),%rdi
lea    -0x1028(%rbp),%rsi
call   1070 <opt_parse_line@plt>
mov    %eax,-0x1034(%rbp)
cmp    $0x0,%eax
je     123a <opt_loadfile+0xda>
jmp    123f <opt_loadfile+0xdf>
jmp    11db <opt_loadfile+0x7b>
mov    -0x1030(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     125f <opt_loadfile+0xff>
movl   $0x6,-0x1034(%rbp)
cmpq   $0x0,-0x1028(%rbp)
je     1279 <opt_loadfile+0x119>
mov    -0x1028(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x1030(%rbp)
je     1293 <opt_loadfile+0x133>
mov    -0x1030(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1034(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_loadfile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1010,%rsp
mov    %rsi,%rbx
test   %rsi,%rsi
je     117d <opt_loadfile+0x1d>
movl   $0x0,(%rbx)
test   %rdi,%rdi
je     11de <opt_loadfile+0x7e>
lea    0xe77(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e5 <opt_loadfile+0x85>
mov    %rax,%r14
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
jmp    11bf <opt_loadfile+0x5f>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <opt_parse_line@plt>
test   %eax,%eax
jne    11ec <opt_loadfile+0x8c>
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11f0 <opt_loadfile+0x90>
test   %rbx,%rbx
je     11b0 <opt_loadfile+0x50>
addl   $0x1,(%rbx)
jmp    11b0 <opt_loadfile+0x50>
mov    $0x1,%ebx
jmp    121c <opt_loadfile+0xbc>
mov    $0x5,%ebx
jmp    121c <opt_loadfile+0xbc>
mov    %eax,%ebp
jmp    11f2 <opt_loadfile+0x92>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
mov    $0x6,%ebx
cmove  %ebp,%ebx
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1214 <opt_loadfile+0xb4>
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %ebx,%eax
add    $0x1010,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @opt_loadfile(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [4096 x i8]
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32*, i32** %5
store i32 0, i32* %13
br label %14
14: ; preds = %12, %2
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14
store i32 1, i32* %3
br label %62
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %8
%21 = load i32*, i32** %8
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %18
store i32 5, i32* %3
br label %62
24: ; preds = %18
store i8* null, i8** %7
br label %25
25: ; preds = %42, %24
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%27 = load i32*, i32** %8
%28 = call i32* @fgets(i8* %26, i32 4096, i32* %27)
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %43
30: ; preds = %25
%31 = load i32*, i32** %5
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32*, i32** %5
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1
store i32 %36, i32* %34
br label %37
37: ; preds = %33, %30
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%39 = call i32 @opt_parse_line(i8* %38, i8** %7)
store i32 %39, i32* %9
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
br label %43
42: ; preds = %37
br label %25
43: ; preds = %41, %25
%44 = load i32*, i32** %8
%45 = call i64 @ferror(i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %43
store i32 6, i32* %9
br label %48
48: ; preds = %47, %43
%49 = load i8*, i8** %7
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i8*, i8** %7
%53 = call i32 @free(i8* %52)
br label %54
54: ; preds = %51, %48
%55 = load i32*, i32** %8
%56 = icmp ne i32* %55, null
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = load i32*, i32** %8
%59 = call i32 @fclose(i32* %58)
br label %60
60: ; preds = %57, %54
%61 = load i32, i32* %9
store i32 %61, i32* %3
br label %62
62: ; preds = %60, %23, %17
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @opt_loadfile(i8* %0, i32* %1) {
%3 = alloca [4096 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = icmp eq i32* %1, null
br i1 %7, label %9, label %8
8: ; preds = %2
store i32 0, i32* %1
br label %9
9: ; preds = %8, %2
%10 = icmp eq i8* %0, null
br i1 %10, label %36, label %11
11: ; preds = %9
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %36, label %14
14: ; preds = %11
store i8* null, i8** %4
br label %15
15: ; preds = %22, %14
%16 = call i32* @fgets(i8* %5, i32 4096, i32* %12)
%17 = icmp eq i32* %16, null
br i1 %17, label %25, label %18
18: ; preds = %15
br i1 %7, label %22, label %19
19: ; preds = %18
%20 = load i32, i32* %1
%21 = add nsw i32 %20, 1
store i32 %21, i32* %1
br label %22
22: ; preds = %19, %18
%23 = call i32 @opt_parse_line(i8* %5, i8** %4)
%24 = icmp eq i32 %23, 0
br i1 %24, label %15, label %25
25: ; preds = %22, %15
%26 = phi i32 [ %23, %22 ], [ 0, %15 ]
%27 = call i64 @ferror(i32* %12)
%28 = icmp eq i64 %27, 0
%29 = select i1 %28, i32 %26, i32 6
%30 = load i8*, i8** %4
%31 = icmp eq i8* %30, null
br i1 %31, label %34, label %32
32: ; preds = %25
%33 = call i32 @free(i8* %30)
br label %34
34: ; preds = %25, %32
%35 = call i32 @fclose(i32* %12)
br label %36
36: ; preds = %11, %9, %34
%37 = phi i32 [ %29, %34 ], [ 1, %9 ], [ 5, %11 ]
ret i32 %37
}