unsigned int _uiRcMifApdu(unsigned char *psApduIn, unsigned int uiInLen,
                          unsigned char *psApduOut, unsigned int *puiOutLen) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(1024);
  uiDataLen = sprintf(psFunCall, "%u(b%03u", 2011, uiInLen);
  memcpy(psFunCall + uiDataLen, psApduIn, uiInLen);
  uiDataLen += uiInLen;
  uiDataLen += sprintf(psFunCall + uiDataLen, ",%u,b000,0)", uiInLen);
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 1);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_uiRcMifApdu iDoRemoteFunc ret = %d", uiRet);
    return 1;
  }
  uiRet = iGetParaInt(0);
  if (uiRet == 0) {
    *puiOutLen = iGetParaInt(5);
    memcpy(psApduOut, psGetParaBuf(4), *puiOutLen);
  }
  return uiRet;
}


x86 assembly (clang, -O0):
<_uiRcMifApdu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%ecx
lea    0xe4d(%rip),%rsi
mov    $0x7db,%edx
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x14(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%eax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    $0x1,%edx
mov    $0x0,%al
call   1090 <iDoRemoteFunc@plt>
mov    %eax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x30(%rbp)
je     124a <_uiRcMifApdu+0xca>
mov    -0x30(%rbp),%esi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1060 <vWriteLogTxt@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a2 <_uiRcMifApdu+0x122>
xor    %edi,%edi
mov    $0x0,%al
call   1040 <iGetParaInt@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    129c <_uiRcMifApdu+0x11c>
mov    $0x5,%edi
mov    $0x0,%al
call   1040 <iGetParaInt@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x4,%edi
mov    $0x0,%al
call   1050 <psGetParaBuf@plt>
mov    -0x40(%rbp),%rdi
movslq %eax,%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_uiRcMifApdu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%r13
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe55(%rip),%rsi
mov    %rax,%rdi
mov    $0x7db,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %eax,%ebp
mov    %eax,%edi
add    %rbx,%rdi
mov    %r12d,%edx
mov    %r13,%rsi
call   1070 <memcpy@plt>
add    %r12d,%ebp
lea    (%rbx,%rbp,1),%rdi
lea    0xe2c(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   10a0 <sprintf@plt>
add    %eax,%ebp
mov    $0x1,%r12d
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1090 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     1220 <_uiRcMifApdu+0xa0>
lea    0xe00(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <vWriteLogTxt@plt>
jmp    125c <_uiRcMifApdu+0xdc>
xor    %edi,%edi
xor    %eax,%eax
call   1040 <iGetParaInt@plt>
mov    %eax,%r12d
test   %eax,%eax
jne    125c <_uiRcMifApdu+0xdc>
mov    $0x5,%edi
xor    %eax,%eax
call   1040 <iGetParaInt@plt>
mov    %eax,(%r15)
mov    $0x4,%edi
xor    %eax,%eax
call   1050 <psGetParaBuf@plt>
movslq %eax,%rsi
mov    (%r15),%edx
mov    %r14,%rdi
call   1070 <memcpy@plt>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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