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


x86 assembly (clang, -O0):
<_ucRcXMemWriteReserved>:
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   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%ecx
lea    0xe61(%rip),%rsi
mov    $0x401,%edx
call   1090 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe27(%rip),%rsi
call   1090 <sprintf@plt>
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x2,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x20(%rbp)
je     122c <_ucRcXMemWriteReserved+0xbc>
mov    -0x20(%rbp),%esi
lea    0xdf3(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movb   $0x1,-0x1(%rbp)
jmp    1236 <_ucRcXMemWriteReserved+0xc6>
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):
<_ucRcXMemWriteReserved>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %esi,%r15d
mov    %rdi,%r12
lea    0x64(%rbx),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe6e(%rip),%rsi
mov    %rax,%rdi
mov    $0x401,%edx
mov    %ebx,%ecx
call   1090 <sprintf@plt>
mov    %eax,%ebp
mov    %eax,%edi
add    %r14,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
add    %ebx,%ebp
lea    (%r14,%rbp,1),%rdi
lea    0xe4a(%rip),%rsi
mov    %r15d,%edx
mov    %ebx,%ecx
call   1090 <sprintf@plt>
add    %eax,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x2,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
test   %ebx,%ebx
je     1201 <_ucRcXMemWriteReserved+0x91>
lea    0xe22(%rip),%rdi
mov    %ebx,%esi
call   1050 <vWriteLogTxt@plt>
mov    $0x1,%al
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <iGetParaInt@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%u(b%03u\00"
@.str.1 = [8 x i8] c",%u,%u)\00"
@.str.2 = [46 x i8] c"_ucRcXMemWriteReserved iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcXMemWriteReserved(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* %7
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 1025, i32 %15)
store i32 %16, i32* %8
%17 = load i8*, i8** %10
%18 = load i32, i32* %8
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8*, i8** %5
%22 = load i32, i32* %7
%23 = call i32 @memcpy(i8* %20, i8* %21, i32 %22)
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = add i32 %25, %24
store i32 %26, i32* %8
%27 = load i8*, i8** %10
%28 = load i32, i32* %8
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %32)
%34 = load i32, i32* %8
%35 = add i32 %34, %33
store i32 %35, i32* %8
%36 = load i8*, i8** %10
%37 = load i32, i32* %8
%38 = call i32 @iDoRemoteFunc(i8* %36, i32 %37, i32 2)
store i32 %38, i32* %9
%39 = load i8*, i8** %10
%40 = call i32 @free(i8* %39)
%41 = load i32, i32* %9
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %3
%44 = load i32, i32* %9
%45 = call i32 @vWriteLogTxt(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %44)
store i8 1, i8* %4
br label %48
46: ; preds = %3
%47 = call zeroext i8 @iGetParaInt(i32 0)
store i8 %47, i8* %4
br label %48
48: ; preds = %46, %43
%49 = load i8, i8* %4
ret i8 %49
}

LLVM IR (-O2):
@.str = [9 x i8] c"%u(b%03u\00"
@.str.1 = [8 x i8] c",%u,%u)\00"
@.str.2 = [46 x i8] c"_ucRcXMemWriteReserved iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcXMemWriteReserved(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 ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 1025, i32 %2)
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
%9 = tail call i32 @memcpy(i8* %8, i8* %0, i32 %2)
%10 = add i32 %6, %2
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %5, i64 %11
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %2)
%14 = add i32 %13, %10
%15 = tail call i32 @iDoRemoteFunc(i8* %5, i32 %14, i32 2)
%16 = tail call i32 @free(i8* %5)
%17 = icmp eq i32 %15, 0
br i1 %17, label %20, label %18
18: ; preds = %3
%19 = tail call i32 @vWriteLogTxt(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %22
20: ; preds = %3
%21 = tail call zeroext i8 @iGetParaInt(i32 0)
br label %22
22: ; preds = %20, %18
%23 = phi i8 [ 1, %18 ], [ %21, %20 ]
ret i8 %23
}