#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_WriteAZ(unsigned char Area, unsigned int Addr,
                                  unsigned int Len, unsigned char *DataBuf) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(1024);
  uiDataLen =
      sprintf(psFunCall, "%u(%u,%u,%u,b%03u", 9411, Area, Addr, Len, Len);
  memcpy(psFunCall + uiDataLen, DataBuf, Len);
  uiDataLen += Len;
  uiDataLen += sprintf(psFunCall + uiDataLen, ")");
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 5);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_AT1604_WriteAZ iDoRemoteFunc ret = %d", uiRet);
    return 1;
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_ucRcAT1604_WriteAZ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movzbl -0x2(%rbp),%ecx
mov    -0x8(%rbp),%r8d
mov    -0xc(%rbp),%r9d
mov    -0xc(%rbp),%eax
lea    0xe50(%rip),%rsi
mov    $0x24c3,%edx
mov    %eax,(%rsp)
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    0xe20(%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    $0x5,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x20(%rbp)
je     123e <_ucRcAT1604_WriteAZ+0xce>
mov    -0x20(%rbp),%esi
lea    0xde4(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movb   $0x1,-0x1(%rbp)
jmp    1248 <_ucRcAT1604_WriteAZ+0xd8>
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_WriteAZ>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r15
mov    %edx,%ebx
mov    %esi,%r12d
mov    %edi,%ebp
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %ebx,(%rsp)
lea    0xe63(%rip),%rsi
mov    %rax,%rdi
mov    $0x24c3,%edx
mov    %ebp,%ecx
mov    %r12d,%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    $0x5,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
test   %ebx,%ebx
je     120d <_ucRcAT1604_WriteAZ+0x9d>
lea    0xe1b(%rip),%rdi
mov    %ebx,%esi
call   1050 <vWriteLogTxt@plt>
mov    $0x1,%al
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <iGetParaInt@plt>

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

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