#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 {
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
#define HOST_NOT_FOUND 131
#define NO_ADDRESS 130
#define NO_RECOVERY 129
#define TRY_AGAIN 128
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname2(char *, int /*<<< orphan*/);
int h_errno;
int /*<<< orphan*/ printf(char *, char *);
struct in_addr *getHostEntryAddress(char *address) {
  struct hostent *tmp = NULL;
  tmp = gethostbyname2(address, AF_INET);
  if (tmp == NULL)
    switch (h_errno) {
    case HOST_NOT_FOUND:
      printf("Host not found: %s\n", address);
      exit(-1);
    case NO_ADDRESS:
      printf("Host valid but without IP address: %s\n", address);
      exit(-1);
    case NO_RECOVERY:
      printf("Not recoverable server error with address: %s\n", address);
      exit(-1);
    case TRY_AGAIN:
      printf("Server temporary error, try again later: %s\n", address);
      exit(-1);
    }
  return (struct in_addr *)tmp->h_addr_list[0];
}


x86 assembly (clang, -O0):
<getHostEntryAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
call   1040 <gethostbyname2@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1201 <getHostEntryAddress+0xd1>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     11fc <getHostEntryAddress+0xcc>
mov    -0x18(%rbp),%rax
lea    0xe75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
jmp    1201 <getHostEntryAddress+0xd1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getHostEntryAddress>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
call   1040 <gethostbyname2@plt>
test   %rax,%rax
jne    1158 <getHostEntryAddress+0x28>
mov    0x2e92(%rip),%rcx
mov    (%rcx),%ecx
add    $0xffffff80,%ecx
cmp    $0x3,%ecx
jbe    1160 <getHostEntryAddress+0x30>
mov    (%rax),%rax
mov    (%rax),%rax
pop    %rbx
ret
lea    0xe99(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
lea    0xf03(%rip),%rdi
jmp    1192 <getHostEntryAddress+0x62>
lea    0xecb(%rip),%rdi
jmp    1192 <getHostEntryAddress+0x62>
lea    0xe9b(%rip),%rdi
jmp    1192 <getHostEntryAddress+0x62>
lea    0xe7e(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i64* }
@AF_INET = global i32 0
@h_errno = global i32 0
@.str = [20 x i8] c"Host not found: %s\0A\00"
@.str.1 = [39 x i8] c"Host valid but without IP address: %s\0A\00"
@.str.2 = [47 x i8] c"Not recoverable server error with address: %s\0A\00"
@.str.3 = [45 x i8] c"Server temporary error, try again later: %s\0A\00"
define %struct.in_addr* @getHostEntryAddress(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.hostent*
store i8* %0, i8** %2
store %struct.hostent* null, %struct.hostent** %3
%4 = load i8*, i8** %2
%5 = load i32, i32* @AF_INET
%6 = call %struct.hostent* @gethostbyname2(i8* %4, i32 %5)
store %struct.hostent* %6, %struct.hostent** %3
%7 = load %struct.hostent*, %struct.hostent** %3
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %9, label %28
9: ; preds = %1
%10 = load i32, i32* @h_errno
switch i32 %10, label %27 [
i32 131, label %11
i32 130, label %15
i32 129, label %19
i32 128, label %23
]
11: ; preds = %9
%12 = load i8*, i8** %2
%13 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %9
%16 = load i8*, i8** %2
%17 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %9
%20 = load i8*, i8** %2
%21 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %9
%24 = load i8*, i8** %2
%25 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %9
br label %28
28: ; preds = %27, %1
%29 = load %struct.hostent*, %struct.hostent** %3
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i32 0, i32 0
%31 = load i64*, i64** %30
%32 = getelementptr inbounds i64, i64* %31, i64 0
%33 = load i64, i64* %32
%34 = inttoptr i64 %33 to %struct.in_addr*
ret %struct.in_addr* %34
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i64* }
@AF_INET = global i32 0
@h_errno = global i32 0
@.str = [20 x i8] c"Host not found: %s\0A\00"
@.str.1 = [39 x i8] c"Host valid but without IP address: %s\0A\00"
@.str.2 = [47 x i8] c"Not recoverable server error with address: %s\0A\00"
@.str.3 = [45 x i8] c"Server temporary error, try again later: %s\0A\00"
define %struct.in_addr* @getHostEntryAddress(i8* %0) {
%2 = load i32, i32* @AF_INET
%3 = tail call %struct.hostent* @gethostbyname2(i8* %0, i32 %2)
%4 = icmp eq %struct.hostent* %3, null
br i1 %4, label %5, label %19
5: ; preds = %1
%6 = load i32, i32* @h_errno
switch i32 %6, label %19 [
i32 131, label %7
i32 130, label %10
i32 129, label %13
i32 128, label %16
]
7: ; preds = %5
%8 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %5
%11 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %5
%14 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %5
%17 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %5, %1
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%21 = load i64*, i64** %20
%22 = load i64, i64* %21
%23 = inttoptr i64 %22 to %struct.in_addr*
ret %struct.in_addr* %23
}