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


x86 assembly (clang, -O0):
<CyBtldr_SetApplicationStatus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movb   $0x0,-0x421(%rbp)
mov    -0x1(%rbp),%al
lea    -0x220(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rcx
movzbl %al,%edi
call   1030 <CyBtldr_CreateSetActiveAppCmd@plt>
mov    %eax,-0x428(%rbp)
xor    %eax,%eax
cmp    -0x428(%rbp),%eax
jne    11a7 <CyBtldr_SetApplicationStatus+0x77>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x420(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1050 <CyBtldr_TransferData@plt>
mov    %eax,-0x428(%rbp)
xor    %eax,%eax
cmp    -0x428(%rbp),%eax
jne    11d2 <CyBtldr_SetApplicationStatus+0xa2>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x421(%rbp),%rdx
call   1040 <CyBtldr_ParseSetActiveAppCmdResult@plt>
mov    %eax,-0x428(%rbp)
xor    %eax,%eax
cmp    -0x428(%rbp),%eax
jne    1208 <CyBtldr_SetApplicationStatus+0xd8>
movzbl -0x421(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     1203 <CyBtldr_SetApplicationStatus+0xd3>
movzbl -0x421(%rbp),%eax
or     $0x4000,%eax
mov    %eax,-0x428(%rbp)
jmp    1208 <CyBtldr_SetApplicationStatus+0xd8>
mov    -0x428(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CyBtldr_SetApplicationStatus>:
sub    $0x428,%rsp
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_CreateSetActiveAppCmd@plt>
test   %eax,%eax
jne    1189 <CyBtldr_SetApplicationStatus+0x59>
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     11a8 <CyBtldr_SetApplicationStatus+0x78>
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
ret
mov    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdi
lea    0xf(%rsp),%rdx
call   1040 <CyBtldr_ParseSetActiveAppCmdResult@plt>
mov    0xf(%rsp),%cl
jmp    118b <CyBtldr_SetApplicationStatus+0x5b>

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

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