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

/* Variables and functions */
unsigned char atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ set_ttl(int /*<<< orphan*/, unsigned char);
int /*<<< orphan*/ str2ip(char *);
int load_ttl_from_file(char *filename) {
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  FILE *fp = fopen(filename, "r");
  if (fp == NULL) {
    return 0;
  }
  while ((read = getline(&line, &len, fp)) != -1) {
    if (line[0] == '#')
      continue;
    if (read < 9)
      continue;
    char *ip = line;
    char *tmp;
    for (tmp = line; tmp != 0; tmp++) {
      if (*tmp == ',') {
        *tmp = 0;
        tmp++;
        break;
      }
    }
    unsigned char ttl = atoi(tmp);
    if (ip && ttl > 0)
      set_ttl(str2ip(ip), ttl);
  }
  if (line)
    free(line);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<load_ttl_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b7 <load_ttl_from_file+0x47>
movl   $0x0,-0x4(%rbp)
jmp    12b7 <load_ttl_from_file+0x147>
jmp    11bc <load_ttl_from_file+0x4c>
mov    -0x30(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1293 <load_ttl_from_file+0x123>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11ee <load_ttl_from_file+0x7e>
jmp    11bc <load_ttl_from_file+0x4c>
cmpl   $0x9,-0x24(%rbp)
jge    11fd <load_ttl_from_file+0x8d>
jmp    11bc <load_ttl_from_file+0x4c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1256 <load_ttl_from_file+0xe6>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
jne    1240 <load_ttl_from_file+0xd0>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1256 <load_ttl_from_file+0xe6>
jmp    1245 <load_ttl_from_file+0xd5>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    120d <load_ttl_from_file+0x9d>
mov    -0x40(%rbp),%rdi
call   1070 <atoi@plt>
mov    %al,-0x41(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     128e <load_ttl_from_file+0x11e>
movzbl -0x41(%rbp),%eax
cmp    $0x0,%eax
jle    128e <load_ttl_from_file+0x11e>
mov    -0x38(%rbp),%rdi
call   1050 <str2ip@plt>
mov    %eax,%edi
movzbl -0x41(%rbp),%esi
call   1090 <set_ttl@plt>
jmp    11bc <load_ttl_from_file+0x4c>
cmpq   $0x0,-0x18(%rbp)
je     12a7 <load_ttl_from_file+0x137>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_ttl_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe6c(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1247 <load_ttl_from_file+0xd7>
mov    %rax,%r12
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1231 <load_ttl_from_file+0xc1>
mov    %rsp,%r14
lea    0x8(%rsp),%r15
jmp    11e3 <load_ttl_from_file+0x73>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1231 <load_ttl_from_file+0xc1>
mov    (%rsp),%rbx
mov    (%rbx),%cl
cmp    $0x23,%cl
je     11d0 <load_ttl_from_file+0x60>
cmp    $0x9,%eax
jl     11d0 <load_ttl_from_file+0x60>
mov    %rbx,%rdi
cmp    $0x2c,%cl
je     120a <load_ttl_from_file+0x9a>
nopl   0x0(%rax,%rax,1)
cmpb   $0x2c,0x1(%rdi)
lea    0x1(%rdi),%rdi
jne    1200 <load_ttl_from_file+0x90>
movb   $0x0,(%rdi)
add    $0x1,%rdi
call   1070 <atoi@plt>
test   %al,%al
je     11d0 <load_ttl_from_file+0x60>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <str2ip@plt>
movzbl %bpl,%esi
mov    %eax,%edi
call   1090 <set_ttl@plt>
jmp    11d0 <load_ttl_from_file+0x60>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     123f <load_ttl_from_file+0xcf>
call   1030 <free@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @load_ttl_from_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8
store i8* %0, i8** %3
store i8* null, i8** %4
store i64 0, i64* %5
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 0, i32* %2
br label %75
16: ; preds = %1
br label %17
17: ; preds = %65, %31, %27, %16
%18 = load i32*, i32** %7
%19 = call i32 @getline(i8** %4, i64* %5, i32* %18)
store i32 %19, i32* %6
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %66
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 35
br i1 %26, label %27, label %28
27: ; preds = %21
br label %17
28: ; preds = %21
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 9
br i1 %30, label %31, label %32
31: ; preds = %28
br label %17
32: ; preds = %28
%33 = load i8*, i8** %4
store i8* %33, i8** %8
%34 = load i8*, i8** %4
store i8* %34, i8** %9
br label %35
35: ; preds = %48, %32
%36 = load i8*, i8** %9
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %51
38: ; preds = %35
%39 = load i8*, i8** %9
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 44
br i1 %42, label %43, label %47
43: ; preds = %38
%44 = load i8*, i8** %9
store i8 0, i8* %44
%45 = load i8*, i8** %9
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %9
br label %51
47: ; preds = %38
br label %48
48: ; preds = %47
%49 = load i8*, i8** %9
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %9
br label %35
51: ; preds = %43, %35
%52 = load i8*, i8** %9
%53 = call zeroext i8 @atoi(i8* %52)
store i8 %53, i8* %10
%54 = load i8*, i8** %8
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %65
56: ; preds = %51
%57 = load i8, i8* %10
%58 = zext i8 %57 to i32
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %56
%61 = load i8*, i8** %8
%62 = call i32 @str2ip(i8* %61)
%63 = load i8, i8* %10
%64 = call i32 @set_ttl(i32 %62, i8 zeroext %63)
br label %65
65: ; preds = %60, %56, %51
br label %17
66: ; preds = %17
%67 = load i8*, i8** %4
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i8*, i8** %4
%71 = call i32 @free(i8* %70)
br label %72
72: ; preds = %69, %66
%73 = load i32*, i32** %7
%74 = call i32 @fclose(i32* %73)
store i32 0, i32* %2
br label %75
75: ; preds = %72, %15
%76 = load i32, i32* %2
ret i32 %76
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @load_ttl_from_file(i8* nocapture %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%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 %43, label %8
8: ; preds = %1
%9 = call i32 @getline(i8** %2, i64* %3, i32* %6)
%10 = icmp eq i32 %9, -1
br i1 %10, label %36, label %11
11: ; preds = %8, %33
%12 = phi i32 [ %34, %33 ], [ %9, %8 ]
%13 = load i8*, i8** %2
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 35
%16 = icmp slt i32 %12, 9
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %33, label %18
18: ; preds = %11
%19 = icmp eq i8 %14, 44
br i1 %19, label %20, label %25
20: ; preds = %25, %18
%21 = phi i8* [ %13, %18 ], [ %27, %25 ]
store i8 0, i8* %21
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = call zeroext i8 @atoi(i8* %22)
%24 = icmp eq i8 %23, 0
br i1 %24, label %33, label %30
25: ; preds = %18, %25
%26 = phi i8* [ %27, %25 ], [ %13, %18 ]
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 44
br i1 %29, label %20, label %25
30: ; preds = %20
%31 = call i32 @str2ip(i8* %13)
%32 = call i32 @set_ttl(i32 %31, i8 zeroext %23)
br label %33
33: ; preds = %20, %30, %11
%34 = call i32 @getline(i8** %2, i64* %3, i32* %6)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %11
36: ; preds = %33, %8
%37 = load i8*, i8** %2
%38 = icmp eq i8* %37, null
br i1 %38, label %41, label %39
39: ; preds = %36
%40 = call i32 @free(i8* %37)
br label %41
41: ; preds = %39, %36
%42 = call i32 @fclose(i32* %6)
br label %43
43: ; preds = %1, %41
ret i32 0
}