#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(char *, int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ psGetParaBuf(int);
unsigned int sprintf(char *, char *, int, unsigned int);
int /*<<< orphan*/ vWriteLogHex(char *, char *, unsigned int);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned int _uiRcSDSCGetSDKVersion(char *pszVersion,
                                    unsigned int *puiVersionLen) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(100);
  uiDataLen = sprintf(psFunCall, "%u(b000, %u)", 5028, *puiVersionLen);
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 1);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_uiRcSDSCGetSDKVersion iDoRemoteFunc ret = %d", uiRet);
    return 99;
  }
  if (iGetParaInt(0) == 0) {
    memcpy(pszVersion, psGetParaBuf(2), iGetParaInt(3));
    pszVersion[iGetParaInt(3)] = 0;
    *puiVersionLen = iGetParaInt(3);
    vWriteLogHex("_uiRcSDSCGetSDKVersion:", pszVersion, *puiVersionLen);
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_uiRcSDSCGetSDKVersion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x64,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
lea    0xe41(%rip),%rsi
mov    $0x13a4,%edx
call   10b0 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   10a0 <iDoRemoteFunc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x20(%rbp)
je     120e <_uiRcSDSCGetSDKVersion+0x7e>
mov    -0x20(%rbp),%esi
lea    0xe10(%rip),%rdi
call   1060 <vWriteLogTxt@plt>
movl   $0x63,-0x4(%rbp)
jmp    129b <_uiRcSDSCGetSDKVersion+0x10b>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
cmp    $0x0,%eax
jne    1291 <_uiRcSDSCGetSDKVersion+0x101>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x2,%edi
call   1050 <psGetParaBuf@plt>
mov    %eax,-0x34(%rbp)
mov    $0x3,%edi
call   1040 <iGetParaInt@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    %eax,%edx
call   1080 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x3,%edi
call   1040 <iGetParaInt@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    $0x3,%edi
call   1040 <iGetParaInt@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xdaf(%rip),%rdi
call   1070 <vWriteLogHex@plt>
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):
<_uiRcSDSCGetSDKVersion>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x64,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    (%r15),%ecx
lea    0xe4c(%rip),%rsi
mov    %rax,%rdi
mov    $0x13a4,%edx
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   10a0 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     11fc <_uiRcSDSCGetSDKVersion+0x6c>
lea    0xe28(%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    1258 <_uiRcSDSCGetSDKVersion+0xc8>
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   1080 <memcpy@plt>
mov    $0x3,%edi
call   1040 <iGetParaInt@plt>
mov    %eax,%eax
movb   $0x0,(%r14,%rax,1)
mov    $0x3,%edi
call   1040 <iGetParaInt@plt>
mov    %eax,(%r15)
lea    0xded(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1070 <vWriteLogHex@plt>
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 = [46 x i8] c"_uiRcSDSCGetSDKVersion iDoRemoteFunc ret = %d\00"
@.str.2 = [24 x i8] c"_uiRcSDSCGetSDKVersion:\00"
define i32 @_uiRcSDSCGetSDKVersion(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 5028, 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 ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %22)
store i32 99, i32* %3
br label %44
24: ; preds = %2
%25 = call i32 @iGetParaInt(i32 0)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %42
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 = load i8*, i8** %4
%33 = call i32 @iGetParaInt(i32 3)
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
%36 = call i32 @iGetParaInt(i32 3)
%37 = load i32*, i32** %5
store i32 %36, i32* %37
%38 = load i8*, i8** %4
%39 = load i32*, i32** %5
%40 = load i32, i32* %39
%41 = call i32 @vWriteLogHex(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %38, i32 %40)
br label %42
42: ; preds = %27, %24
%43 = call i32 @iGetParaInt(i32 0)
store i32 %43, i32* %3
br label %44
44: ; preds = %42, %21
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [13 x i8] c"%u(b000, %u)\00"
@.str.1 = [46 x i8] c"_uiRcSDSCGetSDKVersion iDoRemoteFunc ret = %d\00"
@.str.2 = [24 x i8] c"_uiRcSDSCGetSDKVersion:\00"
define i32 @_uiRcSDSCGetSDKVersion(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 5028, 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 ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %25
11: ; preds = %2
%12 = tail call i32 @iGetParaInt(i32 0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %23
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)
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 0, i8* %20
%21 = tail call i32 @iGetParaInt(i32 3)
store i32 %21, i32* %1
%22 = tail call i32 @vWriteLogHex(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %21)
br label %23
23: ; preds = %14, %11
%24 = tail call i32 @iGetParaInt(i32 0)
br label %25
25: ; preds = %23, %9
%26 = phi i32 [ 99, %9 ], [ %24, %23 ]
ret i32 %26
}