#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 /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ psGetParaBuf(int);
unsigned int sprintf(char *, char *, int, unsigned int);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned int _uiRcResetCard(unsigned int uiReader,
                            unsigned char *pusResetData) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(200);
  uiDataLen = sprintf(psFunCall, "%u(%u,b000)", 1002, uiReader);
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 2);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_uiRcResetCard iDoRemoteFunc ret = %d", uiRet);
    return 0;
  }
  uiRet = iGetParaInt(0);
  if (uiRet > 0) {
    memcpy(pusResetData, psGetParaBuf(3), uiRet);
  }
  return uiRet;
}


x86 assembly (clang, -O0):
<_uiRcResetCard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xc8,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%ecx
lea    0xe55(%rip),%rsi
mov    $0x3ea,%edx
call   10a0 <sprintf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x2,%edx
call   1090 <iDoRemoteFunc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x18(%rbp)
je     11fa <_uiRcResetCard+0x7a>
mov    -0x18(%rbp),%esi
lea    0xe23(%rip),%rdi
call   1060 <vWriteLogTxt@plt>
movl   $0x0,-0x4(%rbp)
jmp    1234 <_uiRcResetCard+0xb4>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jbe    122e <_uiRcResetCard+0xae>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x3,%edi
call   1050 <psGetParaBuf@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_uiRcResetCard>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
mov    $0xc8,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
lea    0xe63(%rip),%rsi
mov    %rax,%rdi
mov    $0x3ea,%edx
mov    %ebx,%ecx
call   10a0 <sprintf@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    $0x2,%edx
call   1090 <iDoRemoteFunc@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
test   %ebx,%ebx
je     11db <_uiRcResetCard+0x5b>
lea    0xe3c(%rip),%rdi
mov    %ebx,%esi
call   1060 <vWriteLogTxt@plt>
xor    %ebp,%ebp
jmp    1202 <_uiRcResetCard+0x82>
xor    %ebp,%ebp
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
test   %eax,%eax
je     1202 <_uiRcResetCard+0x82>
mov    %eax,%ebx
mov    $0x3,%edi
call   1050 <psGetParaBuf@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1070 <memcpy@plt>
mov    %ebx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"%u(%u,b000)\00"
@.str.1 = [38 x i8] c"_uiRcResetCard iDoRemoteFunc ret = %d\00"
define i32 @_uiRcResetCard(i32 %0, i8* %1) {
%3 = tail call dereferenceable_or_null(200) i8* @malloc(i32 200)
%4 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 1002, i32 %0)
%5 = tail call i32 @iDoRemoteFunc(i8* %3, i32 %4, i32 2)
%6 = tail call i32 @free(i8* %3)
%7 = icmp eq i32 %5, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @vWriteLogTxt(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %16
10: ; preds = %2
%11 = tail call i32 @iGetParaInt(i32 0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i32 @psGetParaBuf(i32 3)
%15 = tail call i32 @memcpy(i8* %1, i32 %14, i32 %11)
br label %16
16: ; preds = %10, %13, %8
%17 = phi i32 [ 0, %8 ], [ %11, %13 ], [ 0, %10 ]
ret i32 %17
}