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

/* Variables and functions */
int /*<<< orphan*/ endprotoent();
struct protoent *getprotoent();
int /*<<< orphan*/ setprotoent(int);
scalar_t__ strcmp(char const *, char *);
struct protoent *getprotobyname(const char *name) {
  struct protoent *pe;
  char **aliases;
  if (name == NULL) {
    return NULL;
  }
  setprotoent(1);
  while ((pe = getprotoent()) != NULL) {
    if (strcmp(name, pe->p_name) == 0) {
      break;
    }
    for (aliases = pe->p_aliases; *aliases != NULL; ++aliases) {
      if (strcmp(name, *aliases) == 0) {
        break;
      }
    }
    if (*aliases != NULL) {
      break;
    }
  }
  endprotoent();
  return pe;
}


x86 assembly (clang, -O0):
<getprotobyname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <getprotobyname+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1218 <getprotobyname+0xd8>
mov    $0x1,%edi
call   1050 <setprotoent@plt>
mov    $0x0,%al
call   1040 <getprotoent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1209 <getprotobyname+0xc9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11a2 <getprotobyname+0x62>
jmp    1209 <getprotobyname+0xc9>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11f1 <getprotobyname+0xb1>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11db <getprotobyname+0x9b>
jmp    11f1 <getprotobyname+0xb1>
jmp    11e0 <getprotobyname+0xa0>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11ae <getprotobyname+0x6e>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1204 <getprotobyname+0xc4>
jmp    1209 <getprotobyname+0xc9>
jmp    116e <getprotobyname+0x2e>
mov    $0x0,%al
call   1030 <endprotoent@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getprotobyname>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     11d2 <getprotobyname+0x92>
mov    %rdi,%r15
mov    $0x1,%edi
call   1050 <setprotoent@plt>
jmp    1167 <getprotobyname+0x27>
nopl   (%rax)
xor    %eax,%eax
test   %rax,%rax
jne    11c9 <getprotobyname+0x89>
xor    %eax,%eax
call   1040 <getprotoent@plt>
mov    %rax,%r14
test   %rax,%rax
je     11c9 <getprotobyname+0x89>
mov    (%r14),%rsi
mov    %r15,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11c9 <getprotobyname+0x89>
mov    0x8(%r14),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1160 <getprotobyname+0x20>
add    $0x8,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11c0 <getprotobyname+0x80>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11a0 <getprotobyname+0x60>
jmp    1160 <getprotobyname+0x20>
nopl   0x0(%rax,%rax,1)
mov    -0x8(%rbx),%rax
test   %rax,%rax
je     1167 <getprotobyname+0x27>
xor    %eax,%eax
call   1030 <endprotoent@plt>
jmp    11d5 <getprotobyname+0x95>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.protoent = type { i8*, i8** }
define %struct.protoent* @getprotobyname(i8* %0) {
%2 = alloca %struct.protoent*
%3 = alloca i8*
%4 = alloca %struct.protoent*
%5 = alloca i8**
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store %struct.protoent* null, %struct.protoent** %2
br label %50
9: ; preds = %1
%10 = call i32 @setprotoent(i32 1)
br label %11
11: ; preds = %46, %9
%12 = call %struct.protoent* (...) @getprotoent()
store %struct.protoent* %12, %struct.protoent** %4
%13 = icmp ne %struct.protoent* %12, null
br i1 %13, label %14, label %47
14: ; preds = %11
%15 = load i8*, i8** %3
%16 = load %struct.protoent*, %struct.protoent** %4
%17 = getelementptr inbounds %struct.protoent, %struct.protoent* %16, i32 0, i32 0
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %15, i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
br label %47
22: ; preds = %14
%23 = load %struct.protoent*, %struct.protoent** %4
%24 = getelementptr inbounds %struct.protoent, %struct.protoent* %23, i32 0, i32 1
%25 = load i8**, i8*** %24
store i8** %25, i8*** %5
br label %26
26: ; preds = %38, %22
%27 = load i8**, i8*** %5
%28 = load i8*, i8** %27
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %41
30: ; preds = %26
%31 = load i8*, i8** %3
%32 = load i8**, i8*** %5
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %31, i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %30
br label %41
37: ; preds = %30
br label %38
38: ; preds = %37
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i32 1
store i8** %40, i8*** %5
br label %26
41: ; preds = %36, %26
%42 = load i8**, i8*** %5
%43 = load i8*, i8** %42
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %46
45: ; preds = %41
br label %47
46: ; preds = %41
br label %11
47: ; preds = %45, %21, %11
%48 = call i32 (...) @endprotoent()
%49 = load %struct.protoent*, %struct.protoent** %4
store %struct.protoent* %49, %struct.protoent** %2
br label %50
50: ; preds = %47, %8
%51 = load %struct.protoent*, %struct.protoent** %2
ret %struct.protoent* %51
}

LLVM IR (-O2):
%struct.protoent = type { i8*, i8** }
define %struct.protoent* @getprotobyname(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %34, label %3
3: ; preds = %1
%4 = tail call i32 @setprotoent(i32 1)
br label %5
5: ; preds = %29, %3
%6 = tail call %struct.protoent* (...) @getprotoent()
%7 = icmp eq %struct.protoent* %6, null
br i1 %7, label %32, label %8
8: ; preds = %5
%9 = getelementptr inbounds %struct.protoent, %struct.protoent* %6, i64 0, i32 0
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %0, i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %32, label %13
13: ; preds = %8
%14 = getelementptr inbounds %struct.protoent, %struct.protoent* %6, i64 0, i32 1
%15 = load i8**, i8*** %14
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
br i1 %17, label %29, label %18
18: ; preds = %13, %23
%19 = phi i8* [ %25, %23 ], [ %16, %13 ]
%20 = phi i8** [ %24, %23 ], [ %15, %13 ]
%21 = tail call i64 @strcmp(i8* %0, i8* %19)
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %18
%24 = getelementptr inbounds i8*, i8** %20, i64 1
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %29, label %18
27: ; preds = %18
%28 = load i8*, i8** %20
br label %29
29: ; preds = %23, %13, %27
%30 = phi i8* [ %28, %27 ], [ null, %13 ], [ null, %23 ]
%31 = icmp eq i8* %30, null
br i1 %31, label %5, label %32
32: ; preds = %29, %8, %5
%33 = tail call i32 (...) @endprotoent()
br label %34
34: ; preds = %1, %32
%35 = phi %struct.protoent* [ %6, %32 ], [ null, %1 ]
ret %struct.protoent* %35
}