#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 scalar_t__ u_int;
typedef int bool_t;
struct TYPE_5__ {
  int x_op;
};
typedef TYPE_1__ XDR;

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


x86 assembly (clang, -O0):
<xdr_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x80,%eax
je     11be <xdr_string+0x5e>
jmp    1198 <xdr_string+0x38>
mov    -0x3c(%rbp),%eax
sub    $0x81,%eax
je     11da <xdr_string+0x7a>
jmp    11ab <xdr_string+0x4b>
mov    -0x3c(%rbp),%eax
sub    $0x82,%eax
je     11ec <xdr_string+0x8c>
jmp    11f1 <xdr_string+0x91>
cmpq   $0x0,-0x28(%rbp)
jne    11d5 <xdr_string+0x75>
movl   $0x1,-0x4(%rbp)
jmp    132e <xdr_string+0x1ce>
jmp    11da <xdr_string+0x7a>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
jmp    11f1 <xdr_string+0x91>
jmp    11f1 <xdr_string+0x91>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <xdr_u_int@plt>
cmp    $0x0,%eax
jne    1213 <xdr_string+0xb3>
movl   $0x0,-0x4(%rbp)
jmp    132e <xdr_string+0x1ce>
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    122d <xdr_string+0xcd>
movl   $0x0,-0x4(%rbp)
jmp    132e <xdr_string+0x1ce>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
sub    $0x80,%eax
je     1307 <xdr_string+0x1a7>
jmp    1252 <xdr_string+0xf2>
mov    -0x40(%rbp),%eax
sub    $0x81,%eax
je     12ee <xdr_string+0x18e>
jmp    1265 <xdr_string+0x105>
mov    -0x40(%rbp),%eax
sub    $0x82,%eax
jne    1327 <xdr_string+0x1c7>
jmp    1278 <xdr_string+0x118>
cmpq   $0x0,-0x38(%rbp)
jne    128f <xdr_string+0x12f>
movl   $0x1,-0x4(%rbp)
jmp    132e <xdr_string+0x1ce>
cmpq   $0x0,-0x28(%rbp)
jne    12b6 <xdr_string+0x156>
mov    -0x38(%rbp),%rsi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
jne    12e2 <xdr_string+0x182>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xd2f(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    132e <xdr_string+0x1ce>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <xdr_opaque@plt>
mov    %eax,-0x4(%rbp)
jmp    132e <xdr_string+0x1ce>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    132e <xdr_string+0x1ce>
movl   $0x0,-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   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    (%rsi),%r14
mov    (%rdi),%eax
cmp    $0x81,%eax
je     1191 <xdr_string+0x31>
cmp    $0x80,%eax
jne    119e <xdr_string+0x3e>
test   %r14,%r14
je     1224 <xdr_string+0xc4>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <xdr_u_int@plt>
xor    %r12d,%r12d
test   %eax,%eax
je     122a <xdr_string+0xca>
mov    0x8(%rsp),%rdx
cmp    %rbp,%rdx
jg     122a <xdr_string+0xca>
mov    (%rbx),%eax
cmp    $0x80,%eax
je     1215 <xdr_string+0xb5>
cmp    $0x81,%eax
je     1205 <xdr_string+0xa5>
cmp    $0x82,%eax
jne    122a <xdr_string+0xca>
mov    %rdx,%rsi
add    $0x1,%rsi
je     1224 <xdr_string+0xc4>
test   %r14,%r14
jne    11fb <xdr_string+0x9b>
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     123a <xdr_string+0xda>
mov    %rax,%r14
mov    0x8(%rsp),%rdx
movb   $0x0,(%r14,%rdx,1)
mov    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <xdr_opaque@plt>
mov    %eax,%r12d
jmp    122a <xdr_string+0xca>
mov    %r14,%rdi
call   1030 <free@plt>
movq   $0x0,(%r15)
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdb6(%rip),%rsi
call   1060 <fprintf@plt>
jmp    122a <xdr_string+0xca>

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32 }
@stderr = 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, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_5__*
%6 = alloca i8**
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store %struct.TYPE_5__* %0, %struct.TYPE_5__** %5
store i8** %1, i8*** %6
store i64 %2, i64* %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 %21
i32 130, label %24
]
16: ; preds = %3
%17 = load i8*, i8** %8
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 1, i32* %4
br label %73
20: ; preds = %16
br label %21
21: ; preds = %3, %20
%22 = load i8*, i8** %8
%23 = call i64 @strlen(i8* %22)
store i64 %23, i64* %9
br label %25
24: ; preds = %3
br label %25
25: ; preds = %3, %24, %21
%26 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%27 = call i32 @xdr_u_int(%struct.TYPE_5__* %26, i64* %9)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %25
store i32 0, i32* %4
br label %73
30: ; preds = %25
%31 = load i64, i64* %9
%32 = load i64, i64* %7
%33 = icmp sgt i64 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 0, i32* %4
br label %73
35: ; preds = %30
%36 = load i64, i64* %9
%37 = add nsw i64 %36, 1
store i64 %37, i64* %10
%38 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%39 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %38, i32 0, i32 0
%40 = load i32, i32* %39
switch i32 %40, label %72 [
i32 130, label %41
i32 129, label %63
i32 128, label %68
]
41: ; preds = %35
%42 = load i64, i64* %10
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 1, i32* %4
br label %73
45: ; preds = %41
%46 = load i8*, i8** %8
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %53
48: ; preds = %45
%49 = load i64, i64* %10
%50 = call i64 @calloc(i32 1, i64 %49)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %8
%52 = load i8**, i8*** %6
store i8* %51, i8** %52
br label %53
53: ; preds = %48, %45
%54 = load i8*, i8** %8
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %73
59: ; preds = %53
%60 = load i8*, i8** %8
%61 = load i64, i64* %9
%62 = getelementptr inbounds i8, i8* %60, i64 %61
store i8 0, i8* %62
br label %63
63: ; preds = %35, %59
%64 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%65 = load i8*, i8** %8
%66 = load i64, i64* %9
%67 = call i32 @xdr_opaque(%struct.TYPE_5__* %64, i8* %65, i64 %66)
store i32 %67, i32* %4
br label %73
68: ; preds = %35
%69 = load i8*, i8** %8
%70 = call i32 @free(i8* %69)
%71 = load i8**, i8*** %6
store i8* null, i8** %71
store i32 1, i32* %4
br label %73
72: ; preds = %35
store i32 0, i32* %4
br label %73
73: ; preds = %72, %68, %63, %56, %44, %34, %29, %19
%74 = load i32, i32* %4
ret i32 %74
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32 }
@stderr = 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, i64 %2) {
%4 = alloca i64
%5 = load i8*, i8** %1
%6 = bitcast i64* %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 %13 [
i32 128, label %9
i32 129, label %11
]
9: ; preds = %3
%10 = icmp eq i8* %5, null
br i1 %10, label %46, label %11
11: ; preds = %9, %3
%12 = tail call i64 @strlen(i8* dereferenceable(1) %5)
store i64 %12, i64* %4
br label %13
13: ; preds = %3, %11
%14 = call i32 @xdr_u_int(%struct.TYPE_5__* %0, i64* %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %46, label %16
16: ; preds = %13
%17 = load i64, i64* %4
%18 = icmp sgt i64 %17, %2
br i1 %18, label %46, label %19
19: ; preds = %16
%20 = add nsw i64 %17, 1
%21 = load i32, i32* %7
switch i32 %21, label %46 [
i32 130, label %22
i32 129, label %40
i32 128, label %44
]
22: ; preds = %19
%23 = icmp eq i64 %20, 0
br i1 %23, label %46, label %24
24: ; preds = %22
%25 = icmp eq i8* %5, null
br i1 %25, label %26, label %35
26: ; preds = %24
%27 = call i64 @calloc(i32 1, i64 %20)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %1
%29 = icmp eq i64 %27, 0
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = load i64, i64* %4
br label %35
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %46
35: ; preds = %30, %24
%36 = phi i64 [ %31, %30 ], [ %17, %24 ]
%37 = phi i8* [ %28, %30 ], [ %5, %24 ]
%38 = getelementptr inbounds i8, i8* %37, i64 %36
store i8 0, i8* %38
%39 = load i64, i64* %4
br label %40
40: ; preds = %19, %35
%41 = phi i64 [ %17, %19 ], [ %39, %35 ]
%42 = phi i8* [ %5, %19 ], [ %37, %35 ]
%43 = call i32 @xdr_opaque(%struct.TYPE_5__* %0, i8* %42, i64 %41)
br label %46
44: ; preds = %19
%45 = call i32 @free(i8* %5)
store i8* null, i8** %1
br label %46
46: ; preds = %19, %22, %16, %13, %9, %44, %40, %32
%47 = phi i32 [ 1, %44 ], [ %43, %40 ], [ 0, %32 ], [ 1, %9 ], [ 0, %13 ], [ 0, %16 ], [ 1, %22 ], [ 0, %19 ]
ret i32 %47
}