#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 *, unsigned char *, int);
unsigned int sprintf(char *, char *, unsigned char, int);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned char _ucRcAT24Cxx_Write(unsigned char *DataBuff, unsigned char Addr,
                                 int DataLen) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(512);
  uiDataLen = sprintf(psFunCall, "%u(b%03u", 9704, DataLen);
  memcpy(psFunCall + uiDataLen, DataBuff, DataLen);
  uiDataLen += DataLen;
  uiDataLen += sprintf(psFunCall + uiDataLen, ",%u,%u)", Addr, DataLen);
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 10);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_AT24Cxx_Write iDoRemoteFunc ret = %d", uiRet);
    return 1;
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_ucRcAT24Cxx_Write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%ecx
lea    0xe5f(%rip),%rsi
mov    $0xe8,%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    -0x11(%rbp),%al
mov    -0x18(%rbp),%ecx
lea    0xe25(%rip),%rsi
movzbl %al,%edx
call   1090 <sprintf@plt>
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0xa,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x20(%rbp)
je     1231 <_ucRcAT24Cxx_Write+0xc1>
mov    -0x20(%rbp),%esi
lea    0xdee(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movb   $0x1,-0x1(%rbp)
jmp    123b <_ucRcAT24Cxx_Write+0xcb>
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):
<_ucRcAT24Cxx_Write>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %esi,%r14d
mov    %rdi,%r15
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe6b(%rip),%rsi
mov    %rax,%rdi
mov    $0xe8,%edx
mov    %r12d,%ecx
call   1090 <sprintf@plt>
mov    %eax,%ebp
mov    %eax,%edi
add    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1060 <memcpy@plt>
add    %r12d,%ebp
lea    (%rbx,%rbp,1),%rdi
lea    0xe44(%rip),%rsi
mov    %r14d,%edx
mov    %r12d,%ecx
call   1090 <sprintf@plt>
add    %eax,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0xa,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     1208 <_ucRcAT24Cxx_Write+0x98>
lea    0xe1b(%rip),%rdi
mov    %ebp,%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 = [38 x i8] c"_AT24Cxx_Write iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcAT24Cxx_Write(i8* %0, i8 zeroext %1, i32 %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i8 %1, i8* %6
store i32 %2, i32* %7
%11 = call i8* @malloc(i32 512)
store i8* %11, i8** %10
%12 = load i8*, i8** %10
%13 = load i32, i32* %7
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 zeroext -24, i32 %13)
store i32 %14, i32* %8
%15 = load i8*, i8** %10
%16 = load i32, i32* %8
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8*, i8** %5
%20 = load i32, i32* %7
%21 = call i32 @memcpy(i8* %18, i8* %19, i32 %20)
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = add i32 %23, %22
store i32 %24, i32* %8
%25 = load i8*, i8** %10
%26 = load i32, i32* %8
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %6
%30 = load i32, i32* %7
%31 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %29, i32 %30)
%32 = load i32, i32* %8
%33 = add i32 %32, %31
store i32 %33, i32* %8
%34 = load i8*, i8** %10
%35 = load i32, i32* %8
%36 = call i32 @iDoRemoteFunc(i8* %34, i32 %35, i32 10)
store i32 %36, i32* %9
%37 = load i8*, i8** %10
%38 = call i32 @free(i8* %37)
%39 = load i32, i32* %9
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %3
%42 = load i32, i32* %9
%43 = call i32 @vWriteLogTxt(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %42)
store i8 1, i8* %4
br label %46
44: ; preds = %3
%45 = call zeroext i8 @iGetParaInt(i32 0)
store i8 %45, i8* %4
br label %46
46: ; preds = %44, %41
%47 = load i8, i8* %4
ret i8 %47
}

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