#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 _ucRcAT102_EraseAppEx(unsigned char ucArea,
                                    unsigned char ucLimited,
                                    unsigned char *psEraseKey) {
  unsigned int uiDataLen, uiRet, iKeyLen;
  char *psFunCall = malloc(512);
  if (psEraseKey == NULL)
    uiDataLen = sprintf(psFunCall, "%u(%u,%u)", 9108, ucArea, ucLimited);
  else {
    uiDataLen = sprintf(psFunCall, "%u(%u,%u,b008", 9129, ucArea, ucLimited);
    memcpy(psFunCall + uiDataLen, psEraseKey, 8);
    uiDataLen += 8;
    uiDataLen += sprintf(psFunCall + uiDataLen, ")");
  }
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 2);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_AT102_EraseAppEx iDoRemoteFunc ret = %d", uiRet);
    return 1;
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_ucRcAT102_EraseAppEx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
mov    %rdx,-0x10(%rbp)
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c9 <_ucRcAT102_EraseAppEx+0x59>
mov    -0x28(%rbp),%rdi
movzbl -0x2(%rbp),%ecx
movzbl -0x3(%rbp),%r8d
lea    0xe4b(%rip),%rsi
mov    $0x2394,%edx
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    122b <_ucRcAT102_EraseAppEx+0xbb>
mov    -0x28(%rbp),%rdi
movzbl -0x2(%rbp),%ecx
movzbl -0x3(%rbp),%r8d
lea    0xe2d(%rip),%rsi
mov    $0x23a9,%edx
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%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    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x2,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x18(%rbp)
je     126a <_ucRcAT102_EraseAppEx+0xfa>
mov    -0x18(%rbp),%esi
lea    0xdbc(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movb   $0x1,-0x1(%rbp)
jmp    1274 <_ucRcAT102_EraseAppEx+0x104>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ucRcAT102_EraseAppEx>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebp
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %r14,%r14
je     11d1 <_ucRcAT102_EraseAppEx+0x61>
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
mov    $0x23a9,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %eax,%ebp
mov    %eax,%eax
mov    %rbx,%rdi
add    %rax,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1060 <memcpy@plt>
lea    0x8(%rbp),%eax
movw   $0x29,(%rbx,%rax,1)
add    $0x9,%ebp
jmp    11ee <_ucRcAT102_EraseAppEx+0x7e>
lea    0xe28(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2394,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %eax,%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     1226 <_ucRcAT102_EraseAppEx+0xb6>
lea    0xe06(%rip),%rdi
mov    %ebp,%esi
call   1050 <vWriteLogTxt@plt>
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <iGetParaInt@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"%u(%u,%u)\00"
@.str.1 = [14 x i8] c"%u(%u,%u,b008\00"
@.str.2 = [2 x i8] c")\00"
@.str.3 = [41 x i8] c"_AT102_EraseAppEx iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcAT102_EraseAppEx(i8 zeroext %0, i8 zeroext %1, i8* %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8 %0, i8* %5
store i8 %1, i8* %6
store i8* %2, i8** %7
%12 = call i8* @malloc(i32 512)
store i8* %12, i8** %11
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %22
15: ; preds = %3
%16 = load i8*, i8** %11
%17 = load i8, i8* %5
%18 = zext i8 %17 to i32
%19 = load i8, i8* %6
%20 = zext i8 %19 to i32
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9108, i32 %18, i32 %20)
store i32 %21, i32* %8
br label %44
22: ; preds = %3
%23 = load i8*, i8** %11
%24 = load i8, i8* %5
%25 = zext i8 %24 to i32
%26 = load i8, i8* %6
%27 = zext i8 %26 to i32
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 9129, i32 %25, i32 %27)
store i32 %28, i32* %8
%29 = load i8*, i8** %11
%30 = load i32, i32* %8
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8*, i8** %7
%34 = call i32 @memcpy(i8* %32, i8* %33, i32 8)
%35 = load i32, i32* %8
%36 = add i32 %35, 8
store i32 %36, i32* %8
%37 = load i8*, i8** %11
%38 = load i32, i32* %8
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* %8
%43 = add i32 %42, %41
store i32 %43, i32* %8
br label %44
44: ; preds = %22, %15
%45 = load i8*, i8** %11
%46 = load i32, i32* %8
%47 = call i32 @iDoRemoteFunc(i8* %45, i32 %46, i32 2)
store i32 %47, i32* %9
%48 = load i8*, i8** %11
%49 = call i32 @free(i8* %48)
%50 = load i32, i32* %9
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %44
%53 = load i32, i32* %9
%54 = call i32 @vWriteLogTxt(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %53)
store i8 1, i8* %4
br label %57
55: ; preds = %44
%56 = call zeroext i8 @iGetParaInt(i32 0)
store i8 %56, i8* %4
br label %57
57: ; preds = %55, %52
%58 = load i8, i8* %4
ret i8 %58
}

LLVM IR (-O2):
@.str = [10 x i8] c"%u(%u,%u)\00"
@.str.1 = [14 x i8] c"%u(%u,%u,b008\00"
@.str.3 = [41 x i8] c"_AT102_EraseAppEx iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcAT102_EraseAppEx(i8 zeroext %0, i8 zeroext %1, i8* %2) {
%4 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%5 = icmp eq i8* %2, null
%6 = zext i8 %0 to i32
%7 = zext i8 %1 to i32
br i1 %5, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9108, i32 %6, i32 %7)
br label %20
10: ; preds = %3
%11 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 9129, i32 %6, i32 %7)
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %4, i64 %12
%14 = tail call i32 @memcpy(i8* %13, i8* %2, i32 8)
%15 = add i32 %11, 8
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %4, i64 %16
%18 = bitcast i8* %17 to i16*
store i16 41, i16* %18
%19 = add i32 %11, 9
br label %20
20: ; preds = %10, %8
%21 = phi i32 [ %9, %8 ], [ %19, %10 ]
%22 = tail call i32 @iDoRemoteFunc(i8* %4, i32 %21, i32 2)
%23 = tail call i32 @free(i8* %4)
%24 = icmp eq i32 %22, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = tail call i32 @vWriteLogTxt(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %29
27: ; preds = %20
%28 = tail call zeroext i8 @iGetParaInt(i32 0)
br label %29
29: ; preds = %27, %25
%30 = phi i8 [ 1, %25 ], [ %28, %27 ]
ret i8 %30
}