#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 *);
int /*<<< orphan*/ endhostent();
struct hostent *gethostent();
int /*<<< orphan*/ printf(char *);
void test_host() {
  printf("start walk around host entry\n");
  struct hostent *h = 0;
  while ((h = gethostent()) != 0) {
    dump_host(h);
  }
  endhostent();
  printf("end\n");
}


x86 assembly (clang, -O0):
<test_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <gethostent@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     117f <test_host+0x3f>
mov    -0x8(%rbp),%rdi
call   1050 <dump_host@plt>
jmp    115c <test_host+0x1c>
mov    $0x0,%al
call   1060 <endhostent@plt>
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_host>:
push   %rax
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
nopl   (%rax)
xor    %eax,%eax
call   1040 <gethostent@plt>
test   %rax,%rax
je     1166 <test_host+0x26>
mov    %rax,%rdi
call   1050 <dump_host@plt>
jmp    1150 <test_host+0x10>
xor    %eax,%eax
call   1060 <endhostent@plt>
lea    0xea9(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>

LLVM IR (-O0):
%struct.hostent = type { i32 }
@.str = [30 x i8] c"start walk around host entry\0A\00"
@.str.1 = [5 x i8] c"end\0A\00"
define void @test_host() {
%1 = alloca %struct.hostent*
%2 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* null, %struct.hostent** %1
br label %3
3: ; preds = %6, %0
%4 = call %struct.hostent* (...) @gethostent()
store %struct.hostent* %4, %struct.hostent** %1
%5 = icmp ne %struct.hostent* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load %struct.hostent*, %struct.hostent** %1
%8 = call i32 @dump_host(%struct.hostent* %7)
br label %3
9: ; preds = %3
%10 = call i32 (...) @endhostent()
%11 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@str = [29 x i8] c"start walk around host entry\00"
@str.2 = [4 x i8] c"end\00"
define void @test_host() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%2 = tail call %struct.hostent* (...) @gethostent()
%3 = icmp eq %struct.hostent* %2, null
br i1 %3, label %9, label %4
4: ; preds = %0, %4
%5 = phi %struct.hostent* [ %7, %4 ], [ %2, %0 ]
%6 = tail call i32 @dump_host(%struct.hostent* %5)
%7 = tail call %struct.hostent* (...) @gethostent()
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %9, label %4
9: ; preds = %4, %0
%10 = tail call i32 (...) @endhostent()
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.2, i64 0, i64 0))
ret void
}