#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strtok(char *, char *);
void get_dns_servers(char *str[]) {
  FILE *resolv_file;
  char line[100];
  int i = 0;
  resolv_file = fopen("/etc/resolv.conf", "rt");
  while (fgets(line, 100, resolv_file)) {
    if (strncmp(line, "nameserver", 10) == 0) {
      strcpy(str[i], strtok(line, " "));
      strcpy(str[i], strtok(NULL, "\n"));
      ++i;
    }
  }
  fclose(resolv_file);
}


x86 assembly (clang, -O0):
<get_dns_servers>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x84(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1247 <get_dns_servers+0xe7>
lea    -0x80(%rbp),%rdi
lea    0xe5d(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1242 <get_dns_servers+0xe2>
mov    -0x8(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x98(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1080 <strtok@plt>
mov    -0x98(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x90(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe01(%rip),%rsi
call   1080 <strtok@plt>
mov    -0x90(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1190 <get_dns_servers+0x30>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dns_servers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdi,0x8(%rsp)
lea    0xe86(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1233 <get_dns_servers+0xd3>
xor    %r15d,%r15d
lea    0xe66(%rip),%rbx
lea    0x10(%rsp),%r14
jmp    11d5 <get_dns_servers+0x75>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    $0x64,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1233 <get_dns_servers+0xd3>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11c0 <get_dns_servers+0x60>
movslq %r15d,%r15
mov    0x8(%rsp),%rbp
mov    0x0(%rbp,%r15,8),%r13
mov    %r14,%rdi
lea    0xe1e(%rip),%rsi
call   1080 <strtok@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
mov    0x0(%rbp,%r15,8),%rbp
xor    %edi,%edi
lea    0xe03(%rip),%rsi
call   1080 <strtok@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
add    $0x1,%r15d
jmp    11c0 <get_dns_servers+0x60>
mov    %r12,%rdi
call   1050 <fclose@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/etc/resolv.conf\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [11 x i8] c"nameserver\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @get_dns_servers(i8** %0) {
%2 = alloca i8**
%3 = alloca i32*
%4 = alloca [100 x i8]
%5 = alloca i32
store i8** %0, i8*** %2
store i32 0, i32* %5
%6 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
br label %7
7: ; preds = %34, %1
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = load i32*, i32** %3
%10 = call i64 @fgets(i8* %8, i32 100, i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %35
12: ; preds = %7
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%14 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = load i8**, i8*** %2
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%23 = call i32 @strtok(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @strcpy(i8* %21, i32 %23)
%25 = load i8**, i8*** %2
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @strcpy(i8* %29, i32 %30)
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %34
34: ; preds = %16, %12
br label %7
35: ; preds = %7
%36 = load i32*, i32** %3
%37 = call i32 @fclose(i32* %36)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"/etc/resolv.conf\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [11 x i8] c"nameserver\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @get_dns_servers(i8** nocapture %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = call i64 @fgets(i8* %3, i32 100, i32* %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %25, label %7
7: ; preds = %1, %21
%8 = phi i32 [ %22, %21 ], [ 0, %1 ]
%9 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = sext i32 %8 to i64
%13 = getelementptr inbounds i8*, i8** %0, i64 %12
%14 = load i8*, i8** %13
%15 = call i32 @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @strcpy(i8* %14, i32 %15)
%17 = load i8*, i8** %13
%18 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 @strcpy(i8* %17, i32 %18)
%20 = add nsw i32 %8, 1
br label %21
21: ; preds = %11, %7
%22 = phi i32 [ %20, %11 ], [ %8, %7 ]
%23 = call i64 @fgets(i8* %3, i32 100, i32* %4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %7
25: ; preds = %21, %1
%26 = call i32 @fclose(i32* %4)
ret void
}