#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);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, unsigned char *, int);
unsigned int sprintf(char *, char *, ...);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
void _vRcSLE4442_Write(unsigned char Addr, int DataLen,
                       unsigned char *DataBuff) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(512);
  uiDataLen =
      sprintf(psFunCall, "%u(%u,%u,b%03u", 9204, Addr, DataLen, DataLen);
  memcpy(psFunCall + uiDataLen, DataBuff, DataLen);
  uiDataLen += DataLen;
  uiDataLen += sprintf(psFunCall + uiDataLen, ")");
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 5);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_SLE4442_Write iDoRemoteFunc ret = %d", uiRet);
  }
}


x86 assembly (clang, -O0):
<_vRcSLE4442_Write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movzbl -0x1(%rbp),%ecx
mov    -0x8(%rbp),%r8d
mov    -0x8(%rbp),%r9d
lea    0xe66(%rip),%rsi
mov    $0x23f4,%edx
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x5,%edx
call   1070 <iDoRemoteFunc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x18(%rbp)
je     121c <_vRcSLE4442_Write+0xbc>
mov    -0x18(%rbp),%esi
lea    0xdfa(%rip),%rdi
call   1040 <vWriteLogTxt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_vRcSLE4442_Write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%ebx
mov    %edi,%ebp
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe7e(%rip),%rsi
mov    %rax,%rdi
mov    $0x23f4,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %eax,%ebp
mov    %eax,%edi
add    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
lea    (%rbx,%rbp,1),%eax
movw   $0x29,(%r14,%rax,1)
lea    (%rbx,%rbp,1),%esi
add    $0x1,%esi
mov    %r14,%rdi
mov    $0x5,%edx
call   1070 <iDoRemoteFunc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
test   %ebx,%ebx
je     11ed <_vRcSLE4442_Write+0x8d>
lea    0xe33(%rip),%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <vWriteLogTxt@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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