#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct hostent {
  scalar_t__ h_length;
  scalar_t__ *h_addr_list;
};
struct TYPE_4__ {
  int nscount;
  TYPE_1__ *nsaddr_list;
};
struct TYPE_3__ {
  int /*<<< orphan*/ sin_addr;
};

/* Variables and functions */
TYPE_2__ _res;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ h_errno;
char *hstrerror(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(void *, void *, size_t);
int /*<<< orphan*/ res_init();
int /*<<< orphan*/ stderr;
int set_nameserver(char *ns) {
  struct hostent *host;
  res_init();
  host = gethostbyname(ns);
  if (host == NULL) {
    (void)fprintf(stderr, "Can not resolv nameserver %s: %s\n", ns,
                  hstrerror(h_errno));
    return 0;
  }
  (void)memcpy((void *)&_res.nsaddr_list[0].sin_addr,
               (void *)host->h_addr_list[0], (size_t)host->h_length);
  _res.nscount = 1;
  return 1;
}


x86 assembly (clang, -O0):
<set_nameserver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <res_init@plt>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bf <set_nameserver+0x6f>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1070 <hstrerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe52(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <set_nameserver+0xa5>
mov    0x2e22(%rip),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
call   1060 <memcpy@plt>
mov    0x2e00(%rip),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_nameserver>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <res_init@plt>
mov    %rbx,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1194 <set_nameserver+0x44>
mov    0x2e74(%rip),%rbx
mov    0x8(%rbx),%rdi
mov    (%rax),%rdx
mov    0x8(%rax),%rax
mov    (%rax),%rsi
call   1060 <memcpy@plt>
movl   $0x1,(%rbx)
mov    $0x1,%ebp
jmp    11c1 <set_nameserver+0x71>
mov    0x2e35(%rip),%rax
mov    (%rax),%r14d
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1070 <hstrerror@plt>
lea    0xe4d(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, %struct.TYPE_3__* }
%struct.TYPE_3__ = type { i32 }
%struct.hostent = type { i64, i64* }
@stderr = global i32 0
@.str = [34 x i8] c"Can not resolv nameserver %s: %s\0A\00"
@h_errno = global i32 0
@_res = global %struct.TYPE_4__ zeroinitializer
define i32 @set_nameserver(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.hostent*
store i8* %0, i8** %3
%5 = call i32 (...) @res_init()
%6 = load i8*, i8** %3
%7 = call %struct.hostent* @gethostbyname(i8* %6)
store %struct.hostent* %7, %struct.hostent** %4
%8 = load %struct.hostent*, %struct.hostent** %4
%9 = icmp eq %struct.hostent* %8, null
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = load i32, i32* @h_errno
%14 = call i8* @hstrerror(i32 %13)
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %14)
store i32 0, i32* %2
br label %31
16: ; preds = %1
%17 = load %struct.TYPE_3__*, %struct.TYPE_3__** getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @_res, i32 0, i32 1)
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %17, i64 0
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i32 0, i32 0
%20 = bitcast i32* %19 to i8*
%21 = load %struct.hostent*, %struct.hostent** %4
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i32 0, i32 1
%23 = load i64*, i64** %22
%24 = getelementptr inbounds i64, i64* %23, i64 0
%25 = load i64, i64* %24
%26 = inttoptr i64 %25 to i8*
%27 = load %struct.hostent*, %struct.hostent** %4
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i32 0, i32 0
%29 = load i64, i64* %28
%30 = call i32 @memcpy(i8* %20, i8* %26, i64 %29)
store i32 1, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @_res, i32 0, i32 0)
store i32 1, i32* %2
br label %31
31: ; preds = %16, %10
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, %struct.TYPE_3__* }
%struct.TYPE_3__ = type { i32 }
%struct.hostent = type { i64, i64* }
@stderr = global i32 0
@.str = [34 x i8] c"Can not resolv nameserver %s: %s\0A\00"
@h_errno = global i32 0
@_res = global %struct.TYPE_4__ zeroinitializer
define i32 @set_nameserver(i8* %0) {
%2 = tail call i32 (...) @res_init()
%3 = tail call %struct.hostent* @gethostbyname(i8* %0)
%4 = icmp eq %struct.hostent* %3, null
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = load i32, i32* @h_errno
%8 = tail call i8* @hstrerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %8)
br label %19
10: ; preds = %1
%11 = load i8*, i8** bitcast (%struct.TYPE_3__** getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @_res, i64 0, i32 1) to i8**)
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 1
%13 = load i64*, i64** %12
%14 = load i64, i64* %13
%15 = inttoptr i64 %14 to i8*
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%17 = load i64, i64* %16
%18 = tail call i32 @memcpy(i8* %11, i8* %15, i64 %17)
store i32 1, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @_res, i64 0, i32 0)
br label %19
19: ; preds = %10, %5
%20 = phi i32 [ 0, %5 ], [ 1, %10 ]
ret i32 %20
}