#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_5__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ bool_t;
struct TYPE_5__ {
  int x_op;
};
typedef TYPE_1__ XDR;

/* Variables and functions */
int /*<<< orphan*/ FALSE;
int /*<<< orphan*/ TRUE;
#define XDR_DECODE 130
#define XDR_ENCODE 129
#define XDR_FREE 128
int /*<<< orphan*/ rt_free(char *);
int /*<<< orphan*/ rt_kprintf(char *);
scalar_t__ rt_malloc(unsigned int);
unsigned int strlen(char *);
int /*<<< orphan*/ xdr_opaque(TYPE_1__ *, char *, unsigned int);
int /*<<< orphan*/ xdr_u_int(TYPE_1__ *, unsigned int *);
bool_t xdr_string(XDR *xdrs, char **cpp, unsigned int maxsize) {
  register char *sp = *cpp;
  unsigned int size;
  unsigned int nodesize;
  switch (xdrs->x_op) {
  case XDR_FREE:
    if (sp == NULL) {
      return (TRUE);
    }
  case XDR_ENCODE:
    size = strlen(sp);
    break;
  }
  if (!xdr_u_int(xdrs, &size)) {
    return (FALSE);
  }
  if (size > maxsize) {
    return (FALSE);
  }
  nodesize = size + 1;
  switch (xdrs->x_op) {
  case XDR_DECODE:
    if (nodesize == 0) {
      return (TRUE);
    }
    if (sp == NULL)
      *cpp = sp = (char *)rt_malloc(nodesize);
    if (sp == NULL) {
      rt_kprintf("xdr_string: out of memory\n");
      return (FALSE);
    }
    sp[size] = 0;
  case XDR_ENCODE:
    return (xdr_opaque(xdrs, sp, size));
  case XDR_FREE:
    rt_free(sp);
    *cpp = NULL;
    return (TRUE);
  }
  return (FALSE);
}


