#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 _ucRcAT1608_VerifyPasswordEx(unsigned char Index,
                                           unsigned char *Password) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(50);
  uiDataLen = sprintf(psFunCall, "%u(%u,b008", 9510, Index);
  memcpy(psFunCall + uiDataLen, Password, 8);
  uiDataLen += 8;
  uiDataLen += sprintf(psFunCall + uiDataLen, ")");
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 2);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_AT1608_VerifyPasswordEx iDoRemoteFunc ret = %d", uiRet);
    return 1;
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_ucRcAT1608_VerifyPasswordEx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movzbl -0x2(%rbp),%ecx
lea    0xe61(%rip),%rsi
mov    $0x2526,%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    0xe2b(%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     122c <_ucRcAT1608_VerifyPasswordEx+0xbc>
mov    -0x18(%rbp),%esi
lea    0xdef(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movb   $0x1,-0x1(%rbp)
jmp    1236 <_ucRcAT1608_VerifyPasswordEx+0xc6>
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):
<_ucRcAT1608_VerifyPasswordEx>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe73(%rip),%rsi
mov    %rax,%rdi
mov    $0x2526,%edx
mov    %ebp,%ecx
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     11f0 <_ucRcAT1608_VerifyPasswordEx+0x80>
lea    0xe29(%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 = [11 x i8] c"%u(%u,b008\00"
@.str.1 = [2 x i8] c")\00"
@.str.2 = [48 x i8] c"_AT1608_VerifyPasswordEx iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcAT1608_VerifyPasswordEx(i8 zeroext %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8 %0, i8* %4
store i8* %1, i8** %5
%9 = call i8* @malloc(i32 50)
store i8* %9, i8** %8
%10 = load i8*, i8** %8
%11 = load i8, i8* %4
%12 = zext i8 %11 to i32
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 9510, i32 %12)
store i32 %13, i32* %6
%14 = load i8*, i8** %8
%15 = load i32, i32* %6
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8*, i8** %5
%19 = call i32 @memcpy(i8* %17, i8* %18, i32 8)
%20 = load i32, i32* %6
%21 = add i32 %20, 8
store i32 %21, i32* %6
%22 = load i8*, i8** %8
%23 = load i32, i32* %6
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* %6
%28 = add i32 %27, %26
store i32 %28, i32* %6
%29 = load i8*, i8** %8
%30 = load i32, i32* %6
%31 = call i32 @iDoRemoteFunc(i8* %29, i32 %30, i32 2)
store i32 %31, i32* %7
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %2
%37 = load i32, i32* %7
%38 = call i32 @vWriteLogTxt(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %37)
store i8 1, i8* %3
br label %41
39: ; preds = %2
%40 = call zeroext i8 @iGetParaInt(i32 0)
store i8 %40, i8* %3
br label %41
41: ; preds = %39, %36
%42 = load i8, i8* %3
ret i8 %42
}

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