#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 */

/* Type definitions */

/* Variables and functions */
int TCPIPMsgRecv(int, ...);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(size_t);
char RMsgRcvDecodeOpen(int sock, size_t *size, unsigned char **store) {
  int s;
  size_t buflen = 0;
  unsigned char *bufadr = NULL;
  s = TCPIPMsgRecv(sock, &buflen, sizeof(size_t));
  if (s != sizeof(size_t))
    return 'R';
  bufadr = malloc(buflen + 1);
  if (bufadr == NULL)
    return 'R';
  s = TCPIPMsgRecv(sock, bufadr, buflen);
  if (s != buflen) {
    free(bufadr);
    return 'R';
  }
  *store = bufadr;
  *size = buflen;
  return 0;
}


x86 assembly (clang, -O0):
<RMsgRcvDecodeOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1050 <TCPIPMsgRecv@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x8,%rax
je     1180 <RMsgRcvDecodeOpen+0x50>
movb   $0x52,-0x1(%rbp)
jmp    11f4 <RMsgRcvDecodeOpen+0xc4>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a5 <RMsgRcvDecodeOpen+0x75>
movb   $0x52,-0x1(%rbp)
jmp    11f4 <RMsgRcvDecodeOpen+0xc4>
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1050 <TCPIPMsgRecv@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11da <RMsgRcvDecodeOpen+0xaa>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movb   $0x52,-0x1(%rbp)
jmp    11f4 <RMsgRcvDecodeOpen+0xc4>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RMsgRcvDecodeOpen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebp
movq   $0x0,(%rsp)
mov    %rsp,%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1050 <TCPIPMsgRecv@plt>
mov    $0x52,%r12b
cmp    $0x8,%eax
jne    11a1 <RMsgRcvDecodeOpen+0x71>
mov    (%rsp),%r13
lea    0x1(%r13),%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     11a1 <RMsgRcvDecodeOpen+0x71>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <TCPIPMsgRecv@plt>
cltq
cmp    %rax,(%rsp)
jne    1199 <RMsgRcvDecodeOpen+0x69>
mov    %rbx,(%r15)
mov    %rax,(%r14)
xor    %r12d,%r12d
jmp    11a1 <RMsgRcvDecodeOpen+0x71>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @RMsgRcvDecodeOpen(i32 %0, i64* %1, i8** %2) {
%4 = alloca i8
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
store i32 %0, i32* %5
store i64* %1, i64** %6
store i8** %2, i8*** %7
store i64 0, i64* %9
store i8* null, i8** %10
%11 = load i32, i32* %5
%12 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %11, i64* %9, i64 8)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = sext i32 %13 to i64
%15 = icmp ne i64 %14, 8
br i1 %15, label %16, label %17
16: ; preds = %3
store i8 82, i8* %4
br label %41
17: ; preds = %3
%18 = load i64, i64* %9
%19 = add i64 %18, 1
%20 = call i8* @malloc(i64 %19)
store i8* %20, i8** %10
%21 = load i8*, i8** %10
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %17
store i8 82, i8* %4
br label %41
24: ; preds = %17
%25 = load i32, i32* %5
%26 = load i8*, i8** %10
%27 = load i64, i64* %9
%28 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %25, i8* %26, i64 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = load i64, i64* %9
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = load i8*, i8** %10
%35 = call i32 @free(i8* %34)
store i8 82, i8* %4
br label %41
36: ; preds = %24
%37 = load i8*, i8** %10
%38 = load i8**, i8*** %7
store i8* %37, i8** %38
%39 = load i64, i64* %9
%40 = load i64*, i64** %6
store i64 %39, i64* %40
store i8 0, i8* %4
br label %41
41: ; preds = %36, %33, %23, %16
%42 = load i8, i8* %4
ret i8 %42
}

LLVM IR (-O2):
define signext i8 @RMsgRcvDecodeOpen(i32 %0, i64* nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%6 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %0, i64* %4, i64 8)
%7 = icmp eq i32 %6, 8
br i1 %7, label %8, label %21
8: ; preds = %3
%9 = load i64, i64* %4
%10 = add i64 %9, 1
%11 = call i8* @malloc(i64 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %21, label %13
13: ; preds = %8
%14 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %0, i8* %11, i64 %9)
%15 = sext i32 %14 to i64
%16 = load i64, i64* %4
%17 = icmp eq i64 %16, %15
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = call i32 @free(i8* %11)
br label %21
20: ; preds = %13
store i8* %11, i8** %2
store i64 %15, i64* %1
br label %21
21: ; preds = %8, %3, %20, %18
%22 = phi i8 [ 82, %18 ], [ 0, %20 ], [ 82, %3 ], [ 82, %8 ]
ret i8 %22
}