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

/* Variables and functions */
int /*<<< orphan*/ dump_proto(struct protoent *);
int /*<<< orphan*/ endprotoent();
struct protoent *getprotoent();
int /*<<< orphan*/ printf(char *);
void test_proto() {
  printf("start walk around protocol entry\n");
  struct protoent *h = 0;
  while ((h = getprotoent()) != 0) {
    dump_proto(h);
  }
  endprotoent();
  printf("end\n");
}


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

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

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