#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 */
struct in_addr {
  unsigned long s_addr;
};
struct hostent {
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
struct hostent *gethostbyname(char const *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ stderr;
char *nslkup(const char *host_name) {
  struct hostent *host;
  struct in_addr h_addr;
  if ((host = gethostbyname(host_name)) == NULL) {
    fprintf(stderr, "nslookup failed on '%s' \n", host_name);
    exit(-1);
  }
  h_addr.s_addr = *((unsigned long *)host->h_addr_list[0]);
  return inet_ntoa(h_addr);
}


x86 assembly (clang, -O0):
<nslkup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1186 <nslkup+0x46>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <inet_ntoa@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nslkup>:
push   %rbx
mov    %rdi,%rbx
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     115d <nslkup+0x1d>
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%rdi
pop    %rbx
jmp    1030 <inet_ntoa@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64* }
%struct.in_addr = type { i64 }
@stderr = global i32 0
@.str = [26 x i8] c"nslookup failed on '%s' \0A\00"
define i8* @nslkup(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.hostent*
%4 = alloca %struct.in_addr
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call %struct.hostent* @gethostbyname(i8* %5)
store %struct.hostent* %6, %struct.hostent** %3
%7 = icmp eq %struct.hostent* %6, null
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %2
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %1
%14 = load %struct.hostent*, %struct.hostent** %3
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i32 0, i32 0
%16 = load i64*, i64** %15
%17 = getelementptr inbounds i64, i64* %16, i64 0
%18 = load i64, i64* %17
%19 = inttoptr i64 %18 to i64*
%20 = load i64, i64* %19
%21 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
store i64 %20, i64* %21
%22 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
%23 = load i64, i64* %22
%24 = call i8* @inet_ntoa(i64 %23)
ret i8* %24
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
@stderr = global i32 0
@.str = [26 x i8] c"nslookup failed on '%s' \0A\00"
define i8* @nslkup(i8* %0) {
%2 = tail call %struct.hostent* @gethostbyname(i8* %0)
%3 = icmp eq %struct.hostent* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %1
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%10 = load i64*, i64** %9
%11 = load i64, i64* %10
%12 = inttoptr i64 %11 to i64*
%13 = load i64, i64* %12
%14 = tail call i8* @inet_ntoa(i64 %13)
ret i8* %14
}