#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_server(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ read_thing(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
void read_resolv(char *fname) {
  FILE *fp;
  char buf[512], ip[512];
  fp = fopen(fname, "r");
  if (!fp)
    return;
  while (fgets(buf, sizeof(buf), fp)) {
    if (!strncasecmp(buf, "nameserver", 10)) {
      read_thing(buf + 10, ip);
      if (strlen(ip))
        add_server(ip);
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<read_resolv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a3 <read_resolv+0x33>
jmp    1234 <read_resolv+0xc4>
jmp    11a8 <read_resolv+0x38>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     122b <read_resolv+0xbb>
lea    -0x210(%rbp),%rdi
lea    0xe2b(%rip),%rsi
mov    $0xa,%edx
call   1080 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1226 <read_resolv+0xb6>
lea    -0x210(%rbp),%rdi
add    $0xa,%rdi
lea    -0x410(%rbp),%rsi
call   1040 <read_thing@plt>
lea    -0x410(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
je     1221 <read_resolv+0xb1>
lea    -0x410(%rbp),%rdi
call   1030 <add_server@plt>
jmp    1226 <read_resolv+0xb6>
jmp    11a8 <read_resolv+0x38>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_resolv>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
lea    0xe92(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1210 <read_resolv+0xb0>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1208 <read_resolv+0xa8>
lea    0xa(%rsp),%r14
lea    0xe57(%rip),%r15
mov    %rsp,%rbx
lea    0x200(%rsp),%r13
jmp    11d5 <read_resolv+0x75>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1208 <read_resolv+0xa8>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1070 <strncasecmp@plt>
test   %eax,%eax
jne    11c0 <read_resolv+0x60>
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <read_thing@plt>
cmpb   $0x0,0x200(%rsp)
je     11c0 <read_resolv+0x60>
mov    %r13,%rdi
call   1030 <add_server@plt>
jmp    11c0 <read_resolv+0x60>
mov    %r12,%rdi
call   1050 <fclose@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"nameserver\00"
define void @read_resolv(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
br label %37
11: ; preds = %1
br label %12
12: ; preds = %33, %11
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i64 @fgets(i8* %13, i32 512, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %34
17: ; preds = %12
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%19 = call i32 @strncasecmp(i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 10)
%20 = icmp ne i32 %19, 0
br i1 %20, label %33, label %21
21: ; preds = %17
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%23 = getelementptr inbounds i8, i8* %22, i64 10
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%25 = call i32 @read_thing(i8* %23, i8* %24)
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%27 = call i64 @strlen(i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%31 = call i32 @add_server(i8* %30)
br label %32
32: ; preds = %29, %21
br label %33
33: ; preds = %32, %17
br label %12
34: ; preds = %12
%35 = load i32*, i32** %3
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %34, %10
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"nameserver\00"
define void @read_resolv(i8* nocapture %0) {
%2 = alloca [512 x i8]
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%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 %27, label %8
8: ; preds = %1
%9 = call i64 @fgets(i8* %4, i32 512, i32* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %25, label %11
11: ; preds = %8
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 10
br label %13
13: ; preds = %11, %22
%14 = call i32 @strncasecmp(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 10)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = call i32 @read_thing(i8* %12, i8* %5)
%18 = load i8, i8* %5
%19 = icmp eq i8 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 @add_server(i8* %5)
br label %22
22: ; preds = %16, %20, %13
%23 = call i64 @fgets(i8* %4, i32 512, i32* %6)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %13
25: ; preds = %22, %8
%26 = call i32 @fclose(i32* %6)
br label %27
27: ; preds = %1, %25
ret void
}