#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 /*<<< orphan*/ free(char *);
unsigned int iDoRemoteFunc(unsigned char *, unsigned int, int);
unsigned char iGetParaInt(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ memcpy(void *, int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ psGetParaBuf(int);
unsigned int sprintf(char *, char *, int, unsigned int, unsigned int);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned char _ucRcXMemRead(void *pBuf, unsigned int uiOffset,
                            unsigned int uiLen) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(100 + uiLen);
  uiDataLen = sprintf(psFunCall, "%u(b000,%u,%u)", 1007, uiOffset, uiLen);
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 2);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_ucRcXMemRead iDoRemoteFunc ret = %d", uiRet);
    return 1;
  }
  if (iGetParaInt(0) == 0)
    memcpy(pBuf, psGetParaBuf(2), uiLen);
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_ucRcXMemRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%edi
add    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe4d(%rip),%rsi
mov    $0x3ef,%edx
call   10a0 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x2,%edx
call   1090 <iDoRemoteFunc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x20(%rbp)
je     11ff <_ucRcXMemRead+0x7f>
mov    -0x20(%rbp),%esi
lea    0xe1e(%rip),%rdi
call   1060 <vWriteLogTxt@plt>
movb   $0x1,-0x1(%rbp)
jmp    123c <_ucRcXMemRead+0xbc>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
movzbl %al,%eax
cmp    $0x0,%eax
jne    1232 <_ucRcXMemRead+0xb2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x2,%edi
call   1050 <psGetParaBuf@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%edx
call   1070 <memcpy@plt>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ucRcXMemRead>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
lea    0x64(%r15),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe5e(%rip),%rsi
mov    %rax,%rdi
mov    $0x3ef,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x2,%edx
call   1090 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     11ec <_ucRcXMemRead+0x6c>
lea    0xe37(%rip),%rdi
mov    %ebp,%esi
call   1060 <vWriteLogTxt@plt>
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
test   %al,%al
jne    120e <_ucRcXMemRead+0x8e>
mov    $0x2,%edi
call   1050 <psGetParaBuf@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %r15d,%edx
call   1070 <memcpy@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <iGetParaInt@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"%u(b000,%u,%u)\00"
@.str.1 = [37 x i8] c"_ucRcXMemRead iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcXMemRead(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i32, i32* %7
%12 = add i32 100, %11
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %10
%14 = load i8*, i8** %10
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 1007, i32 %15, i32 %16)
store i32 %17, i32* %8
%18 = load i8*, i8** %10
%19 = load i32, i32* %8
%20 = call i32 @iDoRemoteFunc(i8* %18, i32 %19, i32 2)
store i32 %20, i32* %9
%21 = load i8*, i8** %10
%22 = call i32 @free(i8* %21)
%23 = load i32, i32* %9
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %3
%26 = load i32, i32* %9
%27 = call i32 @vWriteLogTxt(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %26)
store i8 1, i8* %4
br label %39
28: ; preds = %3
%29 = call zeroext i8 @iGetParaInt(i32 0)
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i8*, i8** %5
%34 = call i32 @psGetParaBuf(i32 2)
%35 = load i32, i32* %7
%36 = call i32 @memcpy(i8* %33, i32 %34, i32 %35)
br label %37
37: ; preds = %32, %28
%38 = call zeroext i8 @iGetParaInt(i32 0)
store i8 %38, i8* %4
br label %39
39: ; preds = %37, %25
%40 = load i8, i8* %4
ret i8 %40
}

LLVM IR (-O2):
@.str = [15 x i8] c"%u(b000,%u,%u)\00"
@.str.1 = [37 x i8] c"_ucRcXMemRead iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcXMemRead(i8* %0, i32 %1, i32 %2) {
%4 = add i32 %2, 100
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 1007, i32 %1, i32 %2)
%7 = tail call i32 @iDoRemoteFunc(i8* %5, i32 %6, i32 2)
%8 = tail call i32 @free(i8* %5)
%9 = icmp eq i32 %7, 0
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = tail call i32 @vWriteLogTxt(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %20
12: ; preds = %3
%13 = tail call zeroext i8 @iGetParaInt(i32 0)
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @psGetParaBuf(i32 2)
%17 = tail call i32 @memcpy(i8* %0, i32 %16, i32 %2)
br label %18
18: ; preds = %15, %12
%19 = tail call zeroext i8 @iGetParaInt(i32 0)
br label %20
20: ; preds = %18, %10
%21 = phi i8 [ 1, %10 ], [ %19, %18 ]
ret i8 %21
}