#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_1__;

/* Type definitions */
typedef int /*<<< orphan*/ (*xdrproc_t)(TYPE_1__ *, int /*<<< orphan*/ *,
                                        scalar_t__);
typedef scalar_t__ u_int;
typedef int /*<<< orphan*/ *caddr_t;
typedef int /*<<< orphan*/ bool_t;
struct TYPE_6__ {
  int x_op;
};
typedef TYPE_1__ XDR;

/* Variables and functions */
int /*<<< orphan*/ FALSE;
int /*<<< orphan*/ TRUE;
#define XDR_DECODE 129
#define XDR_FREE 128
int /*<<< orphan*/ _(char *);
int /*<<< orphan*/ fputs(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mem_alloc(scalar_t__);
int /*<<< orphan*/ mem_free(int /*<<< orphan*/ *, scalar_t__);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stub1(TYPE_1__ *, int /*<<< orphan*/ *, scalar_t__);
bool_t xdr_reference(XDR *xdrs, caddr_t *pp, u_int size, xdrproc_t proc) {
  caddr_t loc = *pp;
  bool_t stat;
  if (loc == NULL)
    switch (xdrs->x_op) {
    case XDR_FREE:
      return TRUE;
    case XDR_DECODE:
      *pp = loc = (caddr_t)mem_alloc(size);
      if (loc == NULL) {
        (void)fputs(_("xdr_reference: out of memory\n"), stderr);
        return FALSE;
      }
      memset(loc, 0, (int)size);
      break;
    default:
      break;
    }
  stat = (*proc)(xdrs, loc, ((u_int)0 - 1));
  if (xdrs->x_op == XDR_FREE) {
    mem_free(loc, size);
    *pp = NULL;
  }
  return stat;
}


x86 assembly (clang, -O0):
<xdr_reference>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    122a <xdr_reference+0xda>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
sub    $0x80,%eax
je     11aa <xdr_reference+0x5a>
jmp    1197 <xdr_reference+0x47>
mov    -0x38(%rbp),%eax
sub    $0x81,%eax
je     11bb <xdr_reference+0x6b>
jmp    1220 <xdr_reference+0xd0>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1270 <xdr_reference+0x120>
mov    -0x20(%rbp),%rdi
call   1070 <mem_alloc@plt>
movslq %eax,%rcx
mov    %rcx,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x30(%rbp)
jne    120a <xdr_reference+0xba>
lea    0xe1c(%rip),%rdi
call   1060 <_@plt>
mov    %eax,%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1270 <xdr_reference+0x120>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
jmp    1225 <xdr_reference+0xd5>
jmp    1225 <xdr_reference+0xd5>
jmp    122a <xdr_reference+0xda>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0xffffffffffffffff,%rdx
call   *%rax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x80,(%rax)
jne    126a <xdr_reference+0x11a>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <mem_free@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xdr_reference>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
mov    (%rsi),%rbx
test   %rbx,%rbx
je     119f <xdr_reference+0x4f>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0xffffffffffffffff,%rdx
call   *%r12
mov    %eax,%ebp
cmpl   $0x80,0x0(%r13)
jne    1204 <xdr_reference+0xb4>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <mem_free@plt>
movq   $0x0,(%r15)
jmp    1204 <xdr_reference+0xb4>
mov    0x0(%r13),%eax
cmp    $0x81,%eax
je     11ba <xdr_reference+0x6a>
cmp    $0x80,%eax
jne    11db <xdr_reference+0x8b>
mov    0x2e30(%rip),%rax
jmp    1202 <xdr_reference+0xb2>
mov    %r14,%rdi
call   1070 <mem_alloc@plt>
movslq %eax,%rbx
mov    %rbx,(%r15)
test   %ebx,%ebx
je     11df <xdr_reference+0x8f>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
jmp    116f <xdr_reference+0x1f>
xor    %ebx,%ebx
jmp    116f <xdr_reference+0x1f>
lea    0xe1a(%rip),%rdi
call   1060 <_@plt>
mov    0x2de6(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1040 <fputs@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i32 }
@TRUE = global i32 0
@.str = [30 x i8] c"xdr_reference: out of memory\0A\00"
@stderr = global i32 0
@FALSE = global i32 0
define i32 @xdr_reference(%struct.TYPE_6__* %0, i32** %1, i64 %2, i32 (%struct.TYPE_6__*, i32*, i64)* %3) {
%5 = alloca i32
%6 = alloca %struct.TYPE_6__*
%7 = alloca i32**
%8 = alloca i64
%9 = alloca i32 (%struct.TYPE_6__*, i32*, i64)*
%10 = alloca i32*
%11 = alloca i32
store %struct.TYPE_6__* %0, %struct.TYPE_6__** %6
store i32** %1, i32*** %7
store i64 %2, i64* %8
store i32 (%struct.TYPE_6__*, i32*, i64)* %3, i32 (%struct.TYPE_6__*, i32*, i64)** %9
%12 = load i32**, i32*** %7
%13 = load i32*, i32** %12
store i32* %13, i32** %10
%14 = load i32*, i32** %10
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %42
16: ; preds = %4
%17 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%18 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %17, i32 0, i32 0
%19 = load i32, i32* %18
switch i32 %19, label %40 [
i32 128, label %20
i32 129, label %22
]
20: ; preds = %16
%21 = load i32, i32* @TRUE
store i32 %21, i32* %5
br label %58
22: ; preds = %16
%23 = load i64, i64* %8
%24 = call i32 @mem_alloc(i64 %23)
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i32*
store i32* %26, i32** %10
%27 = load i32**, i32*** %7
store i32* %26, i32** %27
%28 = load i32*, i32** %10
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %35
30: ; preds = %22
%31 = call i32 @_(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = call i32 @fputs(i32 %31, i32 %32)
%34 = load i32, i32* @FALSE
store i32 %34, i32* %5
br label %58
35: ; preds = %22
%36 = load i32*, i32** %10
%37 = load i64, i64* %8
%38 = trunc i64 %37 to i32
%39 = call i32 @memset(i32* %36, i32 0, i32 %38)
br label %41
40: ; preds = %16
br label %41
41: ; preds = %40, %35
br label %42
42: ; preds = %41, %4
%43 = load i32 (%struct.TYPE_6__*, i32*, i64)*, i32 (%struct.TYPE_6__*, i32*, i64)** %9
%44 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%45 = load i32*, i32** %10
%46 = call i32 %43(%struct.TYPE_6__* %44, i32* %45, i64 -1)
store i32 %46, i32* %11
%47 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%48 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = icmp eq i32 %49, 128
br i1 %50, label %51, label %56
51: ; preds = %42
%52 = load i32*, i32** %10
%53 = load i64, i64* %8
%54 = call i32 @mem_free(i32* %52, i64 %53)
%55 = load i32**, i32*** %7
store i32* null, i32** %55
br label %56
56: ; preds = %51, %42
%57 = load i32, i32* %11
store i32 %57, i32* %5
br label %58
58: ; preds = %56, %30, %20
%59 = load i32, i32* %5
ret i32 %59
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32 }
@TRUE = global i32 0
@.str = [30 x i8] c"xdr_reference: out of memory\0A\00"
@stderr = global i32 0
@FALSE = global i32 0
define i32 @xdr_reference(%struct.TYPE_6__* %0, i32** nocapture %1, i64 %2, i32 (%struct.TYPE_6__*, i32*, i64)* nocapture %3) {
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0
%9 = load i32, i32* %8
switch i32 %9, label %25 [
i32 128, label %10
i32 129, label %12
]
10: ; preds = %7
%11 = load i32, i32* @TRUE
br label %33
12: ; preds = %7
%13 = tail call i32 @mem_alloc(i64 %2)
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %1
%16 = icmp eq i32 %13, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = tail call i32 @_(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = tail call i32 @fputs(i32 %18, i32 %19)
%21 = load i32, i32* @FALSE
br label %33
22: ; preds = %12
%23 = trunc i64 %2 to i32
%24 = tail call i32 @memset(i32* %15, i32 0, i32 %23)
br label %25
25: ; preds = %22, %7, %4
%26 = phi i32* [ null, %7 ], [ %15, %22 ], [ %5, %4 ]
%27 = tail call i32 %3(%struct.TYPE_6__* %0, i32* %26, i64 -1)
%28 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 128
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = tail call i32 @mem_free(i32* %26, i64 %2)
store i32* null, i32** %1
br label %33
33: ; preds = %25, %31, %17, %10
%34 = phi i32 [ %21, %17 ], [ %11, %10 ], [ %27, %31 ], [ %27, %25 ]
ret i32 %34
}