#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*/ fputs(char *, 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    1213 <xdr_reference+0xd3>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
sub    $0x80,%eax
je     119a <xdr_reference+0x5a>
jmp    1187 <xdr_reference+0x47>
mov    -0x38(%rbp),%eax
sub    $0x81,%eax
je     11ab <xdr_reference+0x6b>
jmp    1209 <xdr_reference+0xc9>
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1259 <xdr_reference+0x119>
mov    -0x20(%rbp),%rdi
call   1060 <mem_alloc@plt>
movslq %eax,%rcx
mov    %rcx,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x30(%rbp)
jne    11f3 <xdr_reference+0xb3>
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
lea    0xe23(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1259 <xdr_reference+0x119>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
jmp    120e <xdr_reference+0xce>
jmp    120e <xdr_reference+0xce>
jmp    1213 <xdr_reference+0xd3>
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    1253 <xdr_reference+0x113>
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     118f <xdr_reference+0x4f>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0xffffffffffffffff,%rdx
call   *%r12
mov    %eax,%ebp
cmpl   $0x80,0x0(%r13)
jne    11ed <xdr_reference+0xad>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <mem_free@plt>
movq   $0x0,(%r15)
jmp    11ed <xdr_reference+0xad>
mov    0x0(%r13),%eax
cmp    $0x81,%eax
je     11aa <xdr_reference+0x6a>
cmp    $0x80,%eax
jne    11cb <xdr_reference+0x8b>
mov    0x2e40(%rip),%rax
jmp    11eb <xdr_reference+0xab>
mov    %r14,%rdi
call   1060 <mem_alloc@plt>
movslq %eax,%rbx
mov    %rbx,(%r15)
test   %ebx,%ebx
je     11cf <xdr_reference+0x8f>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
jmp    115f <xdr_reference+0x1f>
xor    %ebx,%ebx
jmp    115f <xdr_reference+0x1f>
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
lea    0xe21(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2de5(%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 %41
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 %39 [
i32 128, label %20
i32 129, label %22
]
20: ; preds = %16
%21 = load i32, i32* @TRUE
store i32 %21, i32* %5
br label %57
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 %34
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = call i32 @fputs(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = load i32, i32* @FALSE
store i32 %33, i32* %5
br label %57
34: ; preds = %22
%35 = load i32*, i32** %10
%36 = load i64, i64* %8
%37 = trunc i64 %36 to i32
%38 = call i32 @memset(i32* %35, i32 0, i32 %37)
br label %40
39: ; preds = %16
br label %40
40: ; preds = %39, %34
br label %41
41: ; preds = %40, %4
%42 = load i32 (%struct.TYPE_6__*, i32*, i64)*, i32 (%struct.TYPE_6__*, i32*, i64)** %9
%43 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%44 = load i32*, i32** %10
%45 = call i32 %42(%struct.TYPE_6__* %43, i32* %44, i64 -1)
store i32 %45, i32* %11
%46 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%47 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = icmp eq i32 %48, 128
br i1 %49, label %50, label %55
50: ; preds = %41
%51 = load i32*, i32** %10
%52 = load i64, i64* %8
%53 = call i32 @mem_free(i32* %51, i64 %52)
%54 = load i32**, i32*** %7
store i32* null, i32** %54
br label %55
55: ; preds = %50, %41
%56 = load i32, i32* %11
store i32 %56, i32* %5
br label %57
57: ; preds = %55, %30, %20
%58 = load i32, i32* %5
ret i32 %58
}

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 %24
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 %24 [
i32 128, label %10
i32 129, label %12
]
10: ; preds = %7
%11 = load i32, i32* @TRUE
br label %32
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 %21
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = tail call i32 @fputs(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @FALSE
br label %32
21: ; preds = %12
%22 = trunc i64 %2 to i32
%23 = tail call i32 @memset(i32* %15, i32 0, i32 %22)
br label %24
24: ; preds = %21, %7, %4
%25 = phi i32* [ null, %7 ], [ %15, %21 ], [ %5, %4 ]
%26 = tail call i32 %3(%struct.TYPE_6__* %0, i32* %25, i64 -1)
%27 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 128
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = tail call i32 @mem_free(i32* %25, i64 %2)
store i32* null, i32** %1
br label %32
32: ; preds = %24, %30, %17, %10
%33 = phi i32 [ %20, %17 ], [ %11, %10 ], [ %26, %30 ], [ %26, %24 ]
ret i32 %33
}