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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
in_addr_t net_get_dns(void) {
  FILE *fp;
  char dnsname[80];
  fp = fopen("/etc/resolv.conf", "r");
  if (fp) {
    if (fscanf(fp, "nameserver %s\n", dnsname) != EOF) {
      fclose(fp);
      printf("dns=%s\n", dnsname);
      return inet_addr(dnsname);
    }
    printf("net_get_dns: scan fail!\n");
  }
  printf("net_get_dns: file \"%s\" opened for reading error!\n",
         "/etc/resolv.conf");
  return INADDR_ANY;
}


x86 assembly (clang, -O0):
<net_get_dns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xea1(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d8 <net_get_dns+0x88>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe8a(%rip),%rsi
call   1050 <fscanf@plt>
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%rax
je     11ca <net_get_dns+0x7a>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x60(%rbp),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x4(%rbp)
jmp    11f9 <net_get_dns+0xa9>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe64(%rip),%rdi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_get_dns>:
push   %rbx
sub    $0x50,%rsp
lea    0xe94(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11aa <net_get_dns+0x4a>
mov    %rax,%rbx
lea    0xe8c(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%rax
jne    11ca <net_get_dns+0x6a>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
lea    0xe79(%rip),%rdi
lea    0xe48(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
jmp    11ee <net_get_dns+0x8e>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe49(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <inet_addr@plt>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/etc/resolv.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"nameserver %s\0A\00"
@EOF = global i64 0
@.str.3 = [8 x i8] c"dns=%s\0A\00"
@.str.4 = [25 x i8] c"net_get_dns: scan fail!\0A\00"
@.str.5 = [50 x i8] c"net_get_dns: file \22%s\22 opened for reading error!\0A\00"
@INADDR_ANY = global i32 0
define i32 @net_get_dns() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [80 x i8]
%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** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %22
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%10 = call i64 @fscanf(i32* %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = load i64, i64* @EOF
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %20
13: ; preds = %7
%14 = load i32*, i32** %2
%15 = call i32 @fclose(i32* %14)
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%19 = call i32 @inet_addr(i8* %18)
store i32 %19, i32* %1
br label %25
20: ; preds = %7
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %20, %0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @INADDR_ANY
store i32 %24, i32* %1
br label %25
25: ; preds = %22, %13
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [17 x i8] c"/etc/resolv.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"nameserver %s\0A\00"
@EOF = global i64 0
@.str.3 = [8 x i8] c"dns=%s\0A\00"
@.str.5 = [50 x i8] c"net_get_dns: file \22%s\22 opened for reading error!\0A\00"
@INADDR_ANY = global i32 0
@str = [24 x i8] c"net_get_dns: scan fail!\00"
define i32 @net_get_dns() {
%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 %15, label %5
5: ; preds = %0
%6 = call i64 @fscanf(i32* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%7 = load i64, i64* @EOF
%8 = icmp eq i64 %6, %7
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = call i32 @fclose(i32* %3)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%12 = call i32 @inet_addr(i8* %2)
br label %18
13: ; preds = %5
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @INADDR_ANY
br label %18
18: ; preds = %15, %9
%19 = phi i32 [ %12, %9 ], [ %17, %15 ]
ret i32 %19
}