#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*/ err(int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int sscanf(char *, char *, char *);
char *get_resolvconf_addr() {
  static char addr[16];
  char *rv;
  char buf[80];
  FILE *fp;
  rv = NULL;
  if ((fp = fopen("/etc/resolv.conf", "r")) == NULL)
    err(1, "/etc/resolv.conf");
  while (feof(fp) == 0) {
    fgets(buf, sizeof(buf), fp);
    if (sscanf(buf, "nameserver %15s", addr) == 1) {
      rv = addr;
      break;
    }
  }
  fclose(fp);
  return rv;
}


x86 assembly (clang, -O0):
<get_resolvconf_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movq   $0x0,-0x8(%rbp)
lea    0xe89(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jne    11a2 <get_resolvconf_addr+0x42>
mov    $0x1,%edi
lea    0xe63(%rip),%rsi
call   1060 <err@plt>
jmp    11a7 <get_resolvconf_addr+0x47>
mov    -0x68(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
jne    1201 <get_resolvconf_addr+0xa1>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x50,%esi
call   1040 <fgets@plt>
lea    -0x60(%rbp),%rdi
lea    0xe3c(%rip),%rsi
lea    0x2e82(%rip),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    11fc <get_resolvconf_addr+0x9c>
lea    0x2e6d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <get_resolvconf_addr+0xa1>
jmp    11a7 <get_resolvconf_addr+0x47>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_resolvconf_addr>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1197 <get_resolvconf_addr+0x37>
lea    0xe73(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
mov    %rsp,%r15
lea    0xe72(%rip),%r12
lea    0x2eb8(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    11e2 <get_resolvconf_addr+0x82>
mov    %r15,%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    11b0 <get_resolvconf_addr+0x50>
jmp    11e5 <get_resolvconf_addr+0x85>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@get_resolvconf_addr.addr = internal global [16 x i8] zeroinitializer
@.str = [17 x i8] c"/etc/resolv.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"nameserver %15s\00"
define i8* @get_resolvconf_addr() {
%1 = alloca i8*
%2 = alloca [80 x i8]
%3 = alloca i32*
store i8* null, i8** %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @err(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
br label %9
9: ; preds = %21, %8
%10 = load i32*, i32** %3
%11 = call i64 @feof(i32* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %9
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%15 = load i32*, i32** %3
%16 = call i32 @fgets(i8* %14, i32 80, i32* %15)
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @get_resolvconf_addr.addr, i64 0, i64 0))
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %13
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @get_resolvconf_addr.addr, i64 0, i64 0), i8** %1
br label %22
21: ; preds = %13
br label %9
22: ; preds = %20, %9
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
%25 = load i8*, i8** %1
ret i8* %25
}

LLVM IR (-O2):
@get_resolvconf_addr.addr = internal global [16 x i8] zeroinitializer
@.str = [17 x i8] c"/etc/resolv.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"nameserver %15s\00"
define i8* @get_resolvconf_addr() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
br label %8
8: ; preds = %7, %11
%9 = call i64 @feof(i32* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = call i32 @fgets(i8* %2, i32 80, i32* %3)
%13 = call i32 @sscanf(i8* %2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @get_resolvconf_addr.addr, i64 0, i64 0))
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %8
15: ; preds = %11, %8
%16 = phi i8* [ null, %8 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @get_resolvconf_addr.addr, i64 0, i64 0), %11 ]
%17 = call i32 @fclose(i32* %3)
ret i8* %16
}