#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 *, int);
unsigned int sprintf(char *, char *, ...);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned int uiGenCommKey(unsigned char ucMasterKeyId,
                          unsigned char *psRandom) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(100);
  uiDataLen = sprintf(psFunCall, "%u(%u, b008", 9801, ucMasterKeyId);
  memcpy(psFunCall + uiDataLen, psRandom, 8);
  uiDataLen += 8;
  uiDataLen += sprintf(psFunCall + uiDataLen, ")");
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 5);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("uiGenCommKey iDoRemoteFunc ret = %d", uiRet);
    return 99;
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<uiGenCommKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movzbl -0x5(%rbp),%ecx
lea    0xe61(%rip),%rsi
mov    $0x2649,%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    0xe2c(%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    $0x5,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x18(%rbp)
je     122f <uiGenCommKey+0xbf>
mov    -0x18(%rbp),%esi
lea    0xdf0(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movl   $0x63,-0x4(%rbp)
jmp    1239 <uiGenCommKey+0xc9>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uiGenCommKey>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe73(%rip),%rsi
mov    %rax,%rdi
mov    $0x2649,%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    $0x5,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     11f3 <uiGenCommKey+0x83>
lea    0xe2a(%rip),%rdi
mov    %ebp,%esi
call   1050 <vWriteLogTxt@plt>
mov    $0x63,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %edi,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <iGetParaInt@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"%u(%u, b008\00"
@.str.1 = [2 x i8] c")\00"
@.str.2 = [36 x i8] c"uiGenCommKey iDoRemoteFunc ret = %d\00"
define i32 @uiGenCommKey(i8 zeroext %0, i8* %1) {
%3 = alloca i32
%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 100)
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 ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 9801, 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 5)
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 ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %37)
store i32 99, i32* %3
br label %41
39: ; preds = %2
%40 = call i32 @iGetParaInt(i32 0)
store i32 %40, i32* %3
br label %41
41: ; preds = %39, %36
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [12 x i8] c"%u(%u, b008\00"
@.str.2 = [36 x i8] c"uiGenCommKey iDoRemoteFunc ret = %d\00"
define i32 @uiGenCommKey(i8 zeroext %0, i8* %1) {
%3 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%4 = zext i8 %0 to i32
%5 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 9801, 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 5)
%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 ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %21
19: ; preds = %2
%20 = tail call i32 @iGetParaInt(i32 0)
br label %21
21: ; preds = %19, %17
%22 = phi i32 [ 99, %17 ], [ %20, %19 ]
ret i32 %22
}