#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 CyBtldr_CreateGetAppStatusCmd(unsigned char, unsigned char *,
                                  unsigned long *, unsigned long *);
int CyBtldr_ParseGetAppStatusCmdResult(unsigned char *, unsigned long,
                                       unsigned char *, unsigned char *,
                                       unsigned char *);
int CyBtldr_TransferData(unsigned char *, unsigned long, unsigned char *,
                         unsigned long);
int CyBtldr_GetApplicationStatus(unsigned char appID, unsigned char *isValid,
                                 unsigned char *isActive) {
  unsigned long inSize = 0;
  unsigned long outSize = 0;
  unsigned char inBuf[512];
  unsigned char outBuf[512];
  unsigned char status = 0x00;
  int err;
  err = CyBtldr_CreateGetAppStatusCmd(appID, inBuf, &inSize, &outSize);
  if (0x00 == err)
    err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize);
  if (0x00 == err)
    err = CyBtldr_ParseGetAppStatusCmdResult(outBuf, outSize, isValid, isActive,
                                             &status);
  if (0x00 == err) {
    if (0x00 != status)
      err = status | 0x4000;
  }
  return err;
}


x86 assembly (clang, -O0):
<CyBtldr_GetApplicationStatus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movb   $0x0,-0x431(%rbp)
mov    -0x1(%rbp),%al
lea    -0x230(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
movzbl %al,%edi
call   1030 <CyBtldr_CreateGetAppStatusCmd@plt>
mov    %eax,-0x438(%rbp)
xor    %eax,%eax
cmp    -0x438(%rbp),%eax
jne    11af <CyBtldr_GetApplicationStatus+0x7f>
lea    -0x230(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x430(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <CyBtldr_TransferData@plt>
mov    %eax,-0x438(%rbp)
xor    %eax,%eax
cmp    -0x438(%rbp),%eax
jne    11e2 <CyBtldr_GetApplicationStatus+0xb2>
lea    -0x430(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x431(%rbp),%r8
call   1040 <CyBtldr_ParseGetAppStatusCmdResult@plt>
mov    %eax,-0x438(%rbp)
xor    %eax,%eax
cmp    -0x438(%rbp),%eax
jne    1218 <CyBtldr_GetApplicationStatus+0xe8>
movzbl -0x431(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     1213 <CyBtldr_GetApplicationStatus+0xe3>
movzbl -0x431(%rbp),%eax
or     $0x4000,%eax
mov    %eax,-0x438(%rbp)
jmp    1218 <CyBtldr_GetApplicationStatus+0xe8>
mov    -0x438(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CyBtldr_GetApplicationStatus>:
push   %r14
push   %rbx
sub    $0x428,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
movb   $0x0,0xf(%rsp)
lea    0x220(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1030 <CyBtldr_CreateGetAppStatusCmd@plt>
test   %eax,%eax
jne    1192 <CyBtldr_GetApplicationStatus+0x62>
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%rcx
lea    0x220(%rsp),%rdi
lea    0x20(%rsp),%rdx
call   1050 <CyBtldr_TransferData@plt>
test   %eax,%eax
je     11b4 <CyBtldr_GetApplicationStatus+0x84>
xor    %ecx,%ecx
movzbl %cl,%edx
lea    0x4000(%rdx),%ecx
test   %dl,%dl
cmove  %eax,%ecx
test   %eax,%eax
cmovne %eax,%ecx
mov    %ecx,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r14
ret
mov    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdi
lea    0xf(%rsp),%r8
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <CyBtldr_ParseGetAppStatusCmdResult@plt>
mov    0xf(%rsp),%cl
jmp    1194 <CyBtldr_GetApplicationStatus+0x64>

LLVM IR (-O0):
define i32 @CyBtldr_GetApplicationStatus(i8 zeroext %0, i8* %1, i8* %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca [512 x i8]
%10 = alloca [512 x i8]
%11 = alloca i8
%12 = alloca i32
store i8 %0, i8* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i64 0, i64* %7
store i64 0, i64* %8
store i8 0, i8* %11
%13 = load i8, i8* %4
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%15 = call i32 @CyBtldr_CreateGetAppStatusCmd(i8 zeroext %13, i8* %14, i64* %7, i64* %8)
store i32 %15, i32* %12
%16 = load i32, i32* %12
%17 = icmp eq i32 0, %16
br i1 %17, label %18, label %24
18: ; preds = %3
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%20 = load i64, i64* %7
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%22 = load i64, i64* %8
%23 = call i32 @CyBtldr_TransferData(i8* %19, i64 %20, i8* %21, i64 %22)
store i32 %23, i32* %12
br label %24
24: ; preds = %18, %3
%25 = load i32, i32* %12
%26 = icmp eq i32 0, %25
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%29 = load i64, i64* %8
%30 = load i8*, i8** %5
%31 = load i8*, i8** %6
%32 = call i32 @CyBtldr_ParseGetAppStatusCmdResult(i8* %28, i64 %29, i8* %30, i8* %31, i8* %11)
store i32 %32, i32* %12
br label %33
33: ; preds = %27, %24
%34 = load i32, i32* %12
%35 = icmp eq i32 0, %34
br i1 %35, label %36, label %45
36: ; preds = %33
%37 = load i8, i8* %11
%38 = zext i8 %37 to i32
%39 = icmp ne i32 0, %38
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i8, i8* %11
%42 = zext i8 %41 to i32
%43 = or i32 %42, 16384
store i32 %43, i32* %12
br label %44
44: ; preds = %40, %36
br label %45
45: ; preds = %44, %33
%46 = load i32, i32* %12
ret i32 %46
}

LLVM IR (-O2):
define i32 @CyBtldr_GetApplicationStatus(i8 zeroext %0, i8* %1, i8* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
%8 = alloca i8
%9 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%10 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
store i8 0, i8* %8
%13 = call i32 @CyBtldr_CreateGetAppStatusCmd(i8 zeroext %0, i8* %11, i64* %4, i64* %5)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %3
%16 = load i64, i64* %4
%17 = load i64, i64* %5
%18 = call i32 @CyBtldr_TransferData(i8* %11, i64 %16, i8* %12, i64 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i64, i64* %5
%22 = call i32 @CyBtldr_ParseGetAppStatusCmdResult(i8* %12, i64 %21, i8* %1, i8* %2, i8* %8)
%23 = load i8, i8* %8
br label %24
24: ; preds = %3, %20, %15
%25 = phi i8 [ %23, %20 ], [ 0, %15 ], [ 0, %3 ]
%26 = phi i32 [ %22, %20 ], [ %18, %15 ], [ %13, %3 ]
%27 = icmp eq i32 %26, 0
%28 = icmp ne i8 %25, 0
%29 = select i1 %27, i1 %28, i1 false
%30 = zext i8 %25 to i32
%31 = or i32 %30, 16384
%32 = select i1 %29, i32 %31, i32 %26
ret i32 %32
}