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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct protoent *getprotobyname(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct protoent *result;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s protocol\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  result = getprotobyname(argv[1]);
  if (result == NULL) {
    perror("getprotobyname");
    exit(EXIT_FAILURE);
  }
  printf("Name: %s; type: %d\n", result->p_name, result->p_proto);
  printf("-------alias-------------\n");
  char **ptr = result->p_aliases;
  while (ptr && *ptr) {
    printf("  %s\n", *ptr);
    ++ptr;
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119a <main+0x4a>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <getprotobyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <main+0x80>
lea    0xe57(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
je     1224 <main+0xd4>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1234 <main+0xe4>
jmp    125a <main+0x10a>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1206 <main+0xb6>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1185 <main+0x25>
mov    0x8(%rsi),%rdi
call   1060 <getprotobyname@plt>
test   %rax,%rax
jne    11ab <main+0x4b>
lea    0xe96(%rip),%rdi
call   1070 <perror@plt>
jmp    119d <main+0x3d>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %rax,%rbx
mov    (%rax),%rsi
mov    0x8(%rax),%edx
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     1206 <main+0xa6>
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1206 <main+0xa6>
add    $0x8,%rbx
lea    0xe4d(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11f0 <main+0x90>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.protoent = type { i8*, i32, i8** }
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s protocol\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [15 x i8] c"getprotobyname\00"
@.str.2 = [20 x i8] c"Name: %s; type: %d\0A\00"
@.str.3 = [27 x i8] c"-------alias-------------\0A\00"
@.str.4 = [6 x i8] c" %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.protoent*
%7 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call %struct.protoent* @getprotobyname(i8* %21)
store %struct.protoent* %22, %struct.protoent** %6
%23 = load %struct.protoent*, %struct.protoent** %6
%24 = icmp eq %struct.protoent* %23, null
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %18
%30 = load %struct.protoent*, %struct.protoent** %6
%31 = getelementptr inbounds %struct.protoent, %struct.protoent* %30, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = load %struct.protoent*, %struct.protoent** %6
%34 = getelementptr inbounds %struct.protoent, %struct.protoent* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %32, i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%38 = load %struct.protoent*, %struct.protoent** %6
%39 = getelementptr inbounds %struct.protoent, %struct.protoent* %38, i32 0, i32 2
%40 = load i8**, i8*** %39
store i8** %40, i8*** %7
br label %41
41: ; preds = %50, %29
%42 = load i8**, i8*** %7
%43 = icmp ne i8** %42, null
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i8**, i8*** %7
%46 = load i8*, i8** %45
%47 = icmp ne i8* %46, null
br label %48
48: ; preds = %44, %41
%49 = phi i1 [ false, %41 ], [ %47, %44 ]
br i1 %49, label %50, label %56
50: ; preds = %48
%51 = load i8**, i8*** %7
%52 = load i8*, i8** %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %52)
%54 = load i8**, i8*** %7
%55 = getelementptr inbounds i8*, i8** %54, i32 1
store i8** %55, i8*** %7
br label %41
56: ; preds = %48
%57 = load i32, i32* @EXIT_SUCCESS
%58 = call i32 @exit(i32 %57)
unreachable
}

LLVM IR (-O2):
%struct.protoent = type { i8*, i32, i8** }
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s protocol\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [15 x i8] c"getprotobyname\00"
@.str.2 = [20 x i8] c"Name: %s; type: %d\0A\00"
@.str.4 = [6 x i8] c" %s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [26 x i8] c"-------alias-------------\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call %struct.protoent* @getprotobyname(i8* %12)
%14 = icmp eq %struct.protoent* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = getelementptr inbounds %struct.protoent, %struct.protoent* %13, i64 0, i32 0
%21 = load i8*, i8** %20
%22 = getelementptr inbounds %struct.protoent, %struct.protoent* %13, i64 0, i32 1
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %21, i32 %23)
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%26 = getelementptr inbounds %struct.protoent, %struct.protoent* %13, i64 0, i32 2
%27 = load i8**, i8*** %26
%28 = icmp eq i8** %27, null
br i1 %28, label %39, label %29
29: ; preds = %19
%30 = load i8*, i8** %27
%31 = icmp eq i8* %30, null
br i1 %31, label %39, label %32
32: ; preds = %29, %32
%33 = phi i8* [ %37, %32 ], [ %30, %29 ]
%34 = phi i8** [ %36, %32 ], [ %27, %29 ]
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%36 = getelementptr inbounds i8*, i8** %34, i64 1
%37 = load i8*, i8** %36
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %32
39: ; preds = %32, %29, %19
%40 = load i32, i32* @EXIT_SUCCESS
%41 = tail call i32 @exit(i32 %40)
unreachable
}