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


x86 assembly (clang, -O0):
<iRcTSFID_RUDLL_GetDeviceType>:
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    $0x100e,%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
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    0xe2e(%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     1229 <iRcTSFID_RUDLL_GetDeviceType+0xb9>
mov    -0x20(%rbp),%esi
lea    0xdf4(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
movl   $0x63,-0x4(%rbp)
jmp    1255 <iRcTSFID_RUDLL_GetDeviceType+0xe5>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
cmp    $0x0,%eax
jne    124b <iRcTSFID_RUDLL_GetDeviceType+0xdb>
mov    $0x3,%edi
call   1040 <iGetParaInt@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
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_GetDeviceType>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe6f(%rip),%rsi
mov    %rax,%rdi
mov    $0x100e,%edx
xor    %eax,%eax
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),%eax
movl   $0x29302c,(%rbx,%rax,1)
add    $0x6,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1080 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     11fc <iRcTSFID_RUDLL_GetDeviceType+0x8c>
lea    0xe23(%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
call   1040 <iGetParaInt@plt>
test   %eax,%eax
jne    1214 <iRcTSFID_RUDLL_GetDeviceType+0xa4>
mov    $0x3,%edi
call   1040 <iGetParaInt@plt>
mov    %al,(%r14)
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 = [4 x i8] c",0)\00"
@.str.2 = [52 x i8] c"iRcTSFID_RUDLL_GetDeviceType iDoRemoteFunc ret = %d\00"
define i32 @iRcTSFID_RUDLL_GetDeviceType(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 4110)
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 = call i32 (i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 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 = call i32 @iDoRemoteFunc(i8* %27, i32 %28, i32 1)
store i32 %29, i32* %7
%30 = load i8*, i8** %8
%31 = call i32 @free(i8* %30)
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %2
%35 = load i32, i32* %7
%36 = call i32 @vWriteLogTxt(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %35)
store i32 99, i32* %3
br label %46
37: ; preds = %2
%38 = call i32 @iGetParaInt(i32 0)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = call i32 @iGetParaInt(i32 3)
%42 = trunc i32 %41 to i8
%43 = load i8*, i8** %5
store i8 %42, i8* %43
br label %44
44: ; preds = %40, %37
%45 = call i32 @iGetParaInt(i32 0)
store i32 %45, i32* %3
br label %46
46: ; preds = %44, %34
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [8 x i8] c"%u(b003\00"
@.str.2 = [52 x i8] c"iRcTSFID_RUDLL_GetDeviceType iDoRemoteFunc ret = %d\00"
define i32 @iRcTSFID_RUDLL_GetDeviceType(i8* %0, i8* nocapture writeonly %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 4110)
%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 = bitcast i8* %10 to i32*
store i32 2699308, i32* %11
%12 = add i32 %4, 6
%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 %26
18: ; preds = %2
%19 = tail call i32 @iGetParaInt(i32 0)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = tail call i32 @iGetParaInt(i32 3)
%23 = trunc i32 %22 to i8
store i8 %23, i8* %1
br label %24
24: ; preds = %21, %18
%25 = tail call i32 @iGetParaInt(i32 0)
br label %26
26: ; preds = %24, %16
%27 = phi i32 [ 99, %16 ], [ %25, %24 ]
ret i32 %27
}