unsigned int _uiRcExchangeApduEx(unsigned int uiReader,
                                 unsigned char ucCardType,
                                 unsigned char *psApduIn, unsigned int uiInLen,
                                 unsigned char *psApduOut,
                                 unsigned int *puiOutLen) {
  unsigned int uiDataLen;
  int iRet;
  char *psFunCall = malloc(512);
  uiDataLen =
      sprintf(psFunCall, "%u(%u,%u,b%03u", 1004, uiReader, ucCardType, uiInLen);
  memcpy(psFunCall + uiDataLen, psApduIn, uiInLen);
  uiDataLen += uiInLen;
  uiDataLen += sprintf(psFunCall + uiDataLen, ",%u,b000,0)", uiInLen);
  iRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 8);
  free(psFunCall);
  if (iRet == -2)
    return 9;
  if (iRet) {
    vWriteLogTxt("_uiRcExchangeApdu iDoRemoteFunc ret = %d", iRet);
    return 1;
  }
  iRet = iGetParaInt(0);
  if (iRet != 0)
    return 1;
  uiDataLen = iGetParaInt(7);
  if (uiDataLen < 2)
    return 1;
  *puiOutLen = uiDataLen;
  memcpy(psApduOut, psGetParaBuf(6), uiDataLen);
  return (0);
}


