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


x86 assembly (clang, -O0):
<iRcTSFID_RUDLL_SetDeviceType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe65(%rip),%rsi
mov    $0xd,%edx
call   1090 <sprintf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%eax
add    %rax,%rdi
lea    0xe2e(%rip),%rsi
movzbl -0x11(%rbp),%edx
call   1090 <sprintf@plt>
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x1c(%rbp)
je     122b <iRcTSFID_RUDLL_SetDeviceType+0xbb>
mov    -0x1c(%rbp),%esi
lea    0xdf3(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movl   $0x63,-0x4(%rbp)
jmp    1235 <iRcTSFID_RUDLL_SetDeviceType+0xc5>
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_SetDeviceType>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe6f(%rip),%rsi
mov    %rax,%rdi
mov    $0xd,%edx
call   1090 <sprintf@plt>
mov    %eax,%ebp
mov    %eax,%edi
add    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1060 <memcpy@plt>
lea    0x3(%rbp),%edi
add    %rbx,%rdi
lea    0xe49(%rip),%rsi
mov    %r14d,%edx
call   1090 <sprintf@plt>
lea    (%rax,%rbp,1),%esi
add    $0x3,%esi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     1206 <iRcTSFID_RUDLL_SetDeviceType+0x96>
lea    0xe1e(%rip),%rdi
mov    %ebp,%esi
call   1050 <vWriteLogTxt@plt>
mov    $0x63,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <iGetParaInt@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%u(b003\00"
@.str.1 = [5 x i8] c",%u)\00"
@.str.2 = [52 x i8] c"iRcTSFID_RUDLL_SetDeviceType iDoRemoteFunc ret = %d\00"
define i32 @iRcTSFID_RUDLL_SetDeviceType(i8* %0, i8 zeroext %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 @sprintf(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 zeroext 13)
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 @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 = load i8, i8* %5
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %24)
%26 = load i32, i32* %6
%27 = add i32 %26, %25
store i32 %27, i32* %6
%28 = load i8*, i8** %8
%29 = load i32, i32* %6
%30 = call i32 @iDoRemoteFunc(i8* %28, i32 %29, i32 1)
store i32 %30, i32* %7
%31 = load i8*, i8** %8
%32 = call i32 @free(i8* %31)
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %2
%36 = load i32, i32* %7
%37 = call i32 @vWriteLogTxt(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %36)
store i32 99, i32* %3
br label %40
38: ; preds = %2
%39 = call i32 @iGetParaInt(i32 0)
store i32 %39, i32* %3
br label %40
40: ; preds = %38, %35
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [8 x i8] c"%u(b003\00"
@.str.1 = [5 x i8] c",%u)\00"
@.str.2 = [52 x i8] c"iRcTSFID_RUDLL_SetDeviceType iDoRemoteFunc ret = %d\00"
define i32 @iRcTSFID_RUDLL_SetDeviceType(i8* %0, i8 zeroext %1) {
%3 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%4 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 zeroext 13)
%5 = zext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %3, i64 %5
%7 = tail call i32 @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
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %1)
%12 = add i32 %11, %8
%13 = tail call i32 @iDoRemoteFunc(i8* %3, i32 %12, i32 1)
%14 = tail call i32 @free(i8* %3)
%15 = icmp eq i32 %13, 0
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = tail call i32 @vWriteLogTxt(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %20
18: ; preds = %2
%19 = tail call i32 @iGetParaInt(i32 0)
br label %20
20: ; preds = %18, %16
%21 = phi i32 [ 99, %16 ], [ %19, %18 ]
ret i32 %21
}