#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 char);
unsigned int sprintf(char *, char *, ...);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned char _ucRcAT102_WriteWords(unsigned char ucWordAddr,
                                    unsigned char ucWordNum,
                                    unsigned char *psDataBuf) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(512);
  uiDataLen = sprintf(psFunCall, "%u(%u,%u,b%03u", 9109, ucWordAddr, ucWordNum,
                      ucWordNum * 2);
  memcpy(psFunCall + uiDataLen, psDataBuf, ucWordNum * 2);
  uiDataLen += ucWordNum * 2;
  uiDataLen += sprintf(psFunCall + uiDataLen, ")");
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 5);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_AT102_WriteWords iDoRemoteFunc ret = %d", uiRet);
    return 1;
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_ucRcAT102_WriteWords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
mov    %rdx,-0x10(%rbp)
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movzbl -0x2(%rbp),%ecx
movzbl -0x3(%rbp),%r8d
movzbl -0x3(%rbp),%r9d
shl    $0x1,%r9d
lea    0xe4d(%rip),%rsi
mov    $0x2395,%edx
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movzbl -0x3(%rbp),%eax
shl    $0x1,%eax
movzbl %al,%edx
call   1060 <memcpy@plt>
movzbl -0x3(%rbp),%eax
shl    $0x1,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x5,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x18(%rbp)
je     1249 <_ucRcAT102_WriteWords+0xd9>
mov    -0x18(%rbp),%esi
lea    0xdd6(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movb   $0x1,-0x1(%rbp)
jmp    1253 <_ucRcAT102_WriteWords+0xe3>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ucRcAT102_WriteWords>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%r14d
mov    %edi,%r12d
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    (%r14,%r14,1),%r13d
lea    0xe64(%rip),%rsi
mov    %rax,%rdi
mov    $0x2395,%edx
mov    %r12d,%ecx
mov    %r14d,%r8d
mov    %r13d,%r9d
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %eax,%ebp
mov    %eax,%edi
add    %rbx,%rdi
movzbl %r13b,%edx
mov    %r15,%rsi
call   1060 <memcpy@plt>
lea    0x0(%rbp,%r14,2),%eax
movw   $0x29,(%rbx,%rax,1)
lea    0x1(%rbp,%r14,2),%esi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     1211 <_ucRcAT102_WriteWords+0xa1>
lea    0xe16(%rip),%rdi
mov    %ebp,%esi
call   1050 <vWriteLogTxt@plt>
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <iGetParaInt@plt>

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

LLVM IR (-O2):
@.str = [15 x i8] c"%u(%u,%u,b%03u\00"
@.str.2 = [41 x i8] c"_AT102_WriteWords iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcAT102_WriteWords(i8 zeroext %0, i8 zeroext %1, i8* %2) {
%4 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%5 = zext i8 %0 to i32
%6 = zext i8 %1 to i32
%7 = shl nuw nsw i32 %6, 1
%8 = 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 9109, i32 %5, i32 %6, i32 %7)
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %4, i64 %9
%11 = trunc i32 %7 to i8
%12 = tail call i32 @memcpy(i8* %10, i8* %2, i8 zeroext %11)
%13 = add i32 %8, %7
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %4, i64 %14
%16 = bitcast i8* %15 to i16*
store i16 41, i16* %16
%17 = add i32 %13, 1
%18 = tail call i32 @iDoRemoteFunc(i8* %4, i32 %17, i32 5)
%19 = tail call i32 @free(i8* %4)
%20 = icmp eq i32 %18, 0
br i1 %20, label %23, label %21
21: ; preds = %3
%22 = tail call i32 @vWriteLogTxt(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %25
23: ; preds = %3
%24 = tail call zeroext i8 @iGetParaInt(i32 0)
br label %25
25: ; preds = %23, %21
%26 = phi i8 [ 1, %21 ], [ %24, %23 ]
ret i8 %26
}