x86 assembly (clang, -O0):
<_uiRcExchangeApduEx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    $0x200,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%ecx
movzbl -0x9(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
lea    0xe3b(%rip),%rsi
mov    $0x3ec,%edx
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%eax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%eax
add    %rax,%rdi
mov    -0x1c(%rbp),%edx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    $0x8,%edx
mov    $0x0,%al
call   1090 <iDoRemoteFunc@plt>
mov    %eax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0xfffffffe,-0x38(%rbp)
jne    124b <_uiRcExchangeApduEx+0xcb>
movl   $0x9,-0x4(%rbp)
jmp    12ee <_uiRcExchangeApduEx+0x16e>
cmpl   $0x0,-0x38(%rbp)
je     1272 <_uiRcExchangeApduEx+0xf2>
mov    -0x38(%rbp),%esi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1060 <vWriteLogTxt@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ee <_uiRcExchangeApduEx+0x16e>
xor    %edi,%edi
mov    $0x0,%al
call   1040 <iGetParaInt@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1294 <_uiRcExchangeApduEx+0x114>
movl   $0x1,-0x4(%rbp)
jmp    12ee <_uiRcExchangeApduEx+0x16e>
mov    $0x7,%edi
mov    $0x0,%al
call   1040 <iGetParaInt@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x2,-0x34(%rbp)
jae    12b9 <_uiRcExchangeApduEx+0x139>
movl   $0x1,-0x4(%rbp)
jmp    12ee <_uiRcExchangeApduEx+0x16e>
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x6,%edi
mov    $0x0,%al
call   1050 <psGetParaBuf@plt>
mov    -0x48(%rbp),%rdi
movslq %eax,%rsi
mov    -0x34(%rbp),%eax
mov    %eax,%edx
call   1070 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_uiRcExchangeApduEx>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %r8,(%rsp)
mov    %ecx,%r13d
mov    %rdx,%r12
mov    %esi,%ebp
mov    %edi,%r14d
mov    $0x200,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe4f(%rip),%rsi
mov    %rax,%rdi
mov    $0x3ec,%edx
mov    %r14d,%ecx
mov    %ebp,%r8d
mov    %r13d,%r9d
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %eax,%ebp
mov    %eax,%edi
add    %rbx,%rdi
mov    %r13d,%edx
mov    %r12,%rsi
call   1070 <memcpy@plt>
add    %r13d,%ebp
lea    (%rbx,%rbp,1),%rdi
lea    0xe26(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   10a0 <sprintf@plt>
add    %eax,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x8,%edx
xor    %eax,%eax
call   1090 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
cmp    $0xfffffffe,%ebp
je     125f <_uiRcExchangeApduEx+0xdf>
test   %ebp,%ebp
jne    1266 <_uiRcExchangeApduEx+0xe6>
xor    %edi,%edi
xor    %eax,%eax
call   1040 <iGetParaInt@plt>
mov    $0x1,%ebx
test   %eax,%eax
jne    127b <_uiRcExchangeApduEx+0xfb>
mov    $0x7,%edi
xor    %eax,%eax
call   1040 <iGetParaInt@plt>
cmp    $0x2,%eax
jb     127b <_uiRcExchangeApduEx+0xfb>
mov    %eax,%ebp
mov    %eax,(%r15)
mov    $0x6,%edi
xor    %eax,%eax
call   1050 <psGetParaBuf@plt>
movslq %eax,%rsi
mov    %ebp,%edx
mov    (%rsp),%rdi
call   1070 <memcpy@plt>
xor    %ebx,%ebx
jmp    127b <_uiRcExchangeApduEx+0xfb>
mov    $0x9,%ebx
jmp    127b <_uiRcExchangeApduEx+0xfb>
lea    0xdae(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <vWriteLogTxt@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"%u(%u,%u,b%03u\00"
@.str.1 = [12 x i8] c",%u,b000,0)\00"
@.str.2 = [41 x i8] c"_uiRcExchangeApdu iDoRemoteFunc ret = %d\00"
define i32 @_uiRcExchangeApduEx(i32 %0, i8 zeroext %1, i8* %2, i32 %3, i8* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
store i32 %0, i32* %8
store i8 %1, i8* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i32* %5, i32** %13
%17 = call i8* @malloc(i64 512)
store i8* %17, i8** %16
%18 = load i8*, i8** %16
%19 = load i32, i32* %8
%20 = load i8, i8* %9
%21 = zext i8 %20 to i32
%22 = load i32, i32* %11
%23 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 1004, i32 %19, i32 %21, i32 %22)
store i32 %23, i32* %14
%24 = load i8*, i8** %16
%25 = load i32, i32* %14
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8*, i8** %10
%29 = load i32, i32* %11
%30 = zext i32 %29 to i64
%31 = load i32, i32* %11
%32 = load i32, i32* %14
%33 = add i32 %32, %31
store i32 %33, i32* %14
%34 = load i8*, i8** %16
%35 = load i32, i32* %14
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i32, i32* %11
%39 = call i32 (i8*, i8*, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %14
%41 = add i32 %40, %39
store i32 %41, i32* %14
%42 = load i8*, i8** %16
%43 = load i32, i32* %14
%44 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @iDoRemoteFunc to i32 (i8*, i32, i32, ...)*)(i8* %42, i32 %43, i32 8)
store i32 %44, i32* %15
%45 = load i8*, i8** %16
%46 = load i32, i32* %15
%47 = icmp eq i32 %46, -2
br i1 %47, label %48, label %49
48: ; preds = %6
store i32 9, i32* %7
br label %74
49: ; preds = %6
%50 = load i32, i32* %15
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i32, i32* %15
%54 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @vWriteLogTxt to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %53)
store i32 1, i32* %7
br label %74
55: ; preds = %49
%56 = call i32 (i32, ...) bitcast (i32 (...)* @iGetParaInt to i32 (i32, ...)*)(i32 0)
store i32 %56, i32* %15
%57 = load i32, i32* %15
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %55
store i32 1, i32* %7
br label %74
60: ; preds = %55
%61 = call i32 (i32, ...) bitcast (i32 (...)* @iGetParaInt to i32 (i32, ...)*)(i32 7)
store i32 %61, i32* %14
%62 = load i32, i32* %14
%63 = icmp ult i32 %62, 2
br i1 %63, label %64, label %65
64: ; preds = %60
store i32 1, i32* %7
br label %74
65: ; preds = %60
%66 = load i32, i32* %14
%67 = load i32*, i32** %13
store i32 %66, i32* %67
%68 = load i8*, i8** %12
%69 = call i32 (i32, ...) bitcast (i32 (...)* @psGetParaBuf to i32 (i32, ...)*)(i32 6)
%70 = sext i32 %69 to i64
%71 = inttoptr i64 %70 to i8*
%72 = load i32, i32* %14
%73 = zext i32 %72 to i64
store i32 0, i32* %7
br label %74
74: ; preds = %65, %64, %59, %52, %48
%75 = load i32, i32* %7
ret i32 %75
}

LLVM IR (-O2):
@.str = [15 x i8] c"%u(%u,%u,b%03u\00"
@.str.1 = [12 x i8] c",%u,b000,0)\00"
@.str.2 = [41 x i8] c"_uiRcExchangeApdu iDoRemoteFunc ret = %d\00"
define i32 @_uiRcExchangeApduEx(i32 %0, i8 zeroext %1, i8* nocapture %2, i32 %3, i8* nocapture writeonly %4, i32* nocapture writeonly %5) {
%7 = tail call dereferenceable_or_null(512) i8* @malloc(i64 512)
%8 = zext i8 %1 to i32
%9 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 1004, i32 %0, i32 %8, i32 %3)
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
%12 = zext i32 %3 to i64
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %11, i8* align 1 %2, i64 %12, i1 false)
%13 = add i32 %9, %3
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %7, i64 %14
%16 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%17 = add i32 %16, %13
%18 = tail call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @iDoRemoteFunc to i32 (i8*, i32, i32, ...)*)(i8* %7, i32 %17, i32 8)
tail call void @free(i8* %7)
switch i32 %18, label %19 [
i32 -2, label %32
i32 0, label %21
]
19: ; preds = %6
%20 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @vWriteLogTxt to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %32
21: ; preds = %6
%22 = tail call i32 (i32, ...) bitcast (i32 (...)* @iGetParaInt to i32 (i32, ...)*)(i32 0)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %21
%25 = tail call i32 (i32, ...) bitcast (i32 (...)* @iGetParaInt to i32 (i32, ...)*)(i32 7)
%26 = icmp ult i32 %25, 2
br i1 %26, label %32, label %27
27: ; preds = %24
store i32 %25, i32* %5
%28 = tail call i32 (i32, ...) bitcast (i32 (...)* @psGetParaBuf to i32 (i32, ...)*)(i32 6)
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i8*
%31 = zext i32 %25 to i64
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %4, i8* align 1 %30, i64 %31, i1 false)
br label %32
32: ; preds = %24, %21, %6, %27, %19
%33 = phi i32 [ 1, %19 ], [ 0, %27 ], [ 9, %6 ], [ 1, %21 ], [ 1, %24 ]
ret i32 %33
}