#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);
char *malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ psGetParaBuf(int);
unsigned int sprintf(char *, char *, int, unsigned int);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned int _uiRcSDSCGetFirmwareVer(unsigned char *psFirmwareVer,
                                     unsigned int *puiFirmwareVerLen) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(100);
  uiDataLen = sprintf(psFunCall, "%u(b000, %u)", 5023, *puiFirmwareVerLen);
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 1);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_uiRcSDSCGetFirmwareVer iDoRemoteFunc ret = %d", uiRet);
    return 99;
  }
  if (iGetParaInt(0) == 0) {
    memcpy(psFirmwareVer, psGetParaBuf(2), iGetParaInt(3));
    *puiFirmwareVerLen = iGetParaInt(3);
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_uiRcSDSCGetFirmwareVer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
lea    0xe51(%rip),%rsi
mov    $0x139f,%edx
call   10a0 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1090 <iDoRemoteFunc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x20(%rbp)
je     11fe <_uiRcSDSCGetFirmwareVer+0x7e>
mov    -0x20(%rbp),%esi
lea    0xe20(%rip),%rdi
call   1060 <vWriteLogTxt@plt>
movl   $0x63,-0x4(%rbp)
jmp    1257 <_uiRcSDSCGetFirmwareVer+0xd7>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
cmp    $0x0,%eax
jne    124d <_uiRcSDSCGetFirmwareVer+0xcd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x2,%edi
call   1050 <psGetParaBuf@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x3,%edi
call   1040 <iGetParaInt@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    $0x3,%edi
call   1040 <iGetParaInt@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_uiRcSDSCGetFirmwareVer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    (%r15),%ecx
lea    0xe5c(%rip),%rsi
mov    %rax,%rdi
mov    $0x139f,%edx
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1090 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     11ec <_uiRcSDSCGetFirmwareVer+0x6c>
lea    0xe38(%rip),%rdi
mov    %ebp,%esi
call   1060 <vWriteLogTxt@plt>
mov    $0x63,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
test   %eax,%eax
jne    1226 <_uiRcSDSCGetFirmwareVer+0xa6>
mov    $0x2,%edi
call   1050 <psGetParaBuf@plt>
mov    %eax,%ebx
mov    $0x3,%edi
call   1040 <iGetParaInt@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    $0x3,%edi
call   1040 <iGetParaInt@plt>
mov    %eax,(%r15)
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <iGetParaInt@plt>

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

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