#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 s_addr;
};
struct hostent {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ dump_host(struct hostent *);
struct hostent *gethostbyaddr(struct in_addr *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
void test_host3(struct in_addr *addr) {
  struct hostent *h = gethostbyaddr(addr, sizeof(struct in_addr), AF_INET);
  if (h) {
    printf("find host by addr: 0x%08x\n", addr->s_addr);
    dump_host(h);
  } else
    printf("no host found by addr: 0x%08x\n", addr->s_addr);
}


x86 assembly (clang, -O0):
<test_host3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1050 <gethostbyaddr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1182 <test_host3+0x52>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <dump_host@plt>
jmp    1194 <test_host3+0x64>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_host3>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eaa(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1050 <gethostbyaddr@plt>
mov    (%rbx),%esi
test   %rax,%rax
je     116f <test_host3+0x3f>
mov    %rax,%r14
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <dump_host@plt>
lea    0xea5(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32 }
@AF_INET = global i32 0
@.str = [27 x i8] c"find host by addr: 0x%08x\0A\00"
@.str.1 = [31 x i8] c"no host found by addr: 0x%08x\0A\00"
define void @test_host3(%struct.in_addr* %0) {
%2 = alloca %struct.in_addr*
%3 = alloca %struct.hostent*
store %struct.in_addr* %0, %struct.in_addr** %2
%4 = load %struct.in_addr*, %struct.in_addr** %2
%5 = load i32, i32* @AF_INET
%6 = call %struct.hostent* @gethostbyaddr(%struct.in_addr* %4, i32 4, i32 %5)
store %struct.hostent* %6, %struct.hostent** %3
%7 = load %struct.hostent*, %struct.hostent** %3
%8 = icmp ne %struct.hostent* %7, null
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load %struct.in_addr*, %struct.in_addr** %2
%11 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load %struct.hostent*, %struct.hostent** %3
%15 = call i32 @dump_host(%struct.hostent* %14)
br label %21
16: ; preds = %1
%17 = load %struct.in_addr*, %struct.in_addr** %2
%18 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %16, %9
ret void
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32 }
@AF_INET = global i32 0
@.str = [27 x i8] c"find host by addr: 0x%08x\0A\00"
@.str.1 = [31 x i8] c"no host found by addr: 0x%08x\0A\00"
define void @test_host3(%struct.in_addr* %0) {
%2 = load i32, i32* @AF_INET
%3 = tail call %struct.hostent* @gethostbyaddr(%struct.in_addr* %0, i32 4, i32 %2)
%4 = icmp eq %struct.hostent* %3, null
%5 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %0, i64 0, i32 0
%6 = load i32, i32* %5
br i1 %4, label %10, label %7
7: ; preds = %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %6)
%9 = tail call i32 @dump_host(%struct.hostent* %3)
br label %12
10: ; preds = %1
%11 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %12
12: ; preds = %10, %7
ret void
}