#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 int iGetParaInt(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ psGetParaBuf(int);
unsigned int sprintf(char *, char *, int, unsigned char, unsigned char,
                     unsigned int);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned char _ucRcAT1608_Read(unsigned char Level, unsigned char Addr,
                               unsigned int Len, unsigned char *DataBuf) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(100);
  uiDataLen = sprintf(psFunCall, "%u(%u,%u,%u,b000)", 9504, Level, Addr, Len);
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 5);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_AT1608_Read iDoRemoteFunc ret = %d", uiRet);
    return 1;
  }
  uiRet = iGetParaInt(0);
  if (uiRet == 0)
    memcpy(DataBuf, psGetParaBuf(5), Len);
  return uiRet;
}


x86 assembly (clang, -O0):
<_ucRcAT1608_Read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %dil,%sil
mov    %sil,-0x2(%rbp)
mov    %al,-0x3(%rbp)
mov    %edx,-0x8(%rbp)
mov    %rcx,-0x10(%rbp)
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x2(%rbp),%cl
mov    -0x3(%rbp),%al
mov    -0x8(%rbp),%r9d
lea    0xe41(%rip),%rsi
mov    $0x2520,%edx
movzbl %cl,%ecx
movzbl %al,%r8d
call   10a0 <sprintf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x5,%edx
call   1090 <iDoRemoteFunc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x18(%rbp)
je     1212 <_ucRcAT1608_Read+0x92>
mov    -0x18(%rbp),%esi
lea    0xe0e(%rip),%rdi
call   1060 <vWriteLogTxt@plt>
movb   $0x1,-0x1(%rbp)
jmp    124c <_ucRcAT1608_Read+0xcc>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1246 <_ucRcAT1608_Read+0xc6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x5,%edi
call   1050 <psGetParaBuf@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
mov    -0x8(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%eax
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ucRcAT1608_Read>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%r12d
mov    %edi,%ebp
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe59(%rip),%rsi
mov    %rax,%rdi
mov    $0x2520,%edx
mov    %ebp,%ecx
mov    %r12d,%r8d
mov    %r15d,%r9d
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x5,%edx
call   1090 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     11ec <_ucRcAT1608_Read+0x6c>
lea    0xe32(%rip),%rdi
mov    %ebp,%esi
call   1060 <vWriteLogTxt@plt>
mov    $0x1,%bpl
jmp    1210 <_ucRcAT1608_Read+0x90>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1210 <_ucRcAT1608_Read+0x90>
mov    $0x5,%edi
call   1050 <psGetParaBuf@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %r15d,%edx
call   1070 <memcpy@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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