#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);
int iGetParaInt(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, ...);
unsigned int sprintf(char *, char *, ...);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
int iRcTSFID_RUDLL_SetDeviceNo(char fpflag[3], unsigned char deviceno[12]) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(100);
  uiDataLen = sprintf(psFunCall, "%u(b003", 4106);
  memcpy(psFunCall + uiDataLen, fpflag, 3);
  uiDataLen += 3;
  uiDataLen += sprintf(psFunCall + uiDataLen, ",b012");
  memcpy(psFunCall + uiDataLen, deviceno, 12);
  uiDataLen += 12;
  uiDataLen += sprintf(psFunCall + uiDataLen, ")");
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 1);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("iRcTSFID_RUDLL_SetDeviceNo iDoRemoteFunc ret = %d", uiRet);
    return 99;
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<iRcTSFID_RUDLL_SetDeviceNo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe67(%rip),%rsi
mov    $0x100a,%edx
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    $0x3,%edx
call   1060 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    $0xc,%edx
call   1060 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x20(%rbp)
je     126c <iRcTSFID_RUDLL_SetDeviceNo+0xfc>
mov    -0x20(%rbp),%esi
lea    0xdb5(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movl   $0x63,-0x4(%rbp)
jmp    1276 <iRcTSFID_RUDLL_SetDeviceNo+0x106>
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):
<iRcTSFID_RUDLL_SetDeviceNo>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0xe6e(%rip),%rsi
mov    %rax,%rdi
mov    $0x100a,%edx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %eax,%ebx
mov    %eax,%edi
add    %r15,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1060 <memcpy@plt>
lea    0x3(%rbx),%eax
movl   $0x3130622c,(%r15,%rax,1)
31
movw   $0x32,0x4(%r15,%rax,1)
lea    0x8(%rbx),%edi
add    %r15,%rdi
mov    %r14,%rsi
mov    $0xc,%edx
xor    %eax,%eax
call   1060 <memcpy@plt>
lea    0x14(%rbx),%eax
movw   $0x29,(%r15,%rax,1)
add    $0x15,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
test   %ebx,%ebx
je     1228 <iRcTSFID_RUDLL_SetDeviceNo+0xb8>
lea    0xdfe(%rip),%rdi
mov    %ebx,%esi
call   1050 <vWriteLogTxt@plt>
mov    $0x63,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <iGetParaInt@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%u(b003\00"
@.str.1 = [6 x i8] c",b012\00"
@.str.2 = [2 x i8] c")\00"
@.str.3 = [50 x i8] c"iRcTSFID_RUDLL_SetDeviceNo iDoRemoteFunc ret = %d\00"
define i32 @iRcTSFID_RUDLL_SetDeviceNo(i8* %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 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 4106)
store i32 %11, i32* %6
%12 = load i8*, i8** %8
%13 = load i32, i32* %6
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8*, i8** %4
%17 = call i32 (i8*, ...) @memcpy(i8* %15, i8* %16, i32 3)
%18 = load i32, i32* %6
%19 = add i32 %18, 3
store i32 %19, i32* %6
%20 = load i8*, i8** %8
%21 = load i32, i32* %6
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* %6
%26 = add i32 %25, %24
store i32 %26, i32* %6
%27 = load i8*, i8** %8
%28 = load i32, i32* %6
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8*, i8** %5
%32 = call i32 (i8*, ...) @memcpy(i8* %30, i8* %31, i32 12)
%33 = load i32, i32* %6
%34 = add i32 %33, 12
store i32 %34, i32* %6
%35 = load i8*, i8** %8
%36 = load i32, i32* %6
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = call i32 (i8*, i8*, ...) @sprintf(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* %6
%41 = add i32 %40, %39
store i32 %41, i32* %6
%42 = load i8*, i8** %8
%43 = load i32, i32* %6
%44 = call i32 @iDoRemoteFunc(i8* %42, i32 %43, i32 1)
store i32 %44, i32* %7
%45 = load i8*, i8** %8
%46 = call i32 @free(i8* %45)
%47 = load i32, i32* %7
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %2
%50 = load i32, i32* %7
%51 = call i32 @vWriteLogTxt(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %50)
store i32 99, i32* %3
br label %54
52: ; preds = %2
%53 = call i32 @iGetParaInt(i32 0)
store i32 %53, i32* %3
br label %54
54: ; preds = %52, %49
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [8 x i8] c"%u(b003\00"
@.str.1 = [6 x i8] c",b012\00"
@.str.3 = [50 x i8] c"iRcTSFID_RUDLL_SetDeviceNo iDoRemoteFunc ret = %d\00"
define i32 @iRcTSFID_RUDLL_SetDeviceNo(i8* %0, i8* %1) {
%3 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%4 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 4106)
%5 = zext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %3, i64 %5
%7 = tail call i32 (i8*, ...) @memcpy(i8* %6, i8* %0, i32 3)
%8 = add i32 %4, 3
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %3, i64 %9
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(6) %10, i8* align 1 dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 6, i1 false)
%11 = add i32 %4, 8
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %3, i64 %12
%14 = tail call i32 (i8*, ...) @memcpy(i8* %13, i8* %1, i32 12)
%15 = add i32 %4, 20
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %3, i64 %16
%18 = bitcast i8* %17 to i16*
store i16 41, i16* %18
%19 = add i32 %4, 21
%20 = tail call i32 @iDoRemoteFunc(i8* %3, i32 %19, i32 1)
%21 = tail call i32 @free(i8* %3)
%22 = icmp eq i32 %20, 0
br i1 %22, label %25, label %23
23: ; preds = %2
%24 = tail call i32 @vWriteLogTxt(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %27
25: ; preds = %2
%26 = tail call i32 @iGetParaInt(i32 0)
br label %27
27: ; preds = %25, %23
%28 = phi i32 [ 99, %23 ], [ %26, %25 ]
ret i32 %28
}