#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 *, unsigned int);
unsigned int sprintf(char *, char *, ...);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned char _ucRcAT102_EraseApp(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 {
    iKeyLen = 6;
    if (ucArea == 2)
      iKeyLen = 4;
    uiDataLen =
        sprintf(psFunCall, "%u(%u,%u,b%03u", 9108, ucArea, ucLimited, iKeyLen);
    memcpy(psFunCall + uiDataLen, psEraseKey, iKeyLen);
    uiDataLen += iKeyLen;
    uiDataLen += sprintf(psFunCall + uiDataLen, ")");
  }
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 1);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_AT102_EraseApp iDoRemoteFunc ret = %d", uiRet);
    return 1;
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_ucRcAT102_EraseApp>:
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_EraseApp+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    1248 <_ucRcAT102_EraseApp+0xd8>
movl   $0x6,-0x1c(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0x2,%eax
jne    11e4 <_ucRcAT102_EraseApp+0x74>
movl   $0x4,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
movzbl -0x2(%rbp),%ecx
movzbl -0x3(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
lea    0xe0e(%rip),%rsi
mov    $0x2394,%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    -0x1c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
lea    0xdcd(%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    $0x1,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x18(%rbp)
je     1287 <_ucRcAT102_EraseApp+0x117>
mov    -0x18(%rbp),%esi
lea    0xda0(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movb   $0x1,-0x1(%rbp)
jmp    1291 <_ucRcAT102_EraseApp+0x121>
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_EraseApp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%r15d
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
test   %r14,%r14
je     11ed <_ucRcAT102_EraseApp+0x7d>
xor    %ebx,%ebx
cmp    $0x2,%r15b
setne  %bl
lea    (%rbx,%rbx,1),%r12d
add    $0x4,%r12d
movzbl %bpl,%r8d
lea    0xe59(%rip),%rsi
mov    %r13,%rdi
mov    $0x2394,%edx
mov    %r15d,%ecx
mov    %r12d,%r9d
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %eax,%ebp
mov    %eax,%eax
mov    %r13,%rdi
add    %rax,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1060 <memcpy@plt>
lea    0x4(%rbp,%rbx,2),%eax
movw   $0x29,0x0(%r13,%rax,1)
lea    0x5(%rbp,%rbx,2),%esi
jmp    120c <_ucRcAT102_EraseApp+0x9c>
movzbl %bpl,%r8d
lea    0xe08(%rip),%rsi
mov    %r13,%rdi
mov    $0x2394,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %eax,%esi
mov    %r13,%rdi
mov    $0x1,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     1246 <_ucRcAT102_EraseApp+0xd6>
lea    0xdeb(%rip),%rdi
mov    %ebp,%esi
call   1050 <vWriteLogTxt@plt>
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <iGetParaInt@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"%u(%u,%u)\00"
@.str.1 = [15 x i8] c"%u(%u,%u,b%03u\00"
@.str.2 = [2 x i8] c")\00"
@.str.3 = [39 x i8] c"_AT102_EraseApp iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcAT102_EraseApp(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 %52
22: ; preds = %3
store i32 6, i32* %10
%23 = load i8, i8* %5
%24 = zext i8 %23 to i32
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 4, i32* %10
br label %27
27: ; preds = %26, %22
%28 = load i8*, i8** %11
%29 = load i8, i8* %5
%30 = zext i8 %29 to i32
%31 = load i8, i8* %6
%32 = zext i8 %31 to i32
%33 = load i32, i32* %10
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 9108, i32 %30, i32 %32, i32 %33)
store i32 %34, i32* %8
%35 = load i8*, i8** %11
%36 = load i32, i32* %8
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8*, i8** %7
%40 = load i32, i32* %10
%41 = call i32 @memcpy(i8* %38, i8* %39, i32 %40)
%42 = load i32, i32* %10
%43 = load i32, i32* %8
%44 = add i32 %43, %42
store i32 %44, i32* %8
%45 = load i8*, i8** %11
%46 = load i32, i32* %8
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%50 = load i32, i32* %8
%51 = add i32 %50, %49
store i32 %51, i32* %8
br label %52
52: ; preds = %27, %15
%53 = load i8*, i8** %11
%54 = load i32, i32* %8
%55 = call i32 @iDoRemoteFunc(i8* %53, i32 %54, i32 1)
store i32 %55, i32* %9
%56 = load i8*, i8** %11
%57 = call i32 @free(i8* %56)
%58 = load i32, i32* %9
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %52
%61 = load i32, i32* %9
%62 = call i32 @vWriteLogTxt(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %61)
store i8 1, i8* %4
br label %65
63: ; preds = %52
%64 = call zeroext i8 @iGetParaInt(i32 0)
store i8 %64, i8* %4
br label %65
65: ; preds = %63, %60
%66 = load i8, i8* %4
ret i8 %66
}

LLVM IR (-O2):
@.str = [10 x i8] c"%u(%u,%u)\00"
@.str.1 = [15 x i8] c"%u(%u,%u,b%03u\00"
@.str.3 = [39 x i8] c"_AT102_EraseApp iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcAT102_EraseApp(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
br i1 %5, label %7, label %10
7: ; preds = %3
%8 = zext i8 %1 to i32
%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 %8)
br label %23
10: ; preds = %3
%11 = icmp eq i8 %0, 2
%12 = select i1 %11, i32 4, i32 6
%13 = zext i8 %1 to i32
%14 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 9108, i32 %6, i32 %13, i32 %12)
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %4, i64 %15
%17 = tail call i32 @memcpy(i8* %16, i8* %2, i32 %12)
%18 = add i32 %14, %12
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %4, i64 %19
%21 = bitcast i8* %20 to i16*
store i16 41, i16* %21
%22 = add i32 %18, 1
br label %23
23: ; preds = %10, %7
%24 = phi i32 [ %9, %7 ], [ %22, %10 ]
%25 = tail call i32 @iDoRemoteFunc(i8* %4, i32 %24, i32 1)
%26 = tail call i32 @free(i8* %4)
%27 = icmp eq i32 %25, 0
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = tail call i32 @vWriteLogTxt(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %32
30: ; preds = %23
%31 = tail call zeroext i8 @iGetParaInt(i32 0)
br label %32
32: ; preds = %30, %28
%33 = phi i8 [ 1, %28 ], [ %31, %30 ]
ret i8 %33
}