#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 /*<<< orphan*/ p_name;
};

/* Variables and functions */
int /*<<< orphan*/ endprotoent();
struct protoent *getprotoent();
scalar_t__ strcmp(char const *, int /*<<< orphan*/);
struct protoent *getprotobyname(const char *name) {
  struct protoent *p;
  endprotoent();
  do
    p = getprotoent();
  while (p && strcmp(name, p->p_name));
  return p;
}


x86 assembly (clang, -O0):
<getprotobyname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <endprotoent@plt>
mov    $0x0,%al
call   1040 <getprotoent@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     1177 <getprotobyname+0x47>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1143 <getprotobyname+0x13>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getprotobyname>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <endprotoent@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <getprotoent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     115e <getprotobyname+0x2e>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1140 <getprotobyname+0x10>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.protoent = type { i32 }
define %struct.protoent* @getprotobyname(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.protoent*
store i8* %0, i8** %2
%4 = call i32 (...) @endprotoent()
br label %5
5: ; preds = %17, %1
%6 = call %struct.protoent* (...) @getprotoent()
store %struct.protoent* %6, %struct.protoent** %3
br label %7
7: ; preds = %5
%8 = load %struct.protoent*, %struct.protoent** %3
%9 = icmp ne %struct.protoent* %8, null
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i8*, i8** %2
%12 = load %struct.protoent*, %struct.protoent** %3
%13 = getelementptr inbounds %struct.protoent, %struct.protoent* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @strcmp(i8* %11, i32 %14)
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %10, %7
%18 = phi i1 [ false, %7 ], [ %16, %10 ]
br i1 %18, label %5, label %19
19: ; preds = %17
%20 = load %struct.protoent*, %struct.protoent** %3
ret %struct.protoent* %20
}

LLVM IR (-O2):
%struct.protoent = type { i32 }
define %struct.protoent* @getprotobyname(i8* %0) {
%2 = tail call i32 (...) @endprotoent()
br label %3
3: ; preds = %6, %1
%4 = tail call %struct.protoent* (...) @getprotoent()
%5 = icmp eq %struct.protoent* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.protoent, %struct.protoent* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i64 @strcmp(i8* %0, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %3, %6
ret %struct.protoent* %4
}