#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(char *, unsigned char *, unsigned char);
unsigned int sprintf(char *, char *, int, unsigned char, unsigned char,
                     unsigned char, unsigned char);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned int _uiRcSetMemoryCardCode(unsigned char ucCardType,
                                    unsigned char ucOffset, unsigned char ucLen,
                                    unsigned char *sCardCode) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(200);
  uiDataLen = sprintf(psFunCall, "%u(%u,%u,%u,b%03u", 9100, ucCardType,
                      ucOffset, ucLen, ucLen);
  memcpy(psFunCall + uiDataLen, sCardCode, ucLen);
  uiDataLen += ucLen;
  psFunCall[uiDataLen++] = ')';
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 1);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_uiRcSetMemoryCardCode iDoRemoteFunc ret = %d", uiRet);
    return 1;
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_uiRcSetMemoryCardCode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %dil,%sil
mov    %sil,-0x5(%rbp)
mov    %dl,-0x6(%rbp)
mov    %al,-0x7(%rbp)
mov    %rcx,-0x10(%rbp)
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x5(%rbp),%cl
mov    -0x6(%rbp),%r8b
mov    -0x7(%rbp),%al
lea    0xe4f(%rip),%rsi
mov    $0x238c,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %al,%r9d
movzbl -0x7(%rbp),%eax
mov    %eax,(%rsp)
call   1090 <sprintf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x7(%rbp),%al
movzbl %al,%edx
call   1060 <memcpy@plt>
movzbl -0x7(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
mov    %ecx,%ecx
movb   $0x29,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x18(%rbp)
je     124a <_uiRcSetMemoryCardCode+0xda>
mov    -0x18(%rbp),%esi
lea    0xdd9(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movl   $0x1,-0x4(%rbp)
jmp    1254 <_uiRcSetMemoryCardCode+0xe4>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_uiRcSetMemoryCardCode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r15
mov    %edx,%ebx
mov    %esi,%r12d
mov    %edi,%ebp
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %ebx,(%rsp)
lea    0xe63(%rip),%rsi
mov    %rax,%rdi
mov    $0x238c,%edx
mov    %ebp,%ecx
mov    %r12d,%r8d
mov    %ebx,%r9d
call   1090 <sprintf@plt>
mov    %eax,%ebp
mov    %eax,%edi
add    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
mov    %ebp,%eax
add    %ebx,%eax
lea    (%rbx,%rbp,1),%esi
add    $0x1,%esi
movb   $0x29,(%r14,%rax,1)
mov    %r14,%rdi
mov    $0x1,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
test   %ebx,%ebx
je     120d <_uiRcSetMemoryCardCode+0x9d>
lea    0xe1e(%rip),%rdi
mov    %ebx,%esi
call   1050 <vWriteLogTxt@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <iGetParaInt@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"%u(%u,%u,%u,b%03u\00"
@.str.1 = [46 x i8] c"_uiRcSetMemoryCardCode iDoRemoteFunc ret = %d\00"
define i32 @_uiRcSetMemoryCardCode(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i8 %0, i8* %6
store i8 %1, i8* %7
store i8 %2, i8* %8
store i8* %3, i8** %9
%13 = call i8* @malloc(i32 200)
store i8* %13, i8** %12
%14 = load i8*, i8** %12
%15 = load i8, i8* %6
%16 = load i8, i8* %7
%17 = load i8, i8* %8
%18 = load i8, i8* %8
%19 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 9100, i8 zeroext %15, i8 zeroext %16, i8 zeroext %17, i8 zeroext %18)
store i32 %19, i32* %10
%20 = load i8*, i8** %12
%21 = load i32, i32* %10
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8*, i8** %9
%25 = load i8, i8* %8
%26 = call i32 @memcpy(i8* %23, i8* %24, i8 zeroext %25)
%27 = load i8, i8* %8
%28 = zext i8 %27 to i32
%29 = load i32, i32* %10
%30 = add i32 %29, %28
store i32 %30, i32* %10
%31 = load i8*, i8** %12
%32 = load i32, i32* %10
%33 = add i32 %32, 1
store i32 %33, i32* %10
%34 = zext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 41, i8* %35
%36 = load i8*, i8** %12
%37 = load i32, i32* %10
%38 = call i32 @iDoRemoteFunc(i8* %36, i32 %37, i32 1)
store i32 %38, i32* %11
%39 = load i8*, i8** %12
%40 = call i32 @free(i8* %39)
%41 = load i32, i32* %11
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %4
%44 = load i32, i32* %11
%45 = call i32 @vWriteLogTxt(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %44)
store i32 1, i32* %5
br label %48
46: ; preds = %4
%47 = call i32 @iGetParaInt(i32 0)
store i32 %47, i32* %5
br label %48
48: ; preds = %46, %43
%49 = load i32, i32* %5
ret i32 %49
}

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