#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 rtgtargets {
  int dummy;
};
struct rtgconf {
  int dummy;
};
struct queryhost {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, ...);
struct queryhost *read_host(int /*<<< orphan*/ *, char *,
                            struct rtgconf const *);
struct rtgtargets *rtgtargets_create();
int /*<<< orphan*/ rtgtargets_push_host(struct rtgtargets *,
                                        struct queryhost *);
int /*<<< orphan*/ strclean(int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
char *strdup(char *);
int /*<<< orphan*/ strtolower(char *);
struct rtgtargets *read_new_style_targets(const char *filename,
                                          const struct rtgconf *conf) {
  struct rtgtargets *targets = rtgtargets_create();
  FILE *fileptr;
  char token[513];
  fileptr = fopen(filename, "rb");
  if (!fileptr)
    return targets;
  while (fscanf(fileptr, " %512s", token) == 1) {
    strclean(strtolower(token));
    if (token[0] == '#') {
      int result = fscanf(fileptr, "%*[^\n]");
      (void)result;
      continue;
    }
    if (!strcmp(token, "host")) {
      int result = fscanf(fileptr, " %512s", token);
      char *host_name = strdup(token);
      struct queryhost *host = read_host(fileptr, host_name, conf);
      rtgtargets_push_host(targets, host);
      (void)result;
    }
  }
  fclose(fileptr);
  return targets;
}


x86 assembly (clang, -O0):
<read_new_style_targets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1030 <rtgtargets_create@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ea <read_new_style_targets+0x4a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12e0 <read_new_style_targets+0x140>
jmp    11ef <read_new_style_targets+0x4f>
mov    -0x28(%rbp),%rdi
lea    -0x230(%rbp),%rdx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    12cf <read_new_style_targets+0x12f>
lea    -0x230(%rbp),%rdi
call   1050 <strtolower@plt>
mov    %eax,%edi
call   10a0 <strclean@plt>
movsbl -0x230(%rbp),%eax
cmp    $0x23,%eax
jne    1251 <read_new_style_targets+0xb1>
mov    -0x28(%rbp),%rdi
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    %eax,-0x234(%rbp)
jmp    11ef <read_new_style_targets+0x4f>
lea    -0x230(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    12ca <read_new_style_targets+0x12a>
mov    -0x28(%rbp),%rdi
lea    -0x230(%rbp),%rdx
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    %eax,-0x238(%rbp)
lea    -0x230(%rbp),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x240(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x240(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <read_host@plt>
mov    %rax,-0x248(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x248(%rbp),%rsi
call   1080 <rtgtargets_push_host@plt>
jmp    11ef <read_new_style_targets+0x4f>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_new_style_targets>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,0x8(%rsp)
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <rtgtargets_create@plt>
mov    %rax,%r15
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1295 <read_new_style_targets+0x105>
mov    %rax,%rbx
lea    0xe2e(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    128d <read_new_style_targets+0xfd>
lea    0x10(%rsp),%r12
lea    0xe11(%rip),%r13
lea    0xe03(%rip),%rbp
mov    $0x74736f68,%r14d
jmp    1232 <read_new_style_targets+0xa2>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <fscanf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    128d <read_new_style_targets+0xfd>
mov    %r12,%rdi
call   1050 <strtolower@plt>
mov    %eax,%edi
call   1090 <strclean@plt>
cmpb   $0x23,0x10(%rsp)
je     1210 <read_new_style_targets+0x80>
mov    0x10(%rsp),%eax
xor    %r14d,%eax
movzbl 0x14(%rsp),%ecx
or     %eax,%ecx
jne    121d <read_new_style_targets+0x8d>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
mov    %r12,%rdi
call   10b0 <strdup@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    0x8(%rsp),%rdx
call   1070 <read_host@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1080 <rtgtargets_push_host@plt>
jmp    121d <read_new_style_targets+0x8d>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rtgtargets = type { i32 }
%struct.rtgconf = type { i32 }
%struct.queryhost = type { i32 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [7 x i8] c" %512s\00"
@.str.2 = [7 x i8] c"%*[^\0A]\00"
@.str.3 = [5 x i8] c"host\00"
define %struct.rtgtargets* @read_new_style_targets(i8* %0, %struct.rtgconf* %1) {
%3 = alloca %struct.rtgtargets*
%4 = alloca i8*
%5 = alloca %struct.rtgconf*
%6 = alloca %struct.rtgtargets*
%7 = alloca i32*
%8 = alloca [513 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca %struct.queryhost*
store i8* %0, i8** %4
store %struct.rtgconf* %1, %struct.rtgconf** %5
%13 = call %struct.rtgtargets* (...) @rtgtargets_create()
store %struct.rtgtargets* %13, %struct.rtgtargets** %6
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = icmp ne i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %2
%19 = load %struct.rtgtargets*, %struct.rtgtargets** %6
store %struct.rtgtargets* %19, %struct.rtgtargets** %3
br label %61
20: ; preds = %2
br label %21
21: ; preds = %56, %34, %20
%22 = load i32*, i32** %7
%23 = getelementptr inbounds [513 x i8], [513 x i8]* %8, i64 0, i64 0
%24 = call i32 (i32*, i8*, ...) @fscanf(i32* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %57
26: ; preds = %21
%27 = getelementptr inbounds [513 x i8], [513 x i8]* %8, i64 0, i64 0
%28 = call i32 @strtolower(i8* %27)
%29 = call i32 @strclean(i32 %28)
%30 = getelementptr inbounds [513 x i8], [513 x i8]* %8, i64 0, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 35
br i1 %33, label %34, label %38
34: ; preds = %26
%35 = load i32*, i32** %7
%36 = call i32 (i32*, i8*, ...) @fscanf(i32* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 %36, i32* %9
%37 = load i32, i32* %9
br label %21
38: ; preds = %26
%39 = getelementptr inbounds [513 x i8], [513 x i8]* %8, i64 0, i64 0
%40 = call i32 @strcmp(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%41 = icmp ne i32 %40, 0
br i1 %41, label %56, label %42
42: ; preds = %38
%43 = load i32*, i32** %7
%44 = getelementptr inbounds [513 x i8], [513 x i8]* %8, i64 0, i64 0
%45 = call i32 (i32*, i8*, ...) @fscanf(i32* %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %44)
store i32 %45, i32* %10
%46 = getelementptr inbounds [513 x i8], [513 x i8]* %8, i64 0, i64 0
%47 = call i8* @strdup(i8* %46)
store i8* %47, i8** %11
%48 = load i32*, i32** %7
%49 = load i8*, i8** %11
%50 = load %struct.rtgconf*, %struct.rtgconf** %5
%51 = call %struct.queryhost* @read_host(i32* %48, i8* %49, %struct.rtgconf* %50)
store %struct.queryhost* %51, %struct.queryhost** %12
%52 = load %struct.rtgtargets*, %struct.rtgtargets** %6
%53 = load %struct.queryhost*, %struct.queryhost** %12
%54 = call i32 @rtgtargets_push_host(%struct.rtgtargets* %52, %struct.queryhost* %53)
%55 = load i32, i32* %10
br label %56
56: ; preds = %42, %38
br label %21
57: ; preds = %21
%58 = load i32*, i32** %7
%59 = call i32 @fclose(i32* %58)
%60 = load %struct.rtgtargets*, %struct.rtgtargets** %6
store %struct.rtgtargets* %60, %struct.rtgtargets** %3
br label %61
61: ; preds = %57, %18
%62 = load %struct.rtgtargets*, %struct.rtgtargets** %3
ret %struct.rtgtargets* %62
}

LLVM IR (-O2):
%struct.rtgtargets = type { i32 }
%struct.rtgconf = type { i32 }
%struct.queryhost = type { i32 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [7 x i8] c" %512s\00"
@.str.2 = [7 x i8] c"%*[^\0A]\00"
@.str.3 = [5 x i8] c"host\00"
define %struct.rtgtargets* @read_new_style_targets(i8* nocapture %0, %struct.rtgconf* %1) {
%3 = alloca [513 x i8]
%4 = tail call %struct.rtgtargets* (...) @rtgtargets_create()
%5 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %31, label %8
8: ; preds = %2
%9 = call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %29
11: ; preds = %8, %18
%12 = call i32 @strtolower(i8* %5)
%13 = call i32 @strclean(i32 %12)
%14 = load i8, i8* %5
%15 = icmp eq i8 %14, 35
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %21, %24, %16
%19 = call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%20 = icmp eq i32 %19, 1
br i1 %20, label %11, label %29
21: ; preds = %11
%22 = call i32 @bcmp(i8* dereferenceable(5) %5, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 5)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %18
24: ; preds = %21
%25 = call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%26 = call i8* @strdup(i8* %5)
%27 = call %struct.queryhost* @read_host(i32* %6, i8* %26, %struct.rtgconf* %1)
%28 = call i32 @rtgtargets_push_host(%struct.rtgtargets* %4, %struct.queryhost* %27)
br label %18
29: ; preds = %18, %8
%30 = call i32 @fclose(i32* %6)
br label %31
31: ; preds = %2, %29
ret %struct.rtgtargets* %4
}