#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 /*<<< orphan*/ s_addr;
};
struct hostent {
  char *h_name;
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int ntohl(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
int main(void) {
  struct hostent *h;
  struct in_addr *a;
  if ((h = gethostbyname("localhost")) == NULL) {
    exit(1);
  }
  printf("official hosta name: %s\n", h->h_name);
  a = (struct in_addr *)h->h_addr_list[0];
  printf("internet address: %s (%081X)\n", inet_ntoa(*a), ntohl(a->s_addr));
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1183 <main+0x33>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1070 <ntohl@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
jne    116f <main+0x1f>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    %rax,%rbx
mov    (%rax),%rsi
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rax
mov    (%rax),%rbx
mov    (%rbx),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%r14
mov    (%rbx),%edi
call   1070 <ntohl@plt>
lea    0xe81(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

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

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