#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 *, int);
unsigned int sprintf(char *, char *, ...);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned char _ucRcSLE4442_ChkCodeEx(unsigned char *sSecurityCode) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(50);
  uiDataLen = sprintf(psFunCall, "%u(b008", 9208);
  memcpy(psFunCall + uiDataLen, sSecurityCode, 8);
  uiDataLen += 8;
  uiDataLen += sprintf(psFunCall + uiDataLen, ")");
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 2);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_SLE4442_ChkCodeEx iDoRemoteFunc ret = %d", uiRet);
    return 1;
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_ucRcSLE4442_ChkCodeEx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe6b(%rip),%rsi
mov    $0x23f8,%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
mov    $0x8,%edx
call   1060 <memcpy@plt>
mov    -0x14(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
lea    0xe32(%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    $0x2,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x18(%rbp)
je     1222 <_ucRcSLE4442_ChkCodeEx+0xb2>
mov    -0x18(%rbp),%esi
lea    0xdf6(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movb   $0x1,-0x1(%rbp)
jmp    122c <_ucRcSLE4442_ChkCodeEx+0xbc>
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):
<_ucRcSLE4442_ChkCodeEx>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe75(%rip),%rsi
mov    %rax,%rdi
mov    $0x23f8,%edx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %eax,%ebp
mov    %eax,%edi
add    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1060 <memcpy@plt>
lea    0x8(%rbp),%eax
movw   $0x29,(%rbx,%rax,1)
add    $0x9,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x2,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     11ec <_ucRcSLE4442_ChkCodeEx+0x7c>
lea    0xe2a(%rip),%rdi
mov    %ebp,%esi
call   1050 <vWriteLogTxt@plt>
mov    $0x1,%al
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %edi,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <iGetParaInt@plt>

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

LLVM IR (-O2):
@.str = [8 x i8] c"%u(b008\00"
@.str.2 = [42 x i8] c"_SLE4442_ChkCodeEx iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcSLE4442_ChkCodeEx(i8* %0) {
%2 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%3 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 9208)
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %2, i64 %4
%6 = tail call i32 @memcpy(i8* %5, i8* %0, i32 8)
%7 = add i32 %3, 8
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %2, i64 %8
%10 = bitcast i8* %9 to i16*
store i16 41, i16* %10
%11 = add i32 %3, 9
%12 = tail call i32 @iDoRemoteFunc(i8* %2, i32 %11, i32 2)
%13 = tail call i32 @free(i8* %2)
%14 = icmp eq i32 %12, 0
br i1 %14, label %17, label %15
15: ; preds = %1
%16 = tail call i32 @vWriteLogTxt(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %19
17: ; preds = %1
%18 = tail call zeroext i8 @iGetParaInt(i32 0)
br label %19
19: ; preds = %17, %15
%20 = phi i8 [ 1, %15 ], [ %18, %17 ]
ret i8 %20
}