#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*/ endprotoent();
struct protoent *getprotobyname(char *);
struct protoent *getprotobynumber(int);
struct protoent *getprotoent();
int /*<<< orphan*/ output_protoent(char *, struct protoent *);
int /*<<< orphan*/ setprotoent(int /*<<< orphan*/);
void test_protocols(void) {
  struct protoent *prptr;
  prptr = getprotobyname("IP");
  output_protoent("getprotobyname (\"IP\")", prptr);
  prptr = getprotobynumber(1);
  output_protoent("getprotobynumber (1)", prptr);
  setprotoent(0);
  do {
    prptr = getprotoent();
    output_protoent("getprotoent ()", prptr);
  } while (prptr != NULL);
  endprotoent();
}


x86 assembly (clang, -O0):
<test_protocols>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
call   1080 <getprotobyname@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1070 <output_protoent@plt>
mov    $0x1,%edi
call   1060 <getprotobynumber@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1070 <output_protoent@plt>
xor    %edi,%edi
call   1050 <setprotoent@plt>
mov    $0x0,%al
call   1040 <getprotoent@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe6b(%rip),%rdi
call   1070 <output_protoent@plt>
cmpq   $0x0,-0x8(%rbp)
jne    11ad <test_protocols+0x4d>
mov    $0x0,%al
call   1030 <endprotoent@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_protocols>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
call   1080 <getprotobyname@plt>
lea    0xe8c(%rip),%rdi
mov    %rax,%rsi
call   1070 <output_protoent@plt>
mov    $0x1,%edi
call   1060 <getprotobynumber@plt>
lea    0xe89(%rip),%rdi
mov    %rax,%rsi
call   1070 <output_protoent@plt>
xor    %edi,%edi
call   1050 <setprotoent@plt>
lea    0xe88(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getprotoent@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <output_protoent@plt>
test   %rbx,%rbx
jne    11b0 <test_protocols+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <endprotoent@plt>

LLVM IR (-O0):
%struct.protoent = type { i32 }
@.str = [3 x i8] c"IP\00"
@.str.1 = [22 x i8] c"getprotobyname (\22IP\22)\00"
@.str.2 = [21 x i8] c"getprotobynumber (1)\00"
@.str.3 = [15 x i8] c"getprotoent ()\00"
define void @test_protocols() {
%1 = alloca %struct.protoent*
%2 = call %struct.protoent* @getprotobyname(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store %struct.protoent* %2, %struct.protoent** %1
%3 = load %struct.protoent*, %struct.protoent** %1
%4 = call i32 @output_protoent(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %struct.protoent* %3)
%5 = call %struct.protoent* @getprotobynumber(i32 1)
store %struct.protoent* %5, %struct.protoent** %1
%6 = load %struct.protoent*, %struct.protoent** %1
%7 = call i32 @output_protoent(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %struct.protoent* %6)
%8 = call i32 @setprotoent(i32 0)
br label %9
9: ; preds = %13, %0
%10 = call %struct.protoent* (...) @getprotoent()
store %struct.protoent* %10, %struct.protoent** %1
%11 = load %struct.protoent*, %struct.protoent** %1
%12 = call i32 @output_protoent(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %struct.protoent* %11)
br label %13
13: ; preds = %9
%14 = load %struct.protoent*, %struct.protoent** %1
%15 = icmp ne %struct.protoent* %14, null
br i1 %15, label %9, label %16
16: ; preds = %13
%17 = call i32 (...) @endprotoent()
ret void
}

LLVM IR (-O2):
%struct.protoent = type { i32 }
@.str = [3 x i8] c"IP\00"
@.str.1 = [22 x i8] c"getprotobyname (\22IP\22)\00"
@.str.2 = [21 x i8] c"getprotobynumber (1)\00"
@.str.3 = [15 x i8] c"getprotoent ()\00"
define void @test_protocols() {
%1 = tail call %struct.protoent* @getprotobyname(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @output_protoent(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %struct.protoent* %1)
%3 = tail call %struct.protoent* @getprotobynumber(i32 1)
%4 = tail call i32 @output_protoent(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %struct.protoent* %3)
%5 = tail call i32 @setprotoent(i32 0)
br label %6
6: ; preds = %6, %0
%7 = tail call %struct.protoent* (...) @getprotoent()
%8 = tail call i32 @output_protoent(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %struct.protoent* %7)
%9 = icmp eq %struct.protoent* %7, null
br i1 %9, label %10, label %6
10: ; preds = %6
%11 = tail call i32 (...) @endprotoent()
ret void
}