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

/* Variables and functions */
int /*<<< orphan*/ add_host(char *, char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int read_thing(char *, char *);
scalar_t__ strchr(char *, char);
scalar_t__ strlen(char *);
void read_hosts(char *fname) {
  FILE *fp;
  char buf[512], ip[512], host[512];
  int skip, n;
  fp = fopen(fname, "r");
  if (!fp)
    return;
  while (fgets(buf, sizeof(buf), fp)) {
    if (strchr(buf, '#'))
      continue;
    skip = read_thing(buf, ip);
    if (!strlen(ip))
      continue;
    while (n = read_thing(buf + skip, host)) {
      skip += n;
      if (strlen(host))
        add_host(ip, host);
    }
  }
}


x86 assembly (clang, -O0):
<read_hosts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x620,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1193 <read_hosts+0x33>
jmp    1281 <read_hosts+0x121>
jmp    1198 <read_hosts+0x38>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1281 <read_hosts+0x121>
lea    -0x210(%rbp),%rdi
mov    $0x23,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     11d7 <read_hosts+0x77>
jmp    1198 <read_hosts+0x38>
lea    -0x210(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1030 <read_thing@plt>
mov    %eax,-0x614(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    120b <read_hosts+0xab>
jmp    1198 <read_hosts+0x38>
jmp    1210 <read_hosts+0xb0>
lea    -0x210(%rbp),%rdi
movslq -0x614(%rbp),%rax
add    %rax,%rdi
lea    -0x610(%rbp),%rsi
call   1030 <read_thing@plt>
mov    %eax,-0x618(%rbp)
cmp    $0x0,%eax
je     127c <read_hosts+0x11c>
mov    -0x618(%rbp),%eax
add    -0x614(%rbp),%eax
mov    %eax,-0x614(%rbp)
lea    -0x610(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     1277 <read_hosts+0x117>
lea    -0x410(%rbp),%rdi
lea    -0x610(%rbp),%rsi
call   1080 <add_host@plt>
jmp    1210 <read_hosts+0xb0>
jmp    1198 <read_hosts+0x38>
add    $0x620,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_hosts>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x600,%rsp
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1220 <read_hosts+0xd0>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1220 <read_hosts+0xd0>
mov    %rsp,%r15
lea    0x400(%rsp),%r12
lea    0x200(%rsp),%rbx
jmp    11c5 <read_hosts+0x75>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    $0x200,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1220 <read_hosts+0xd0>
mov    %r15,%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11b0 <read_hosts+0x60>
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <read_thing@plt>
cmpb   $0x0,0x400(%rsp)
je     11b0 <read_hosts+0x60>
mov    %eax,%ebp
xchg   %ax,%ax
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rdi
mov    %rbx,%rsi
call   1030 <read_thing@plt>
test   %eax,%eax
je     11b0 <read_hosts+0x60>
mov    %ebp,%ecx
mov    %eax,%ebp
add    %ecx,%ebp
cmpb   $0x0,0x200(%rsp)
je     11f0 <read_hosts+0xa0>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <add_host@plt>
jmp    11f0 <read_hosts+0xa0>
add    $0x600,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define void @read_hosts(i8* nocapture %0) {
%2 = alloca [512 x i8]
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, 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 %41, label %10
10: ; preds = %1
%11 = call i64 @fgets(i8* %5, i32 512, i32* %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %41, label %13
13: ; preds = %10, %16
%14 = call i64 @strchr(i8* %5, i8 signext 35)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %36, %23, %13, %19
%17 = call i64 @fgets(i8* %5, i32 512, i32* %8)
%18 = icmp eq i64 %17, 0
br i1 %18, label %41, label %13
19: ; preds = %13
%20 = call i32 @read_thing(i8* %5, i8* %6)
%21 = load i8, i8* %6
%22 = icmp eq i8 %21, 0
br i1 %22, label %16, label %23
23: ; preds = %19
%24 = sext i32 %20 to i64
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %24
%26 = call i32 @read_thing(i8* %25, i8* %7)
%27 = icmp eq i32 %26, 0
br i1 %27, label %16, label %28
28: ; preds = %23, %36
%29 = phi i32 [ %39, %36 ], [ %26, %23 ]
%30 = phi i32 [ %31, %36 ], [ %20, %23 ]
%31 = add nsw i32 %29, %30
%32 = load i8, i8* %7
%33 = icmp eq i8 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %28
%35 = call i32 @add_host(i8* %6, i8* %7)
br label %36
36: ; preds = %34, %28
%37 = sext i32 %31 to i64
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %37
%39 = call i32 @read_thing(i8* %38, i8* %7)
%40 = icmp eq i32 %39, 0
br i1 %40, label %16, label %28
41: ; preds = %16, %10, %1
ret void
}