#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 hostent {
  int /*<<< orphan*/ *h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  struct hostent *host;
  host = gethostbyname("localhost");
  if (host == NULL) {
    perror("gethost");
    exit(1);
  }
  printf("addr:%hhd.%hhd.%hhd.%hhd\n", host->h_addr[0], host->h_addr[1],
         host->h_addr[2], host->h_addr[3]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1179 <main+0x39>
lea    0xea0(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x4(%rax),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x8(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0xc(%rax),%r8d
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1171 <main+0x31>
mov    (%rax),%rax
mov    (%rax),%esi
mov    0x4(%rax),%edx
mov    0x8(%rax),%ecx
mov    0xc(%rax),%r8d
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe92(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
%struct.hostent = type { i32* }
@.str = [10 x i8] c"localhost\00"
@.str.1 = [8 x i8] c"gethost\00"
@.str.2 = [26 x i8] c"addr:%hhd.%hhd.%hhd.%hhd\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 %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 0
%8 = load i32*, i32** %7
%9 = load i32, i32* %8
%10 = getelementptr inbounds i32, i32* %8, i64 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds i32, i32* %8, i64 2
%13 = load i32, i32* %12
%14 = getelementptr inbounds i32, i32* %8, i64 3
%15 = load i32, i32* %14
%16 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %11, i32 %13, i32 %15)
ret i32 0
}