x86 assembly (clang, -O0):
<xdr_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
sub    $0x80,%eax
je     11aa <xdr_string+0x4a>
jmp    1197 <xdr_string+0x37>
mov    -0x34(%rbp),%eax
sub    $0x81,%eax
je     11cb <xdr_string+0x6b>
jmp    11d7 <xdr_string+0x77>
cmpq   $0x0,-0x28(%rbp)
jne    11c6 <xdr_string+0x66>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    131b <xdr_string+0x1bb>
jmp    11cb <xdr_string+0x6b>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1070 <xdr_u_int@plt>
cmp    $0x0,%eax
jne    11fe <xdr_string+0x9e>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    131b <xdr_string+0x1bb>
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jbe    121b <xdr_string+0xbb>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    131b <xdr_string+0x1bb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
sub    $0x80,%eax
je     12ea <xdr_string+0x18a>
jmp    123d <xdr_string+0xdd>
mov    -0x38(%rbp),%eax
sub    $0x81,%eax
je     12d2 <xdr_string+0x172>
jmp    1250 <xdr_string+0xf0>
mov    -0x38(%rbp),%eax
sub    $0x82,%eax
jne    130f <xdr_string+0x1af>
jmp    1263 <xdr_string+0x103>
cmpl   $0x0,-0x30(%rbp)
jne    127e <xdr_string+0x11e>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    131b <xdr_string+0x1bb>
cmpq   $0x0,-0x28(%rbp)
jne    129f <xdr_string+0x13f>
mov    -0x30(%rbp),%edi
call   1040 <rt_malloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
jne    12c7 <xdr_string+0x167>
lea    0xd4f(%rip),%rdi
call   1080 <rt_kprintf@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    131b <xdr_string+0x1bb>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <xdr_opaque@plt>
mov    %eax,-0x4(%rbp)
jmp    131b <xdr_string+0x1bb>
mov    -0x28(%rbp),%rdi
call   1060 <rt_free@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    0x2ce3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    131b <xdr_string+0x1bb>
mov    0x2cc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xdr_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    (%rsi),%r14
mov    (%rdi),%eax
cmp    $0x81,%eax
je     1187 <xdr_string+0x27>
cmp    $0x80,%eax
jne    1193 <xdr_string+0x33>
test   %r14,%r14
je     11ff <xdr_string+0x9f>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <xdr_u_int@plt>
test   %eax,%eax
je     122c <xdr_string+0xcc>
mov    0x4(%rsp),%edx
cmp    %ebp,%edx
ja     122c <xdr_string+0xcc>
mov    (%rbx),%eax
cmp    $0x80,%eax
je     1208 <xdr_string+0xa8>
cmp    $0x81,%eax
je     11f2 <xdr_string+0x92>
cmp    $0x82,%eax
jne    122c <xdr_string+0xcc>
mov    %edx,%edi
add    $0x1,%edi
je     11ff <xdr_string+0x9f>
test   %r14,%r14
jne    11e7 <xdr_string+0x87>
call   1040 <rt_malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1220 <xdr_string+0xc0>
mov    %rax,%r14
mov    0x4(%rsp),%edx
mov    %edx,%eax
movb   $0x0,(%r14,%rax,1)
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <xdr_opaque@plt>
jmp    1235 <xdr_string+0xd5>
mov    0x2de2(%rip),%rax
jmp    1233 <xdr_string+0xd3>
mov    %r14,%rdi
call   1060 <rt_free@plt>
movq   $0x0,(%r15)
mov    0x2dca(%rip),%rax
jmp    1233 <xdr_string+0xd3>
lea    0xdd9(%rip),%rdi
call   1080 <rt_kprintf@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32 }
@TRUE = global i32 0
@FALSE = global i32 0
@.str = [27 x i8] c"xdr_string: out of memory\0A\00"
define i32 @xdr_string(%struct.TYPE_5__* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_5__*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store %struct.TYPE_5__* %0, %struct.TYPE_5__** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%11 = load i8**, i8*** %6
%12 = load i8*, i8** %11
store i8* %12, i8** %8
%13 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i32 0, i32 0
%15 = load i32, i32* %14
switch i32 %15, label %25 [
i32 128, label %16
i32 129, label %22
]
16: ; preds = %3
%17 = load i8*, i8** %8
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load i32, i32* @TRUE
store i32 %20, i32* %4
br label %79
21: ; preds = %16
br label %22
22: ; preds = %3, %21
%23 = load i8*, i8** %8
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %9
br label %25
25: ; preds = %3, %22
%26 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%27 = call i32 @xdr_u_int(%struct.TYPE_5__* %26, i32* %9)
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = load i32, i32* @FALSE
store i32 %30, i32* %4
br label %79
31: ; preds = %25
%32 = load i32, i32* %9
%33 = load i32, i32* %7
%34 = icmp ugt i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = load i32, i32* @FALSE
store i32 %36, i32* %4
br label %79
37: ; preds = %31
%38 = load i32, i32* %9
%39 = add i32 %38, 1
store i32 %39, i32* %10
%40 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%41 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %40, i32 0, i32 0
%42 = load i32, i32* %41
switch i32 %42, label %77 [
i32 130, label %43
i32 129, label %67
i32 128, label %72
]
43: ; preds = %37
%44 = load i32, i32* %10
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = load i32, i32* @TRUE
store i32 %47, i32* %4
br label %79
48: ; preds = %43
%49 = load i8*, i8** %8
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load i32, i32* %10
%53 = call i64 @rt_malloc(i32 %52)
%54 = inttoptr i64 %53 to i8*
store i8* %54, i8** %8
%55 = load i8**, i8*** %6
store i8* %54, i8** %55
br label %56
56: ; preds = %51, %48
%57 = load i8*, i8** %8
%58 = icmp eq i8* %57, null
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = call i32 @rt_kprintf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%61 = load i32, i32* @FALSE
store i32 %61, i32* %4
br label %79
62: ; preds = %56
%63 = load i8*, i8** %8
%64 = load i32, i32* %9
%65 = zext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 0, i8* %66
br label %67
67: ; preds = %37, %62
%68 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%69 = load i8*, i8** %8
%70 = load i32, i32* %9
%71 = call i32 @xdr_opaque(%struct.TYPE_5__* %68, i8* %69, i32 %70)
store i32 %71, i32* %4
br label %79
72: ; preds = %37
%73 = load i8*, i8** %8
%74 = call i32 @rt_free(i8* %73)
%75 = load i8**, i8*** %6
store i8* null, i8** %75
%76 = load i32, i32* @TRUE
store i32 %76, i32* %4
br label %79
77: ; preds = %37
%78 = load i32, i32* @FALSE
store i32 %78, i32* %4
br label %79
79: ; preds = %77, %72, %67, %59, %46, %35, %29, %19
%80 = load i32, i32* %4
ret i32 %80
}

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