#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);
char *malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/, unsigned char);
int /*<<< orphan*/ psGetParaBuf(int);
unsigned int sprintf(char *, char *, int, unsigned char, unsigned char);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
void _vRcAT102_ReadWords(unsigned char ucWordAddr, unsigned char ucWordNum,
                         unsigned char *psDataBuf) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(50);
  uiDataLen = sprintf(psFunCall, "%u(%u,%u,b000)", 9106, ucWordAddr, ucWordNum);
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 2);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_AT102_ReadWords iDoRemoteFunc ret = %d", uiRet);
    return;
  }
  memcpy(psDataBuf, psGetParaBuf(4), ucWordNum * 2);
}


x86 assembly (clang, -O0):
<_vRcAT102_ReadWords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
mov    %rdx,-0x10(%rbp)
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x1(%rbp),%al
lea    0xe5c(%rip),%rsi
mov    $0x2392,%edx
movzbl %al,%ecx
movzbl -0x2(%rbp),%r8d
call   1090 <sprintf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x2,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x18(%rbp)
je     11f4 <_vRcAT102_ReadWords+0x84>
mov    -0x18(%rbp),%esi
lea    0xe25(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
jmp    121b <_vRcAT102_ReadWords+0xab>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x4,%edi
call   1040 <psGetParaBuf@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
movzbl -0x2(%rbp),%eax
shl    $0x1,%eax
movzbl %al,%edx
call   1060 <memcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_vRcAT102_ReadWords>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebx
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
lea    0xe6d(%rip),%rsi
mov    %rax,%rdi
mov    $0x2392,%edx
mov    %ebx,%ecx
mov    %r15d,%r8d
call   1090 <sprintf@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    $0x2,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
test   %ebx,%ebx
je     11da <_vRcAT102_ReadWords+0x6a>
lea    0xe46(%rip),%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <vWriteLogTxt@plt>
mov    $0x4,%edi
call   1040 <psGetParaBuf@plt>
add    %r15b,%r15b
movzbl %r15b,%edx
mov    %r14,%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <memcpy@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"%u(%u,%u,b000)\00"
@.str.1 = [40 x i8] c"_AT102_ReadWords iDoRemoteFunc ret = %d\00"
define void @_vRcAT102_ReadWords(i8 zeroext %0, i8 zeroext %1, i8* %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8 %0, i8* %4
store i8 %1, i8* %5
store i8* %2, i8** %6
%10 = call i8* @malloc(i32 50)
store i8* %10, i8** %9
%11 = load i8*, i8** %9
%12 = load i8, i8* %4
%13 = load i8, i8* %5
%14 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 9106, i8 zeroext %12, i8 zeroext %13)
store i32 %14, i32* %7
%15 = load i8*, i8** %9
%16 = load i32, i32* %7
%17 = call i32 @iDoRemoteFunc(i8* %15, i32 %16, i32 2)
store i32 %17, i32* %8
%18 = load i8*, i8** %9
%19 = call i32 @free(i8* %18)
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %3
%23 = load i32, i32* %8
%24 = call i32 @vWriteLogTxt(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %33
25: ; preds = %3
%26 = load i8*, i8** %6
%27 = call i32 @psGetParaBuf(i32 4)
%28 = load i8, i8* %5
%29 = zext i8 %28 to i32
%30 = mul nsw i32 %29, 2
%31 = trunc i32 %30 to i8
%32 = call i32 @memcpy(i8* %26, i32 %27, i8 zeroext %31)
br label %33
33: ; preds = %25, %22
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"%u(%u,%u,b000)\00"
@.str.1 = [40 x i8] c"_AT102_ReadWords iDoRemoteFunc ret = %d\00"
define void @_vRcAT102_ReadWords(i8 zeroext %0, i8 zeroext %1, i8* %2) {
%4 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 9106, i8 zeroext %0, i8 zeroext %1)
%6 = tail call i32 @iDoRemoteFunc(i8* %4, i32 %5, i32 2)
%7 = tail call i32 @free(i8* %4)
%8 = icmp eq i32 %6, 0
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i32 @vWriteLogTxt(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %15
11: ; preds = %3
%12 = tail call i32 @psGetParaBuf(i32 4)
%13 = shl i8 %1, 1
%14 = tail call i32 @memcpy(i8* %2, i32 %12, i8 zeroext %13)
br label %15
15: ; preds = %11, %9
ret void
}