#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 *, unsigned int);
unsigned int sprintf(char *, char *, ...);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned char _ucRcAT1604_Write(unsigned int Addr, unsigned int Len,
                                unsigned char *DataBuf) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(1024);
  uiDataLen = sprintf(psFunCall, "%u(%u,%u,p%04u", 9410, Addr, Len, Len);
  memcpy(psFunCall + uiDataLen, DataBuf, Len);
  uiDataLen += Len;
  uiDataLen += sprintf(psFunCall + uiDataLen, ")");
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 8);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_AT1604_Write iDoRemoteFunc ret = %d", uiRet);
    return 1;
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_ucRcAT1604_Write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0xc(%rbp),%r9d
lea    0xe5a(%rip),%rsi
mov    $0x24c2,%edx
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0xc(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x8,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x20(%rbp)
je     1231 <_ucRcAT1604_Write+0xc1>
mov    -0x20(%rbp),%esi
lea    0xdee(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movb   $0x1,-0x1(%rbp)
jmp    123b <_ucRcAT1604_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):
<_ucRcAT1604_Write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%ebx
mov    %edi,%ebp
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe6e(%rip),%rsi
mov    %rax,%rdi
mov    $0x24c2,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %eax,%ebp
mov    %eax,%edi
add    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
lea    (%rbx,%rbp,1),%eax
movw   $0x29,(%r14,%rax,1)
lea    (%rbx,%rbp,1),%esi
add    $0x1,%esi
mov    %r14,%rdi
mov    $0x8,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
test   %ebx,%ebx
je     1200 <_ucRcAT1604_Write+0x90>
lea    0xe23(%rip),%rdi
mov    %ebx,%esi
call   1050 <vWriteLogTxt@plt>
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
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(%u,%u,p%04u\00"
@.str.1 = [2 x i8] c")\00"
@.str.2 = [37 x i8] c"_AT1604_Write iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcAT1604_Write(i32 %0, i32 %1, i8* %2) {
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%11 = call i8* @malloc(i32 1024)
store i8* %11, i8** %10
%12 = load i8*, i8** %10
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = load i32, i32* %6
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 9410, i32 %13, i32 %14, 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** %7
%22 = load i32, i32* %6
%23 = call i32 @memcpy(i8* %20, i8* %21, i32 %22)
%24 = load i32, i32* %6
%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 = call i32 (i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%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 8)
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 ([37 x i8], [37 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 = [15 x i8] c"%u(%u,%u,p%04u\00"
@.str.2 = [37 x i8] c"_AT1604_Write iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcAT1604_Write(i32 %0, i32 %1, i8* %2) {
%4 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%5 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 9410, i32 %0, i32 %1, i32 %1)
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %4, i64 %6
%8 = tail call i32 @memcpy(i8* %7, i8* %2, i32 %1)
%9 = add i32 %5, %1
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %4, i64 %10
%12 = bitcast i8* %11 to i16*
store i16 41, i16* %12
%13 = add i32 %9, 1
%14 = tail call i32 @iDoRemoteFunc(i8* %4, i32 %13, i32 8)
%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 ([37 x i8], [37 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
}