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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ init_from_string(char *, int);
int /*<<< orphan*/ log_fatal(char const *, char *, char const *, char *, ...);
scalar_t__ sscanf(char *, char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int init_from_file(char *file, const char *name, int value,
                   int ignore_invalid_hosts) {
  FILE *fp;
  char line[1000];
  fp = fopen(file, "r");
  if (fp == NULL) {
    log_fatal(name, "unable to open %s file: %s: %s", name, file,
              strerror(errno));
  }
  while (fgets(line, sizeof(line), fp) != NULL) {
    char *comment = strchr(line, '#');
    if (comment) {
      *comment = '\0';
    }
    char ip[256];
    if ((sscanf(line, "%256s", ip)) == EOF) {
      continue;
    }
    if (init_from_string(ip, value)) {
      if (!ignore_invalid_hosts) {
        log_fatal(name, "unable to parse %s file: %s", name, file);
      }
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<init_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x540,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120d <init_from_file+0x8d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x538(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x530(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x528(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x538(%rbp),%rdi
mov    -0x530(%rbp),%rdx
mov    -0x528(%rbp),%rcx
mov    %eax,%r8d
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1090 <log_fatal@plt>
jmp    1212 <init_from_file+0x92>
lea    -0x410(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12d7 <init_from_file+0x157>
lea    -0x410(%rbp),%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     1261 <init_from_file+0xe1>
mov    -0x418(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x410(%rbp),%rdi
lea    -0x520(%rbp),%rdx
lea    0xdab(%rip),%rsi
call   1070 <sscanf@plt>
mov    0x2d66(%rip),%rcx
cmp    (%rcx),%rax
jne    1290 <init_from_file+0x110>
jmp    1212 <init_from_file+0x92>
lea    -0x520(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <init_from_string@plt>
cmp    $0x0,%rax
je     12d2 <init_from_file+0x152>
cmpl   $0x0,-0x18(%rbp)
jne    12cd <init_from_file+0x14d>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xd61(%rip),%rsi
mov    $0x0,%al
call   1090 <log_fatal@plt>
jmp    12d2 <init_from_file+0x152>
jmp    1212 <init_from_file+0x92>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x540,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4f8,%rsp
mov    %ecx,0x4(%rsp)
mov    %edx,(%rsp)
mov    %rsi,%r13
lea    0xe5e(%rip),%rsi
mov    %rdi,0x8(%rsp)
call   1080 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11de <init_from_file+0x5e>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe39(%rip),%rsi
mov    %r13,%rdi
mov    %r13,%rdx
mov    0x8(%rsp),%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1090 <log_fatal@plt>
lea    0x110(%rsp),%rdi
mov    $0x3e8,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1290 <init_from_file+0x110>
lea    0x110(%rsp),%rbx
lea    0xe16(%rip),%r15
lea    0x10(%rsp),%r14
mov    0x2dd1(%rip),%r12
jmp    1235 <init_from_file+0xb5>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1290 <init_from_file+0x110>
mov    %rbx,%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     124a <init_from_file+0xca>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <sscanf@plt>
cmp    (%r12),%rax
je     1220 <init_from_file+0xa0>
mov    %r14,%rdi
mov    (%rsp),%esi
call   1060 <init_from_string@plt>
cmpl   $0x0,0x4(%rsp)
jne    1220 <init_from_file+0xa0>
test   %rax,%rax
je     1220 <init_from_file+0xa0>
mov    %r13,%rdi
lea    0xda8(%rip),%rsi
mov    %r13,%rdx
mov    0x8(%rsp),%rcx
xor    %eax,%eax
call   1090 <log_fatal@plt>
jmp    1220 <init_from_file+0xa0>
mov    %rbp,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x4f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"unable to open %s file: %s: %s\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"%256s\00"
@EOF = global i64 0
@.str.3 = [28 x i8] c"unable to parse %s file: %s\00"
define i32 @init_from_file(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca [1000 x i8]
%11 = alloca i8*
%12 = alloca [256 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %9
%15 = load i32*, i32** %9
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %24
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = load i8*, i8** %6
%20 = load i8*, i8** %5
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 (i8*, i8*, i8*, i8*, ...) @log_fatal(i8* %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20, i32 %22)
br label %24
24: ; preds = %17, %4
br label %25
25: ; preds = %58, %43, %24
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%27 = load i32*, i32** %9
%28 = call i32* @fgets(i8* %26, i32 1000, i32* %27)
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %59
30: ; preds = %25
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%32 = call i8* @strchr(i8* %31, i8 signext 35)
store i8* %32, i8** %11
%33 = load i8*, i8** %11
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = load i8*, i8** %11
store i8 0, i8* %36
br label %37
37: ; preds = %35, %30
%38 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%40 = call i64 @sscanf(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = load i64, i64* @EOF
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %37
br label %25
44: ; preds = %37
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%46 = load i32, i32* %7
%47 = call i64 @init_from_string(i8* %45, i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %58
49: ; preds = %44
%50 = load i32, i32* %8
%51 = icmp ne i32 %50, 0
br i1 %51, label %57, label %52
52: ; preds = %49
%53 = load i8*, i8** %6
%54 = load i8*, i8** %6
%55 = load i8*, i8** %5
%56 = call i32 (i8*, i8*, i8*, i8*, ...) @log_fatal(i8* %53, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %54, i8* %55)
br label %57
57: ; preds = %52, %49
br label %58
58: ; preds = %57, %44
br label %25
59: ; preds = %25
%60 = load i32*, i32** %9
%61 = call i32 @fclose(i32* %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"unable to open %s file: %s: %s\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"%256s\00"
@EOF = global i64 0
@.str.3 = [28 x i8] c"unable to parse %s file: %s\00"
define i32 @init_from_file(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [1000 x i8]
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = load i32, i32* @errno
%12 = tail call i32 @strerror(i32 %11)
%13 = tail call i32 (i8*, i8*, i8*, i8*, ...) @log_fatal(i8* %1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %0, i32 %12)
br label %14
14: ; preds = %10, %4
%15 = call i32* @fgets(i8* %7, i32 1000, i32* %8)
%16 = icmp eq i32* %15, null
br i1 %16, label %37, label %17
17: ; preds = %14
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%19 = icmp ne i32 %3, 0
br label %20
20: ; preds = %17, %34
%21 = call i8* @strchr(i8* %7, i8 signext 35)
%22 = icmp eq i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %20
store i8 0, i8* %21
br label %24
24: ; preds = %23, %20
%25 = call i64 @sscanf(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
br i1 %27, label %34, label %28
28: ; preds = %24
%29 = call i64 @init_from_string(i8* %18, i32 %2)
%30 = icmp eq i64 %29, 0
%31 = or i1 %19, %30
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = call i32 (i8*, i8*, i8*, i8*, ...) @log_fatal(i8* %1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %0)
br label %34
34: ; preds = %28, %32, %24
%35 = call i32* @fgets(i8* %7, i32 1000, i32* %8)
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %20
37: ; preds = %34, %14
%38 = call i32 @fclose(i32* %8)
ret i32 0
}