#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 s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ statstime;
typedef int /*<<< orphan*/ host_stat;
typedef int /*<<< orphan*/ caddr_t;
typedef int /*<<< orphan*/ CLIENT;

/* Variables and functions */
scalar_t__ RPC_SUCCESS;
int /*<<< orphan*/ RSTATPROC_STATS;
int /*<<< orphan*/ RSTATPROG;
int /*<<< orphan*/ RSTATVERS_TIME;
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ clnt_call(int /*<<< orphan*/ *, int /*<<< orphan*/,
                     int /*<<< orphan*/, int /*<<< orphan*/ *,
                     int /*<<< orphan*/, int /*<<< orphan*/ *, struct timeval);
int /*<<< orphan*/ *clnt_create(char *, int /*<<< orphan*/, int /*<<< orphan*/,
                                char *);
int /*<<< orphan*/ clnt_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ clnt_spcreateerror(char *);
int /*<<< orphan*/ clnt_sperror(int /*<<< orphan*/ *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ rstat_reply(int /*<<< orphan*/, struct sockaddr_in *);
int /*<<< orphan*/ warnx(char *, char *, ...);
scalar_t__ xdr_statstime;
scalar_t__ xdr_void;
int onehost(char *host) {
  CLIENT *rstat_clnt;
  statstime host_stat;
  struct sockaddr_in addr;
  struct hostent *hp;
  struct timeval tv;
  hp = gethostbyname(host);
  if (hp == NULL) {
    warnx("unknown host \"%s\"", host);
    return (-1);
  }
  rstat_clnt = clnt_create(host, RSTATPROG, RSTATVERS_TIME, "udp");
  if (rstat_clnt == NULL) {
    warnx("%s %s", host, clnt_spcreateerror(""));
    return (-1);
  }
  bzero((char *)&host_stat, sizeof(host_stat));
  tv.tv_sec = 15;
  tv.tv_usec = 0;
  if (clnt_call(rstat_clnt, RSTATPROC_STATS, (xdrproc_t)xdr_void, NULL,
                (xdrproc_t)xdr_statstime, &host_stat, tv) != RPC_SUCCESS) {
    warnx("%s: %s", host, clnt_sperror(rstat_clnt, host));
    clnt_destroy(rstat_clnt);
    return (-1);
  }
  addr.sin_addr.s_addr = *(int *)hp->h_addr;
  rstat_reply((caddr_t)&host_stat, &addr);
  clnt_destroy(rstat_clnt);
  return (0);
}


x86 assembly (clang, -O0):
<onehost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d2 <onehost+0x42>
mov    -0x10(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <onehost+0x184>
mov    -0x10(%rbp),%rdi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
mov    0x2dca(%rip),%rax
mov    (%rax),%edx
lea    0xe23(%rip),%rcx
call   1070 <clnt_create@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1237 <onehost+0xa7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xdff(%rip),%rdi
call   1050 <clnt_spcreateerror@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <onehost+0x184>
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
call   10a0 <bzero@plt>
movl   $0xf,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
mov    0x2d78(%rip),%rax
mov    (%rax),%rax
mov    %eax,%edx
mov    0x2d84(%rip),%rax
mov    (%rax),%rax
mov    %eax,%r8d
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x1c(%rbp),%r9
lea    -0x38(%rbp),%rax
mov    (%rax),%r10
mov    %r10,(%rsp)
mov    0x8(%rax),%rax
mov    %rax,0x8(%rsp)
call   1080 <clnt_call@plt>
mov    0x2d36(%rip),%rcx
cmp    (%rcx),%rax
je     12e9 <onehost+0x159>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <clnt_sperror@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1040 <warnx@plt>
mov    -0x18(%rbp),%rdi
call   1090 <clnt_destroy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <onehost+0x184>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x1c(%rbp),%rax
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
call   1030 <rstat_reply@plt>
mov    -0x18(%rbp),%rdi
call   1090 <clnt_destroy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<onehost>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%r12
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     1263 <onehost+0xd3>
mov    %rax,%r15
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    0x2def(%rip),%rax
mov    (%rax),%edx
lea    0xe48(%rip),%rcx
mov    %r12,%rdi
call   1070 <clnt_create@plt>
test   %rax,%rax
je     1276 <onehost+0xe6>
mov    %rax,%r14
lea    0x1c(%rsp),%r13
mov    %r13,%rdi
mov    $0x4,%esi
call   10a0 <bzero@plt>
movl   $0xf,0x20(%rsp)
movq   $0x0,0x28(%rsp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
mov    0x2dde(%rip),%rax
mov    (%rax),%r8d
movups 0x20(%rsp),%xmm0
movups %xmm0,(%rsp)
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %ecx,%ecx
mov    %r13,%r9
call   1080 <clnt_call@plt>
mov    0x2d9c(%rip),%rcx
cmp    (%rcx),%rax
jne    1297 <onehost+0x107>
mov    (%r15),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
lea    0x1c(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1030 <rstat_reply@plt>
mov    %r14,%rdi
call   1090 <clnt_destroy@plt>
jmp    12c2 <onehost+0x132>
lea    0xd96(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <warnx@plt>
jmp    12bd <onehost+0x12d>
lea    0xd94(%rip),%rdi
call   1050 <clnt_spcreateerror@plt>
lea    0xd8d(%rip),%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <warnx@plt>
jmp    12bd <onehost+0x12d>
mov    %r14,%rdi
mov    %r12,%rsi
call   10b0 <clnt_sperror@plt>
lea    0xd73(%rip),%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <warnx@plt>
mov    %r14,%rdi
call   1090 <clnt_destroy@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64 }
%struct.timeval = type { i32, i64 }
@.str = [18 x i8] c"unknown host \22%s\22\00"
@RSTATPROG = global i32 0
@RSTATVERS_TIME = global i32 0
@.str.1 = [4 x i8] c"udp\00"
@.str.2 = [6 x i8] c"%s %s\00"
@.str.3 = [1 x i8] zeroinitializer
@RSTATPROC_STATS = global i32 0
@xdr_void = global i64 0
@xdr_statstime = global i64 0
@RPC_SUCCESS = global i64 0
@.str.4 = [7 x i8] c"%s: %s\00"
define i32 @onehost(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.hostent*
%8 = alloca %struct.timeval
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call %struct.hostent* @gethostbyname(i8* %9)
store %struct.hostent* %10, %struct.hostent** %7
%11 = load %struct.hostent*, %struct.hostent** %7
%12 = icmp eq %struct.hostent* %11, null
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 -1, i32* %2
br label %61
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = load i32, i32* @RSTATPROG
%19 = load i32, i32* @RSTATVERS_TIME
%20 = call i32* @clnt_create(i8* %17, i32 %18, i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %4
%21 = load i32*, i32** %4
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = load i8*, i8** %3
%25 = call i32 @clnt_spcreateerror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %24, i32 %25)
store i32 -1, i32* %2
br label %61
27: ; preds = %16
%28 = bitcast i32* %5 to i8*
%29 = call i32 @bzero(i8* %28, i32 4)
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i32 15, i32* %30
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
store i64 0, i64* %31
%32 = load i32*, i32** %4
%33 = load i32, i32* @RSTATPROC_STATS
%34 = load i64, i64* @xdr_void
%35 = trunc i64 %34 to i32
%36 = load i64, i64* @xdr_statstime
%37 = trunc i64 %36 to i32
%38 = call i64 @clnt_call(i32* %32, i32 %33, i32 %35, i32* null, i32 %37, i32* %5, %struct.timeval* byval(%struct.timeval) align 8 %8)
%39 = load i64, i64* @RPC_SUCCESS
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %49
41: ; preds = %27
%42 = load i8*, i8** %3
%43 = load i32*, i32** %4
%44 = load i8*, i8** %3
%45 = call i32 @clnt_sperror(i32* %43, i8* %44)
%46 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %42, i32 %45)
%47 = load i32*, i32** %4
%48 = call i32 @clnt_destroy(i32* %47)
store i32 -1, i32* %2
br label %61
49: ; preds = %27
%50 = load %struct.hostent*, %struct.hostent** %7
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i32 0, i32 0
%52 = load i64, i64* %51
%53 = inttoptr i64 %52 to i32*
%54 = load i32, i32* %53
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%56 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %55, i32 0, i32 0
store i32 %54, i32* %56
%57 = ptrtoint i32* %5 to i32
%58 = call i32 @rstat_reply(i32 %57, %struct.sockaddr_in* %6)
%59 = load i32*, i32** %4
%60 = call i32 @clnt_destroy(i32* %59)
store i32 0, i32* %2
br label %61
61: ; preds = %49, %41, %23, %13
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.hostent = type { i64 }
@.str = [18 x i8] c"unknown host \22%s\22\00"
@RSTATPROG = global i32 0
@RSTATVERS_TIME = global i32 0
@.str.1 = [4 x i8] c"udp\00"
@.str.2 = [6 x i8] c"%s %s\00"
@.str.3 = [1 x i8] zeroinitializer
@RSTATPROC_STATS = global i32 0
@xdr_void = global i64 0
@xdr_statstime = global i64 0
@RPC_SUCCESS = global i64 0
@.str.4 = [7 x i8] c"%s: %s\00"
define i32 @onehost(i8* %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.timeval
%5 = bitcast i32* %2 to i8*
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = tail call %struct.hostent* @gethostbyname(i8* %0)
%9 = icmp eq %struct.hostent* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = tail call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %46
12: ; preds = %1
%13 = load i32, i32* @RSTATPROG
%14 = load i32, i32* @RSTATVERS_TIME
%15 = tail call i32* @clnt_create(i8* %0, i32 %13, i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = tail call i32 @clnt_spcreateerror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%19 = tail call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %18)
br label %46
20: ; preds = %12
%21 = call i32 @bzero(i8* %5, i32 4)
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 15, i32* %22
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 0, i64* %23
%24 = load i32, i32* @RSTATPROC_STATS
%25 = load i64, i64* @xdr_void
%26 = trunc i64 %25 to i32
%27 = load i64, i64* @xdr_statstime
%28 = trunc i64 %27 to i32
%29 = call i64 @clnt_call(i32* %15, i32 %24, i32 %26, i32* null, i32 %28, i32* %2, %struct.timeval* byval(%struct.timeval) align 8 %4)
%30 = load i64, i64* @RPC_SUCCESS
%31 = icmp eq i64 %29, %30
br i1 %31, label %36, label %32
32: ; preds = %20
%33 = call i32 @clnt_sperror(i32* %15, i8* %0)
%34 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %33)
%35 = call i32 @clnt_destroy(i32* %15)
br label %46
36: ; preds = %20
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 0
%38 = load i64, i64* %37
%39 = inttoptr i64 %38 to i32*
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %40, i32* %41
%42 = ptrtoint i32* %2 to i64
%43 = trunc i64 %42 to i32
%44 = call i32 @rstat_reply(i32 %43, %struct.sockaddr_in* %3)
%45 = call i32 @clnt_destroy(i32* %15)
br label %46
46: ; preds = %36, %32, %17, %10
%47 = phi i32 [ -1, %10 ], [ -1, %17 ], [ -1, %32 ], [ 0, %36 ]
ret i32 %47
}