#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int net_set_dns(char *dnsname) {
  FILE *fp;
  fp = fopen("/etc/resolv.conf", "w");
  if (fp) {
    fprintf(fp, "nameserver %s\n", dnsname);
    fclose(fp);
    printf("dns=%s\n", dnsname);
    return 0;
  }
  printf("net_set_dns: file \"%s\" opened for writing error!\n",
         "/etc/resolv.conf");
  return -1;
}


x86 assembly (clang, -O0):
<net_set_dns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
lea    0xeb7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a7 <net_set_dns+0x67>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe96(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rsi
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <net_set_dns+0x81>
lea    0xe7c(%rip),%rdi
lea    0xe4b(%rip),%rsi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_set_dns>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     118f <net_set_dns+0x4f>
mov    %rax,%rbx
lea    0xeaa(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe9f(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    11a7 <net_set_dns+0x67>
lea    0xe94(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"/etc/resolv.conf\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [15 x i8] c"nameserver %s\0A\00"
@.str.3 = [8 x i8] c"dns=%s\0A\00"
@.str.4 = [50 x i8] c"net_set_dns: file \22%s\22 opened for writing error!\0A\00"
define i32 @net_set_dns(i8* %0) {
%2 = 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))
%3 = icmp eq i32* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%6 = tail call i32 @fclose(i32* %2)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %10
8: ; preds = %1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %4
%11 = phi i32 [ 0, %4 ], [ -1, %8 ]
ret i32 %11
}