#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__ *, char *, unsigned int);
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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ rt_free(char *);
int /*<<< orphan*/ rt_kprintf(char *);
scalar_t__ rt_malloc(unsigned int);
int /*<<< orphan*/ stub1(TYPE_1__ *, char *, unsigned int);
bool_t xdr_reference(XDR *xdrs, char **pp, unsigned int size, xdrproc_t proc) {
  register char *loc = *pp;
  register bool_t stat;
  if (loc == NULL)
    switch (xdrs->x_op) {
    case XDR_FREE:
      return (TRUE);
    case XDR_DECODE:
      *pp = loc = (char *)rt_malloc(size);
      if (loc == NULL) {
        rt_kprintf("xdr_reference: out of memory\n");
        return (FALSE);
      }
      memset(loc, 0, (int)size);
      break;
    }
  stat = (*proc)(xdrs, loc, ((unsigned int)0 - 1));
  if (xdrs->x_op == XDR_FREE) {
    rt_free(loc);
    *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    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11fb <xdr_reference+0xbb>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
sub    $0x80,%eax
je     1199 <xdr_reference+0x59>
jmp    1186 <xdr_reference+0x46>
mov    -0x38(%rbp),%eax
sub    $0x81,%eax
je     11aa <xdr_reference+0x6a>
jmp    11f6 <xdr_reference+0xb6>
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    123b <xdr_reference+0xfb>
mov    -0x1c(%rbp),%edi
call   1040 <rt_malloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x30(%rbp)
jne    11e8 <xdr_reference+0xa8>
lea    0xe2e(%rip),%rdi
call   1060 <rt_kprintf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    123b <xdr_reference+0xfb>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
jmp    11fb <xdr_reference+0xbb>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0xffffffff,%edx
call   *%rax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x80,(%rax)
jne    1235 <xdr_reference+0xf5>
mov    -0x30(%rbp),%rdi
call   1050 <rt_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   %r12
push   %rbx
mov    %rcx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rsi),%rbx
test   %rbx,%rbx
je     1184 <xdr_reference+0x44>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0xffffffff,%edx
call   *%r15
mov    %eax,%ebp
cmpl   $0x80,(%r12)
jne    11da <xdr_reference+0x9a>
mov    %rbx,%rdi
call   1050 <rt_free@plt>
movq   $0x0,(%r14)
jmp    11da <xdr_reference+0x9a>
mov    (%r12),%eax
cmp    $0x81,%eax
je     119f <xdr_reference+0x5f>
cmp    $0x80,%eax
jne    11c1 <xdr_reference+0x81>
mov    0x2e4b(%rip),%rax
jmp    11d8 <xdr_reference+0x98>
mov    %edx,%ebp
mov    %edx,%edi
call   1040 <rt_malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11c5 <xdr_reference+0x85>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
jmp    1159 <xdr_reference+0x19>
xor    %ebx,%ebx
jmp    1159 <xdr_reference+0x19>
lea    0xe34(%rip),%rdi
call   1060 <rt_kprintf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
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"
@FALSE = global i32 0
define i32 @xdr_reference(%struct.TYPE_6__* %0, i8** %1, i32 %2, i32 (%struct.TYPE_6__*, i8*, i32)* %3) {
%5 = alloca i32
%6 = alloca %struct.TYPE_6__*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32 (%struct.TYPE_6__*, i8*, i32)*
%10 = alloca i8*
%11 = alloca i32
store %struct.TYPE_6__* %0, %struct.TYPE_6__** %6
store i8** %1, i8*** %7
store i32 %2, i32* %8
store i32 (%struct.TYPE_6__*, i8*, i32)* %3, i32 (%struct.TYPE_6__*, i8*, i32)** %9
%12 = load i8**, i8*** %7
%13 = load i8*, i8** %12
store i8* %13, i8** %10
%14 = load i8*, i8** %10
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %37
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 %36 [
i32 128, label %20
i32 129, label %22
]
20: ; preds = %16
%21 = load i32, i32* @TRUE
store i32 %21, i32* %5
br label %52
22: ; preds = %16
%23 = load i32, i32* %8
%24 = call i64 @rt_malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %10
%26 = load i8**, i8*** %7
store i8* %25, i8** %26
%27 = load i8*, i8** %10
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = call i32 @rt_kprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%31 = load i32, i32* @FALSE
store i32 %31, i32* %5
br label %52
32: ; preds = %22
%33 = load i8*, i8** %10
%34 = load i32, i32* %8
%35 = call i32 @memset(i8* %33, i32 0, i32 %34)
br label %36
36: ; preds = %16, %32
br label %37
37: ; preds = %36, %4
%38 = load i32 (%struct.TYPE_6__*, i8*, i32)*, i32 (%struct.TYPE_6__*, i8*, i32)** %9
%39 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%40 = load i8*, i8** %10
%41 = call i32 %38(%struct.TYPE_6__* %39, i8* %40, i32 -1)
store i32 %41, i32* %11
%42 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%43 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = icmp eq i32 %44, 128
br i1 %45, label %46, label %50
46: ; preds = %37
%47 = load i8*, i8** %10
%48 = call i32 @rt_free(i8* %47)
%49 = load i8**, i8*** %7
store i8* null, i8** %49
br label %50
50: ; preds = %46, %37
%51 = load i32, i32* %11
store i32 %51, i32* %5
br label %52
52: ; preds = %50, %29, %20
%53 = load i32, i32* %5
ret i32 %53
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32 }
@TRUE = global i32 0
@.str = [30 x i8] c"xdr_reference: out of memory\0A\00"
@FALSE = global i32 0
define i32 @xdr_reference(%struct.TYPE_6__* %0, i8** nocapture %1, i32 %2, i32 (%struct.TYPE_6__*, i8*, i32)* nocapture %3) {
%5 = load i8*, i8** %1
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %21
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 %21 [
i32 128, label %10
i32 129, label %12
]
10: ; preds = %7
%11 = load i32, i32* @TRUE
br label %29
12: ; preds = %7
%13 = tail call i64 @rt_malloc(i32 %2)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %1
%15 = icmp eq i64 %13, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = tail call i32 @rt_kprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @FALSE
br label %29
19: ; preds = %12
%20 = tail call i32 @memset(i8* %14, i32 0, i32 %2)
br label %21
21: ; preds = %19, %7, %4
%22 = phi i8* [ null, %7 ], [ %14, %19 ], [ %5, %4 ]
%23 = tail call i32 %3(%struct.TYPE_6__* %0, i8* %22, i32 -1)
%24 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, 128
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = tail call i32 @rt_free(i8* %22)
store i8* null, i8** %1
br label %29
29: ; preds = %21, %27, %16, %10
%30 = phi i32 [ %18, %16 ], [ %11, %10 ], [ %23, %27 ], [ %23, %21 ]
ret i32 %30
}