#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 {
  char *p_name;
};

/* Variables and functions */
int /*<<< orphan*/ endprotoent();
struct protoent *getprotoent();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ setprotoent(int);
scalar_t__ strcmp(char const *, char *);
struct protoent *my_getprotonam(char const *name) {
  struct protoent *ptr = 0;
  setprotoent(1);
  while ((ptr = getprotoent()) != NULL) {
    printf("searching %s\n", ptr->p_name);
    if (strcmp(name, ptr->p_name) == 0)
      break;
  }
  endprotoent();
  return (ptr);
}


x86 assembly (clang, -O0):
<my_getprotonam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x1,%edi
call   1060 <setprotoent@plt>
mov    $0x0,%al
call   1050 <getprotoent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11ba <my_getprotonam+0x6a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11b5 <my_getprotonam+0x65>
jmp    11ba <my_getprotonam+0x6a>
jmp    116e <my_getprotonam+0x1e>
mov    $0x0,%al
call   1030 <endprotoent@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_getprotonam>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x1,%edi
call   1060 <setprotoent@plt>
lea    0xe97(%rip),%r15
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getprotoent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     119a <my_getprotonam+0x4a>
mov    (%rbx),%rsi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    (%rbx),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1170 <my_getprotonam+0x20>
xor    %eax,%eax
call   1030 <endprotoent@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.protoent = type { i8* }
@.str = [14 x i8] c"searching %s\0A\00"
define %struct.protoent* @my_getprotonam(i8* %0) {
%2 = tail call i32 @setprotoent(i32 1)
br label %3
3: ; preds = %6, %1
%4 = tail call %struct.protoent* (...) @getprotoent()
%5 = icmp eq %struct.protoent* %4, null
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.protoent, %struct.protoent* %4, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %7
%11 = tail call i64 @strcmp(i8* %0, i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %3
13: ; preds = %6, %3
%14 = tail call i32 (...) @endprotoent()
ret %struct.protoent* %4
}