#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 */
typedef int /*<<< orphan*/ msg_buf;

/* Variables and functions */
int build_ping_message(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ rpcbind_recv(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ rpcbind_send(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ update_xid(char *);
int rpcbind_ping(void) {
  char msg_buf[1024];
  int msg_len;
  printf("=== Pinging rpcbind ===\n");
  msg_len = build_ping_message(msg_buf, sizeof(msg_buf));
  update_xid(msg_buf);
  if (!rpcbind_send(msg_buf, msg_len)) {
    perror("sendto failed");
    return 0;
  }
  if (rpcbind_recv(NULL, 0, 5) <= 0) {
    fprintf(stderr, "Unable to receive reply to ping message\n");
    return 0;
  }
  printf("Success!\n");
  printf("Server rpcbind alive and kicking\n");
  return 1;
}


x86 assembly (clang, -O0):
<rpcbind_ping>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1060 <build_ping_message@plt>
mov    %eax,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
call   1090 <update_xid@plt>
lea    -0x410(%rbp),%rdi
mov    -0x414(%rbp),%esi
call   1080 <rpcbind_send@plt>
cmp    $0x0,%eax
jne    11dd <rpcbind_ping+0x6d>
lea    0xe4d(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1237 <rpcbind_ping+0xc7>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <rpcbind_recv@plt>
cmp    $0x0,%rax
jg     1218 <rpcbind_ping+0xa8>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1237 <rpcbind_ping+0xc7>
lea    0xe31(%rip),%rdi
call   1030 <printf@plt>
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpcbind_ping>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1060 <build_ping_message@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <update_xid@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <rpcbind_send@plt>
test   %eax,%eax
je     1202 <rpcbind_ping+0x92>
xor    %ebx,%ebx
xor    %edi,%edi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <rpcbind_recv@plt>
test   %rax,%rax
jle    11e1 <rpcbind_ping+0x71>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    11f6 <rpcbind_ping+0x86>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdf7(%rip),%rdi
call   1070 <perror@plt>
xor    %ebx,%ebx
jmp    11f6 <rpcbind_ping+0x86>

LLVM IR (-O0):
@.str = [25 x i8] c"=== Pinging rpcbind ===\0A\00"
@.str.1 = [14 x i8] c"sendto failed\00"
@stderr = global i32 0
@.str.2 = [41 x i8] c"Unable to receive reply to ping message\0A\00"
@.str.3 = [10 x i8] c"Success!\0A\00"
@.str.4 = [34 x i8] c"Server rpcbind alive and kicking\0A\00"
define i32 @rpcbind_ping() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = call i32 @build_ping_message(i8* %5, i32 1024)
store i32 %6, i32* %3
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%8 = call i32 @update_xid(i8* %7)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* %3
%11 = call i32 @rpcbind_send(i8* %9, i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %24
15: ; preds = %0
%16 = call i64 @rpcbind_recv(i32* null, i32 0, i32 5)
%17 = icmp sle i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %24
21: ; preds = %15
%22 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %24
24: ; preds = %21, %18, %13
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"sendto failed\00"
@stderr = global i32 0
@.str.2 = [41 x i8] c"Unable to receive reply to ping message\0A\00"
@str = [24 x i8] c"=== Pinging rpcbind ===\00"
@str.5 = [9 x i8] c"Success!\00"
@str.6 = [33 x i8] c"Server rpcbind alive and kicking\00"
define i32 @rpcbind_ping() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%4 = call i32 @build_ping_message(i8* %2, i32 1024)
%5 = call i32 @update_xid(i8* %2)
%6 = call i32 @rpcbind_send(i8* %2, i32 %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %19
10: ; preds = %0
%11 = call i64 @rpcbind_recv(i32* null, i32 0, i32 5)
%12 = icmp slt i64 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %19
16: ; preds = %10
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.5, i64 0, i64 0))
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.6, i64 0, i64 0))
br label %19
19: ; preds = %16, %13, %8
%20 = phi i32 [ 0, %13 ], [ 1, %16 ], [ 0, %8 ]
ret i32 %20
}