#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ dump_host(struct hostent *);
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ printf(char *, char const *);
void test_host2(char const *hostname) {
  struct hostent *h = gethostbyname(hostname);
  if (h) {
    printf("find host by name: %s\n", hostname);
    dump_host(h);
  } else
    printf("no host found by name: %s\n", hostname);
}


x86 assembly (clang, -O0):
<test_host2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1172 <test_host2+0x42>
mov    -0x8(%rbp),%rsi
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <dump_host@plt>
jmp    1182 <test_host2+0x52>
mov    -0x8(%rbp),%rsi
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_host2>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1162 <test_host2+0x32>
mov    %rax,%r14
lea    0xeb5(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <dump_host@plt>
lea    0xeae(%rip),%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
%struct.hostent = type { i32 }
@.str = [23 x i8] c"find host by name: %s\0A\00"
@.str.1 = [27 x i8] c"no host found by name: %s\0A\00"
define void @test_host2(i8* %0) {
%2 = tail call %struct.hostent* @gethostbyname(i8* %0)
%3 = icmp eq %struct.hostent* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32 @dump_host(%struct.hostent* %2)
br label %9
7: ; preds = %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %4
ret void
}