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

/* Variables and functions */
int /*<<< orphan*/ dump_serv(struct servent *);
int /*<<< orphan*/ endservent();
struct servent *getservent();
int /*<<< orphan*/ printf(char *);
void test_serv() {
  printf("start walk around server entry\n");
  struct servent *h = 0;
  while ((h = getservent()) != 0) {
    dump_serv(h);
  }
  endservent();
  printf("end\n");
}


x86 assembly (clang, -O0):
<test_serv>:
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 <getservent@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     117f <test_serv+0x3f>
mov    -0x8(%rbp),%rdi
call   1050 <dump_serv@plt>
jmp    115c <test_serv+0x1c>
mov    $0x0,%al
call   1060 <endservent@plt>
lea    0xe93(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.servent = type { i32 }
@.str = [32 x i8] c"start walk around server entry\0A\00"
@.str.1 = [5 x i8] c"end\0A\00"
define void @test_serv() {
%1 = alloca %struct.servent*
%2 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store %struct.servent* null, %struct.servent** %1
br label %3
3: ; preds = %6, %0
%4 = call %struct.servent* (...) @getservent()
store %struct.servent* %4, %struct.servent** %1
%5 = icmp ne %struct.servent* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load %struct.servent*, %struct.servent** %1
%8 = call i32 @dump_serv(%struct.servent* %7)
br label %3
9: ; preds = %3
%10 = call i32 (...) @endservent()
%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.servent = type { i32 }
@str = [31 x i8] c"start walk around server entry\00"
@str.2 = [4 x i8] c"end\00"
define void @test_serv() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%2 = tail call %struct.servent* (...) @getservent()
%3 = icmp eq %struct.servent* %2, null
br i1 %3, label %9, label %4
4: ; preds = %0, %4
%5 = phi %struct.servent* [ %7, %4 ], [ %2, %0 ]
%6 = tail call i32 @dump_serv(%struct.servent* %5)
%7 = tail call %struct.servent* (...) @getservent()
%8 = icmp eq %struct.servent* %7, null
br i1 %8, label %9, label %4
9: ; preds = %4, %0
%10 = tail call i32 (...) @endservent()
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.2, i64 0, i64 0))
ret void
}