#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 {
  int dummy;
};
struct hostent {
  char *h_name;
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *, char *);
int main(int argc, char *argv[]) {
  struct hostent *h;
  if ((h = gethostbyname(argv[1])) == NULL) {
    exit(1);
  }
  printf("hostname:%s\nIP Addr:%s\n", h->h_name,
         inet_ntoa(*((struct in_addr *)h->h_addr)));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    117b <main+0x3b>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x8(%rsi),%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     1173 <main+0x33>
mov    (%rax),%rbx
mov    0x8(%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
lea    0xe9c(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
%struct.hostent = type { i8*, i64 }
%struct.in_addr = type { i32 }
@.str = [24 x i8] c"hostname:%s\0AIP Addr:%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call %struct.hostent* @gethostbyname(i8* %4)
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 1
%13 = load i64, i64* %12
%14 = inttoptr i64 %13 to %struct.in_addr*
%15 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %14, i64 0, i32 0
%16 = load i32, i32* %15
%17 = tail call i8* @inet_ntoa(i32 %16)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %17)
ret i32 0
}