#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 servent {
  char *s_name;
  int s_port;
  char *s_proto;
  char **s_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 servent *my_getservnam(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct servent *result;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s service protocol\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  result = my_getservnam(argv[1], argv[2]);
  if (result == NULL) {
    perror("getservnam");
    exit(EXIT_FAILURE);
  }
  printf("Name: %s; port: %d, proto: %s\n", result->s_name, result->s_port,
         result->s_proto);
  printf("-------alias-------------\n");
  char **ptr = result->s_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   $0x3,-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
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1060 <my_getservnam@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d8 <main+0x88>
lea    0xe57(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
je     1234 <main+0xe4>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1244 <main+0xf4>
jmp    126a <main+0x11a>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1216 <main+0xc6>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1189 <main+0x29>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
call   1070 <my_getservnam@plt>
test   %rax,%rax
jne    11af <main+0x4f>
lea    0xe9a(%rip),%rdi
call   1060 <perror@plt>
jmp    11a1 <main+0x41>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe64(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %rax,%rbx
mov    (%rax),%rsi
mov    0x8(%rax),%edx
mov    0x10(%rax),%rcx
lea    0xe64(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     1216 <main+0xb6>
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1216 <main+0xb6>
add    $0x8,%rbx
lea    0xe54(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1200 <main+0xa0>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.servent = type { i8*, i32, i8*, i8** }
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s service protocol\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [11 x i8] c"getservnam\00"
@.str.2 = [31 x i8] c"Name: %s; port: %d, proto: %s\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.servent*
%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, 3
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 ([28 x i8], [28 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 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call %struct.servent* @my_getservnam(i8* %21, i8* %24)
store %struct.servent* %25, %struct.servent** %6
%26 = load %struct.servent*, %struct.servent** %6
%27 = icmp eq %struct.servent* %26, null
br i1 %27, label %28, label %32
28: ; preds = %18
%29 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %18
%33 = load %struct.servent*, %struct.servent** %6
%34 = getelementptr inbounds %struct.servent, %struct.servent* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = load %struct.servent*, %struct.servent** %6
%37 = getelementptr inbounds %struct.servent, %struct.servent* %36, i32 0, i32 1
%38 = load i32, i32* %37
%39 = load %struct.servent*, %struct.servent** %6
%40 = getelementptr inbounds %struct.servent, %struct.servent* %39, i32 0, i32 2
%41 = load i8*, i8** %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %35, i32 %38, i8* %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%44 = load %struct.servent*, %struct.servent** %6
%45 = getelementptr inbounds %struct.servent, %struct.servent* %44, i32 0, i32 3
%46 = load i8**, i8*** %45
store i8** %46, i8*** %7
br label %47
47: ; preds = %56, %32
%48 = load i8**, i8*** %7
%49 = icmp ne i8** %48, null
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = load i8**, i8*** %7
%52 = load i8*, i8** %51
%53 = icmp ne i8* %52, null
br label %54
54: ; preds = %50, %47
%55 = phi i1 [ false, %47 ], [ %53, %50 ]
br i1 %55, label %56, label %62
56: ; preds = %54
%57 = load i8**, i8*** %7
%58 = load i8*, i8** %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %58)
%60 = load i8**, i8*** %7
%61 = getelementptr inbounds i8*, i8** %60, i32 1
store i8** %61, i8*** %7
br label %47
62: ; preds = %54
%63 = load i32, i32* @EXIT_SUCCESS
%64 = call i32 @exit(i32 %63)
unreachable
}

LLVM IR (-O2):
%struct.servent = type { i8*, i32, i8*, i8** }
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s service protocol\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [11 x i8] c"getservnam\00"
@.str.2 = [31 x i8] c"Name: %s; port: %d, proto: %s\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, 3
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 ([28 x i8], [28 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 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call %struct.servent* @my_getservnam(i8* %12, i8* %14)
%16 = icmp eq %struct.servent* %15, null
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %10
%22 = getelementptr inbounds %struct.servent, %struct.servent* %15, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = getelementptr inbounds %struct.servent, %struct.servent* %15, i64 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.servent, %struct.servent* %15, i64 0, i32 2
%27 = load i8*, i8** %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %23, i32 %25, i8* %27)
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%30 = getelementptr inbounds %struct.servent, %struct.servent* %15, i64 0, i32 3
%31 = load i8**, i8*** %30
%32 = icmp eq i8** %31, null
br i1 %32, label %43, label %33
33: ; preds = %21
%34 = load i8*, i8** %31
%35 = icmp eq i8* %34, null
br i1 %35, label %43, label %36
36: ; preds = %33, %36
%37 = phi i8* [ %41, %36 ], [ %34, %33 ]
%38 = phi i8** [ %40, %36 ], [ %31, %33 ]
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%40 = getelementptr inbounds i8*, i8** %38, i64 1
%41 = load i8*, i8** %40
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %36
43: ; preds = %36, %33, %21
%44 = load i32, i32* @EXIT_SUCCESS
%45 = tail call i32 @exit(i32 %44)
unreachable
}