#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 rpcent {
  char *r_name;
  int r_number;
  scalar_t__ *r_aliases;
};
typedef int /*<<< orphan*/ rpcdata;

/* Variables and functions */
int ENOENT;
int /*<<< orphan*/ endrpcent();
int getrpcent_r(struct rpcent *, char *, int, struct rpcent **);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int main(int argc, char *argv[]) {
  int ret;
  char rpcdata[1024];
  struct rpcent rpcbuf, *ent;
  while ((ret = getrpcent_r(&rpcbuf, rpcdata, sizeof(rpcdata), &ent)) == 0) {
    printf("%s: %i", ent->r_name, ent->r_number);
    while (ent->r_aliases[0])
      printf(" %s", *ent->r_aliases++);
    printf("\n");
  }
  if (ret != ENOENT)
    printf("Test failed: %s\n", strerror(ret));
  endrpcent();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x420(%rbp),%rsi
lea    -0x438(%rbp),%rdi
mov    $0x400,%edx
lea    -0x440(%rbp),%rcx
call   1050 <getrpcent_r@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    11fa <main+0xba>
mov    -0x440(%rbp),%rax
mov    (%rax),%rsi
mov    -0x440(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x440(%rbp),%rax
mov    0x10(%rax),%rax
cmpq   $0x0,(%rax)
je     11e7 <main+0xa7>
mov    -0x440(%rbp),%rcx
mov    0x10(%rcx),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,0x10(%rcx)
mov    (%rax),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a6 <main+0x66>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1159 <main+0x19>
mov    -0x14(%rbp),%eax
mov    0x2dd4(%rip),%rcx
cmp    (%rcx),%eax
je     1225 <main+0xe5>
mov    -0x14(%rbp),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <endrpcent@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x420,%rsp
lea    0x8(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    %rsp,%rcx
mov    $0x400,%edx
call   1060 <getrpcent_r@plt>
test   %eax,%eax
je     11b8 <main+0x68>
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%eax
je     119e <main+0x4e>
mov    %eax,%edi
call   1070 <strerror@plt>
lea    0xe77(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <endrpcent@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe41(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x20(%rsp),%r12
mov    %rsp,%r13
lea    0xe34(%rip),%rbx
jmp    1205 <main+0xb5>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x400,%edx
mov    %r13,%rcx
call   1060 <getrpcent_r@plt>
test   %eax,%eax
jne    117b <main+0x2b>
mov    (%rsp),%rax
mov    (%rax),%rsi
mov    0x8(%rax),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%rax
mov    0x10(%rax),%rcx
mov    (%rcx),%rsi
test   %rsi,%rsi
je     11e0 <main+0x90>
add    $0x10,%rax
nopl   (%rax)
add    $0x8,%rcx
mov    %rcx,(%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%rax
mov    0x10(%rax),%rcx
add    $0x10,%rax
mov    (%rcx),%rsi
test   %rsi,%rsi
jne    1230 <main+0xe0>
jmp    11e0 <main+0x90>

LLVM IR (-O0):
%struct.rpcent = type { i8*, i32, i64* }
@.str = [7 x i8] c"%s: %i\00"
@.str.1 = [4 x i8] c" %s\00"
@.str.2 = [2 x i8] c"\0A\00"
@ENOENT = global i32 0
@.str.3 = [17 x i8] c"Test failed: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca %struct.rpcent
%9 = alloca %struct.rpcent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %10
10: ; preds = %36, %2
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = call i32 @getrpcent_r(%struct.rpcent* %8, i8* %11, i32 1024, %struct.rpcent** %9)
store i32 %12, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %38
14: ; preds = %10
%15 = load %struct.rpcent*, %struct.rpcent** %9
%16 = getelementptr inbounds %struct.rpcent, %struct.rpcent* %15, i32 0, i32 0
%17 = load i8*, i8** %16
%18 = load %struct.rpcent*, %struct.rpcent** %9
%19 = getelementptr inbounds %struct.rpcent, %struct.rpcent* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %20)
br label %22
22: ; preds = %29, %14
%23 = load %struct.rpcent*, %struct.rpcent** %9
%24 = getelementptr inbounds %struct.rpcent, %struct.rpcent* %23, i32 0, i32 2
%25 = load i64*, i64** %24
%26 = getelementptr inbounds i64, i64* %25, i64 0
%27 = load i64, i64* %26
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %22
%30 = load %struct.rpcent*, %struct.rpcent** %9
%31 = getelementptr inbounds %struct.rpcent, %struct.rpcent* %30, i32 0, i32 2
%32 = load i64*, i64** %31
%33 = getelementptr inbounds i64, i64* %32, i32 1
store i64* %33, i64** %31
%34 = load i64, i64* %32
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %34)
br label %22
36: ; preds = %22
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %10
38: ; preds = %10
%39 = load i32, i32* %6
%40 = load i32, i32* @ENOENT
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i32, i32* %6
%44 = call i8* @strerror(i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %42, %38
%47 = call i32 (...) @endrpcent()
ret i32 0
}

LLVM IR (-O2):
%struct.rpcent = type { i8*, i32, i64* }
@.str = [7 x i8] c"%s: %i\00"
@.str.1 = [4 x i8] c" %s\00"
@ENOENT = global i32 0
@.str.3 = [17 x i8] c"Test failed: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.rpcent
%5 = alloca %struct.rpcent*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.rpcent* %4 to i8*
%8 = bitcast %struct.rpcent** %5 to i8*
%9 = call i32 @getrpcent_r(%struct.rpcent* %4, i8* %6, i32 1024, %struct.rpcent** %5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %38
11: ; preds = %2, %34
%12 = load %struct.rpcent*, %struct.rpcent** %5
%13 = getelementptr inbounds %struct.rpcent, %struct.rpcent* %12, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = getelementptr inbounds %struct.rpcent, %struct.rpcent* %12, i64 0, i32 1
%16 = load i32, i32* %15
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %16)
%18 = load %struct.rpcent*, %struct.rpcent** %5
%19 = getelementptr inbounds %struct.rpcent, %struct.rpcent* %18, i64 0, i32 2
%20 = load i64*, i64** %19
%21 = load i64, i64* %20
%22 = icmp eq i64 %21, 0
br i1 %22, label %34, label %23
23: ; preds = %11, %23
%24 = phi i64 [ %32, %23 ], [ %21, %11 ]
%25 = phi i64* [ %31, %23 ], [ %20, %11 ]
%26 = phi i64** [ %30, %23 ], [ %19, %11 ]
%27 = getelementptr inbounds i64, i64* %25, i64 1
store i64* %27, i64** %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %24)
%29 = load %struct.rpcent*, %struct.rpcent** %5
%30 = getelementptr inbounds %struct.rpcent, %struct.rpcent* %29, i64 0, i32 2
%31 = load i64*, i64** %30
%32 = load i64, i64* %31
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %23
34: ; preds = %23, %11
%35 = call i32 @putchar(i32 10)
%36 = call i32 @getrpcent_r(%struct.rpcent* %4, i8* %6, i32 1024, %struct.rpcent** %5)
%37 = icmp eq i32 %36, 0
br i1 %37, label %11, label %38
38: ; preds = %34, %2
%39 = phi i32 [ %9, %2 ], [ %36, %34 ]
%40 = load i32, i32* @ENOENT
%41 = icmp eq i32 %39, %40
br i1 %41, label %45, label %42
42: ; preds = %38
%43 = call i8* @strerror(i32 %39)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %42, %38
%46 = call i32 (...) @endrpcent()
ret i32 0
}