#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_CreateVerifyChecksumCmd(unsigned char *, unsigned long *,
                                    unsigned long *);
int CyBtldr_ParseVerifyChecksumCmdResult(unsigned char *, unsigned long,
                                         unsigned char *, unsigned char *);
int CyBtldr_TransferData(unsigned char *, unsigned long, unsigned char *,
                         unsigned long);
int CyBtldr_VerifyApplication() {
  unsigned char inBuf[512];
  unsigned char outBuf[512];
  unsigned long inSize = 0;
  unsigned long outSize = 0;
  unsigned char checksumValid = 0;
  unsigned char status = 0x00;
  int err = CyBtldr_CreateVerifyChecksumCmd(inBuf, &inSize, &outSize);
  if (0x00 == err)
    err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize);
  if (0x00 == err)
    err = CyBtldr_ParseVerifyChecksumCmdResult(outBuf, outSize, &checksumValid,
                                               &status);
  if (0x00 != status)
    err = status | 0x4000;
  if ((0x00 == err) && (!checksumValid))
    err = 0x08;
  return err;
}


x86 assembly (clang, -O0):
<CyBtldr_VerifyApplication>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movq   $0x0,-0x408(%rbp)
movq   $0x0,-0x410(%rbp)
movb   $0x0,-0x411(%rbp)
movb   $0x0,-0x412(%rbp)
lea    -0x200(%rbp),%rdi
lea    -0x408(%rbp),%rsi
lea    -0x410(%rbp),%rdx
call   1030 <CyBtldr_CreateVerifyChecksumCmd@plt>
mov    %eax,-0x418(%rbp)
xor    %eax,%eax
cmp    -0x418(%rbp),%eax
jne    11b4 <CyBtldr_VerifyApplication+0x84>
lea    -0x200(%rbp),%rdi
mov    -0x408(%rbp),%rsi
lea    -0x400(%rbp),%rdx
mov    -0x410(%rbp),%rcx
call   1040 <CyBtldr_TransferData@plt>
mov    %eax,-0x418(%rbp)
xor    %eax,%eax
cmp    -0x418(%rbp),%eax
jne    11e9 <CyBtldr_VerifyApplication+0xb9>
lea    -0x400(%rbp),%rdi
mov    -0x410(%rbp),%rsi
lea    -0x411(%rbp),%rdx
lea    -0x412(%rbp),%rcx
call   1050 <CyBtldr_ParseVerifyChecksumCmdResult@plt>
mov    %eax,-0x418(%rbp)
movzbl -0x412(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     120c <CyBtldr_VerifyApplication+0xdc>
movzbl -0x412(%rbp),%eax
or     $0x4000,%eax
mov    %eax,-0x418(%rbp)
xor    %eax,%eax
cmp    -0x418(%rbp),%eax
jne    1231 <CyBtldr_VerifyApplication+0x101>
cmpb   $0x0,-0x411(%rbp)
jne    1231 <CyBtldr_VerifyApplication+0x101>
movl   $0x8,-0x418(%rbp)
mov    -0x418(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CyBtldr_VerifyApplication>:
sub    $0x428,%rsp
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
movb   $0x0,0xf(%rsp)
movb   $0x0,0xe(%rsp)
lea    0x220(%rsp),%rdi
lea    0x18(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1030 <CyBtldr_CreateVerifyChecksumCmd@plt>
test   %eax,%eax
jne    118e <CyBtldr_VerifyApplication+0x5e>
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%rcx
lea    0x220(%rsp),%rdi
lea    0x20(%rsp),%rdx
call   1040 <CyBtldr_TransferData@plt>
test   %eax,%eax
je     11a9 <CyBtldr_VerifyApplication+0x79>
xor    %ecx,%ecx
test   %cl,%cl
mov    $0x8,%ecx
cmovne %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
lea    0xe(%rsp),%rcx
call   1050 <CyBtldr_ParseVerifyChecksumCmdResult@plt>
movzbl 0xe(%rsp),%edx
cmpb   $0x0,0xf(%rsp)
setne  %cl
test   %edx,%edx
je     1190 <CyBtldr_VerifyApplication+0x60>
or     $0x4000,%edx
mov    %edx,%eax
jmp    1190 <CyBtldr_VerifyApplication+0x60>

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

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