#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_6__ TYPE_3__;
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
typedef scalar_t__ xdrproc_t;
struct TYPE_4__ {
  scalar_t__ rp_stat;
};
struct TYPE_5__ {
  scalar_t__ proc;
  scalar_t__ where;
};
struct TYPE_6__ {
  TYPE_2__ ar_results;
};
struct rpc_msg {
  scalar_t__ rm_direction;
  TYPE_1__ rm_reply;
  TYPE_3__ acpted_rply;
};
typedef int /*<<< orphan*/ XDR;

/* Variables and functions */
scalar_t__ MSG_ACCEPTED;
scalar_t__ REPLY;
int /*<<< orphan*/ XDR_DECODE;
int /*<<< orphan*/ xdr_int(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ xdr_replymsg(int /*<<< orphan*/ *, struct rpc_msg *);
scalar_t__ xdr_void;
int /*<<< orphan*/ xdrmem_create(int /*<<< orphan*/ *, char *, size_t,
                                 int /*<<< orphan*/);
short parse_getport_response(char *buf, size_t len) {
  XDR xdr;
  xdrmem_create(&xdr, buf, len, XDR_DECODE);
  struct rpc_msg msg;
  msg.acpted_rply.ar_results.where = 0;
  msg.acpted_rply.ar_results.proc = (xdrproc_t)(xdr_void);
  xdr_replymsg(&xdr, &msg);
  if (msg.rm_direction != REPLY)
    return 0;
  if (msg.rm_reply.rp_stat != MSG_ACCEPTED)
    return 0;
  int port;
  xdr_int(&xdr, &port);
  return (short)(port);
}


x86 assembly (clang, -O0):
<parse_getport_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    0x2ea1(%rip),%rax
mov    (%rax),%ecx
lea    -0x1c(%rbp),%rdi
call   1050 <xdrmem_create@plt>
movq   $0x0,-0x28(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
lea    -0x1c(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1040 <xdr_replymsg@plt>
mov    -0x40(%rbp),%rax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%rax
je     119c <parse_getport_response+0x6c>
movw   $0x0,-0x2(%rbp)
jmp    11cf <parse_getport_response+0x9f>
mov    -0x38(%rbp),%rax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
je     11bb <parse_getport_response+0x8b>
movw   $0x0,-0x2(%rbp)
jmp    11cf <parse_getport_response+0x9f>
lea    -0x1c(%rbp),%rdi
lea    -0x44(%rbp),%rsi
call   1030 <xdr_int@plt>
mov    -0x44(%rbp),%eax
mov    %ax,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_getport_response>:
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rdx
mov    %rdi,%rsi
mov    0x2eae(%rip),%rax
mov    (%rax),%ecx
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <xdrmem_create@plt>
movq   $0x0,0x28(%rsp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rsp)
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <xdr_replymsg@plt>
mov    0x10(%rsp),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
jne    11ae <parse_getport_response+0x7e>
mov    0x18(%rsp),%rax
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%rax
jne    11ae <parse_getport_response+0x7e>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <xdr_int@plt>
movzwl 0x8(%rsp),%eax
jmp    11b0 <parse_getport_response+0x80>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rpc_msg = type { i64, %struct.TYPE_4__, %struct.TYPE_6__ }
%struct.TYPE_4__ = type { i64 }
%struct.TYPE_6__ = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i64, i64 }
@XDR_DECODE = global i32 0
@xdr_void = global i64 0
@REPLY = global i64 0
@MSG_ACCEPTED = global i64 0
define signext i16 @parse_getport_response(i8* %0, i64 %1) {
%3 = alloca i16
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.rpc_msg
%8 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = load i8*, i8** %4
%10 = load i64, i64* %5
%11 = load i32, i32* @XDR_DECODE
%12 = call i32 @xdrmem_create(i32* %6, i8* %9, i64 %10, i32 %11)
%13 = getelementptr inbounds %struct.rpc_msg, %struct.rpc_msg* %7, i32 0, i32 2
%14 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 1
store i64 0, i64* %15
%16 = load i64, i64* @xdr_void
%17 = getelementptr inbounds %struct.rpc_msg, %struct.rpc_msg* %7, i32 0, i32 2
%18 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %17, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %18, i32 0, i32 0
store i64 %16, i64* %19
%20 = call i32 @xdr_replymsg(i32* %6, %struct.rpc_msg* %7)
%21 = getelementptr inbounds %struct.rpc_msg, %struct.rpc_msg* %7, i32 0, i32 0
%22 = load i64, i64* %21
%23 = load i64, i64* @REPLY
%24 = icmp ne i64 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %2
store i16 0, i16* %3
br label %37
26: ; preds = %2
%27 = getelementptr inbounds %struct.rpc_msg, %struct.rpc_msg* %7, i32 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %27, i32 0, i32 0
%29 = load i64, i64* %28
%30 = load i64, i64* @MSG_ACCEPTED
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %26
store i16 0, i16* %3
br label %37
33: ; preds = %26
%34 = call i32 @xdr_int(i32* %6, i32* %8)
%35 = load i32, i32* %8
%36 = trunc i32 %35 to i16
store i16 %36, i16* %3
br label %37
37: ; preds = %33, %32, %25
%38 = load i16, i16* %3
ret i16 %38
}

LLVM IR (-O2):
%struct.rpc_msg = type { i64, %struct.TYPE_4__, %struct.TYPE_6__ }
%struct.TYPE_4__ = type { i64 }
%struct.TYPE_6__ = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i64, i64 }
@XDR_DECODE = global i32 0
@xdr_void = global i64 0
@REPLY = global i64 0
@MSG_ACCEPTED = global i64 0
define signext i16 @parse_getport_response(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca %struct.rpc_msg
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = load i32, i32* @XDR_DECODE
%8 = call i32 @xdrmem_create(i32* %3, i8* %0, i64 %1, i32 %7)
%9 = bitcast %struct.rpc_msg* %4 to i8*
%10 = getelementptr inbounds %struct.rpc_msg, %struct.rpc_msg* %4, i64 0, i32 2, i32 0, i32 1
store i64 0, i64* %10
%11 = load i64, i64* @xdr_void
%12 = getelementptr inbounds %struct.rpc_msg, %struct.rpc_msg* %4, i64 0, i32 2, i32 0, i32 0
store i64 %11, i64* %12
%13 = call i32 @xdr_replymsg(i32* %3, %struct.rpc_msg* %4)
%14 = getelementptr inbounds %struct.rpc_msg, %struct.rpc_msg* %4, i64 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* @REPLY
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %28
18: ; preds = %2
%19 = getelementptr inbounds %struct.rpc_msg, %struct.rpc_msg* %4, i64 0, i32 1, i32 0
%20 = load i64, i64* %19
%21 = load i64, i64* @MSG_ACCEPTED
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = bitcast i32* %5 to i8*
%25 = call i32 @xdr_int(i32* %3, i32* %5)
%26 = load i32, i32* %5
%27 = trunc i32 %26 to i16
br label %28
28: ; preds = %18, %2, %23
%29 = phi i16 [ %27, %23 ], [ 0, %2 ], [ 0, %18 ]
ret i16 %29
}