#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ xdrproc_t;
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  scalar_t__ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ *h_addr_list;
};
typedef enum clnt_stat { ____Placeholder_clnt_stat } clnt_stat;
typedef int /*<<< orphan*/ addr;
typedef int /*<<< orphan*/ CLIENT;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int RPC_ANYSOCK;
int RPC_SUCCESS;
int clnt_call(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
              int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
              struct timeval);
int /*<<< orphan*/ clnt_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ clnt_pcreateerror(char *);
int /*<<< orphan*/ *clntudp_create(struct sockaddr_in *, int, int,
                                   struct timeval, int *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ herror(char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ xdr_void;
int ping_udp(char *hostname, int prog_num, int version, int timeout) {
  struct sockaddr_in addr;
  struct hostent *hent;
  CLIENT *clnt;
  struct timeval val;
  enum clnt_stat ans;
  int s = RPC_ANYSOCK, ret;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = 0;
  hent = gethostbyname(hostname);
  if (hent != NULL) {
    memcpy(&addr.sin_addr.s_addr, hent->h_addr_list[0], hent->h_length);
  } else {
    herror("Could not lookup hostname:");
    return -1;
  }
  val.tv_sec = timeout;
  val.tv_usec = 0;
  if ((clnt = clntudp_create(&addr, prog_num, version, val, &s)) == NULL) {
    clnt_pcreateerror("Could not create udp client handle");
    return -1;
  }
  ans = clnt_call(clnt, 0, (xdrproc_t)xdr_void, 0, (xdrproc_t)xdr_void, 0, val);
  if (ans != RPC_SUCCESS) {
    ret = -1;
    printf("No answer from the specified program's UDP service\n");
  } else {
    ret = 0;
    printf("Specified program's UDP service is alive\n");
  }
  clnt_destroy(clnt);
  return ret;
}


x86 assembly (clang, -O0):
<ping_udp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     120e <ping_udp+0x7e>
lea    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   1060 <memcpy@plt>
jmp    1226 <ping_udp+0x96>
lea    0xdeb(%rip),%rdi
call   1070 <herror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1302 <ping_udp+0x172>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x58(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x58(%rbp),%ecx
mov    -0x50(%rbp),%r8
lea    -0x38(%rbp),%rdi
lea    -0x60(%rbp),%r9
call   10b0 <clntudp_create@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    1274 <ping_udp+0xe4>
lea    0xdb8(%rip),%rdi
call   1090 <clnt_pcreateerror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1302 <ping_udp+0x172>
mov    -0x48(%rbp),%rdi
mov    0x2d59(%rip),%rax
mov    (%rax),%rax
mov    %eax,%edx
mov    0x2d4d(%rip),%rax
mov    (%rax),%rax
mov    %eax,%r8d
xor    %r9d,%r9d
lea    -0x58(%rbp),%rax
mov    %r9d,%esi
mov    %r9d,%ecx
mov    (%rax),%r10
mov    %r10,(%rsp)
mov    0x8(%rax),%rax
mov    %rax,0x8(%rsp)
call   1080 <clnt_call@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x2d10(%rip),%rcx
cmp    (%rcx),%eax
je     12e0 <ping_udp+0x150>
movl   $0xffffffff,-0x64(%rbp)
lea    0xd68(%rip),%rdi
call   1030 <printf@plt>
jmp    12f3 <ping_udp+0x163>
movl   $0x0,-0x64(%rbp)
lea    0xd84(%rip),%rdi
call   1030 <printf@plt>
mov    -0x48(%rbp),%rdi
call   10a0 <clnt_destroy@plt>
mov    -0x64(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ping_udp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbp
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
lea    0x30(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
movq   $0x0,0x38(%rsp)
mov    %rbp,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     1282 <ping_udp+0xf2>
mov    0x8(%rax),%rcx
mov    (%rcx),%esi
mov    (%rax),%edx
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <memcpy@plt>
mov    %ebx,0x20(%rsp)
movq   $0x0,0x28(%rsp)
lea    0x1c(%rsp),%r9
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
xor    %r8d,%r8d
call   10b0 <clntudp_create@plt>
test   %rax,%rax
je     1290 <ping_udp+0x100>
mov    %rax,%rbx
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
movups 0x20(%rsp),%xmm0
movups %xmm0,(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
xor    %ecx,%ecx
mov    %edx,%r8d
xor    %r9d,%r9d
call   1080 <clnt_call@plt>
mov    0x2d79(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%eax
setne  %bpl
lea    0xdd8(%rip),%rax
lea    0xdfa(%rip),%rdi
cmove  %rax,%rdi
neg    %ebp
call   1030 <puts@plt>
mov    %rbx,%rdi
call   10a0 <clnt_destroy@plt>
jmp    12a1 <ping_udp+0x111>
lea    0xd77(%rip),%rdi
call   1070 <herror@plt>
jmp    129c <ping_udp+0x10c>
lea    0xd84(%rip),%rdi
call   1090 <clnt_pcreateerror@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32* }
%struct.timeval = type { i32, i64 }
@RPC_ANYSOCK = global i32 0
@AF_INET = global i32 0
@.str = [27 x i8] c"Could not lookup hostname:\00"
@.str.1 = [35 x i8] c"Could not create udp client handle\00"
@xdr_void = global i64 0
@RPC_SUCCESS = global i32 0
@.str.2 = [52 x i8] c"No answer from the specified program's UDP service\0A\00"
@.str.3 = [42 x i8] c"Specified program's UDP service is alive\0A\00"
define i32 @ping_udp(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.hostent*
%12 = alloca i32*
%13 = alloca %struct.timeval
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%17 = load i32, i32* @RPC_ANYSOCK
store i32 %17, i32* %15
%18 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 24)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i64 0, i64* %21
%22 = load i8*, i8** %6
%23 = call %struct.hostent* @gethostbyname(i8* %22)
store %struct.hostent* %23, %struct.hostent** %11
%24 = load %struct.hostent*, %struct.hostent** %11
%25 = icmp ne %struct.hostent* %24, null
br i1 %25, label %26, label %38
26: ; preds = %4
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
%29 = load %struct.hostent*, %struct.hostent** %11
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i32 0, i32 1
%31 = load i32*, i32** %30
%32 = getelementptr inbounds i32, i32* %31, i64 0
%33 = load i32, i32* %32
%34 = load %struct.hostent*, %struct.hostent** %11
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @memcpy(i32* %28, i32 %33, i32 %36)
br label %40
38: ; preds = %4
%39 = call i32 @herror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %73
40: ; preds = %26
%41 = load i32, i32* %9
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
store i32 %41, i32* %42
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
store i64 0, i64* %43
%44 = load i32, i32* %7
%45 = load i32, i32* %8
%46 = bitcast %struct.timeval* %13 to { i32, i64 }*
%47 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %46, i32 0, i32 1
%50 = load i64, i64* %49
%51 = call i32* @clntudp_create(%struct.sockaddr_in* %10, i32 %44, i32 %45, i32 %48, i64 %50, i32* %15)
store i32* %51, i32** %12
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %55
53: ; preds = %40
%54 = call i32 @clnt_pcreateerror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %73
55: ; preds = %40
%56 = load i32*, i32** %12
%57 = load i64, i64* @xdr_void
%58 = trunc i64 %57 to i32
%59 = load i64, i64* @xdr_void
%60 = trunc i64 %59 to i32
%61 = call i32 @clnt_call(i32* %56, i32 0, i32 %58, i32 0, i32 %60, i32 0, %struct.timeval* byval(%struct.timeval) align 8 %13)
store i32 %61, i32* %14
%62 = load i32, i32* %14
%63 = load i32, i32* @RPC_SUCCESS
%64 = icmp ne i32 %62, %63
br i1 %64, label %65, label %67
65: ; preds = %55
store i32 -1, i32* %16
%66 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
br label %69
67: ; preds = %55
store i32 0, i32* %16
%68 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %67, %65
%70 = load i32*, i32** %12
%71 = call i32 @clnt_destroy(i32* %70)
%72 = load i32, i32* %16
store i32 %72, i32* %5
br label %73
73: ; preds = %69, %53, %38
%74 = load i32, i32* %5
ret i32 %74
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.hostent = type { i32, i32* }
@RPC_ANYSOCK = global i32 0
@AF_INET = global i32 0
@.str = [27 x i8] c"Could not lookup hostname:\00"
@.str.1 = [35 x i8] c"Could not create udp client handle\00"
@xdr_void = global i64 0
@RPC_SUCCESS = global i32 0
@str = [41 x i8] c"Specified program's UDP service is alive\00"
@str.4 = [51 x i8] c"No answer from the specified program's UDP service\00"
define i32 @ping_udp(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = bitcast %struct.timeval* %6 to i8*
%10 = bitcast i32* %7 to i8*
%11 = load i32, i32* @RPC_ANYSOCK
store i32 %11, i32* %7
%12 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 24)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i64 0, i64* %15
%16 = call %struct.hostent* @gethostbyname(i8* %0)
%17 = icmp eq %struct.hostent* %16, null
br i1 %17, label %30, label %18
18: ; preds = %4
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i64 0, i32 1
%21 = load i32*, i32** %20
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @memcpy(i32* %19, i32 %22, i32 %24)
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
store i32 %3, i32* %26
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
store i64 0, i64* %27
%28 = call i32* @clntudp_create(%struct.sockaddr_in* %5, i32 %1, i32 %2, i32 %3, i64 0, i32* %7)
%29 = icmp eq i32* %28, null
br i1 %29, label %32, label %34
30: ; preds = %4
%31 = call i32 @herror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %45
32: ; preds = %18
%33 = call i32 @clnt_pcreateerror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %45
34: ; preds = %18
%35 = load i64, i64* @xdr_void
%36 = trunc i64 %35 to i32
%37 = call i32 @clnt_call(i32* %28, i32 0, i32 %36, i32 0, i32 %36, i32 0, %struct.timeval* byval(%struct.timeval) align 8 %6)
%38 = load i32, i32* @RPC_SUCCESS
%39 = icmp eq i32 %37, %38
%40 = select i1 %39, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([51 x i8], [51 x i8]* @str.4, i64 0, i64 0)
%41 = xor i1 %39, true
%42 = sext i1 %41 to i32
%43 = call i32 @puts(i8* dereferenceable(1) %40)
%44 = call i32 @clnt_destroy(i32* %28)
br label %45
45: ; preds = %34, %32, %30
%46 = phi i32 [ -1, %32 ], [ %42, %34 ], [ -1, %30 ]
ret i32 %46
}