#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_CreateVerifyRowCmd(unsigned char, unsigned short, unsigned char *,
                               unsigned long *, unsigned long *);
int CyBtldr_ParseVerifyRowCmdResult(unsigned char *, unsigned long,
                                    unsigned char *, unsigned char *);
int CyBtldr_TransferData(unsigned char *, unsigned long, unsigned char *,
                         unsigned long);
int CyBtldr_ValidateRow(unsigned char, unsigned short);
int CyBtldr_VerifyRow(unsigned char arrayID, unsigned short rowNum,
                      unsigned char checksum) {
  unsigned char inBuf[512];
  unsigned char outBuf[512];
  unsigned long inSize = 0;
  unsigned long outSize = 0;
  unsigned char rowChecksum = 0;
  unsigned char status = 0x00;
  int err = CyBtldr_ValidateRow(arrayID, rowNum);
  if (0x00 == err)
    err = CyBtldr_CreateVerifyRowCmd(arrayID, rowNum, inBuf, &inSize, &outSize);
  if (0x00 == err)
    err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize);
  if (0x00 == err)
    err =
        CyBtldr_ParseVerifyRowCmdResult(outBuf, outSize, &rowChecksum, &status);
  if (0x00 != status)
    err = status | 0x4000;
  if ((0x00 == err) && (rowChecksum != checksum))
    err = 0x08;
  return err;
}


x86 assembly (clang, -O0):
<CyBtldr_VerifyRow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %dl,%al
mov    %si,%cx
mov    %dil,%dl
mov    %dl,-0x1(%rbp)
mov    %cx,-0x4(%rbp)
mov    %al,-0x5(%rbp)
movq   $0x0,-0x418(%rbp)
movq   $0x0,-0x420(%rbp)
movb   $0x0,-0x421(%rbp)
movb   $0x0,-0x422(%rbp)
mov    -0x1(%rbp),%al
movzbl %al,%edi
movzwl -0x4(%rbp),%esi
call   1040 <CyBtldr_ValidateRow@plt>
mov    %eax,-0x428(%rbp)
xor    %eax,%eax
cmp    -0x428(%rbp),%eax
jne    11d3 <CyBtldr_VerifyRow+0x93>
mov    -0x1(%rbp),%sil
mov    -0x4(%rbp),%ax
lea    -0x210(%rbp),%rdx
lea    -0x418(%rbp),%rcx
lea    -0x420(%rbp),%r8
movzbl %sil,%edi
movzwl %ax,%esi
call   1030 <CyBtldr_CreateVerifyRowCmd@plt>
mov    %eax,-0x428(%rbp)
xor    %eax,%eax
cmp    -0x428(%rbp),%eax
jne    1208 <CyBtldr_VerifyRow+0xc8>
lea    -0x210(%rbp),%rdi
mov    -0x418(%rbp),%rsi
lea    -0x410(%rbp),%rdx
mov    -0x420(%rbp),%rcx
call   1060 <CyBtldr_TransferData@plt>
mov    %eax,-0x428(%rbp)
xor    %eax,%eax
cmp    -0x428(%rbp),%eax
jne    123d <CyBtldr_VerifyRow+0xfd>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rsi
lea    -0x421(%rbp),%rdx
lea    -0x422(%rbp),%rcx
call   1050 <CyBtldr_ParseVerifyRowCmdResult@plt>
mov    %eax,-0x428(%rbp)
movzbl -0x422(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     1260 <CyBtldr_VerifyRow+0x120>
movzbl -0x422(%rbp),%eax
or     $0x4000,%eax
mov    %eax,-0x428(%rbp)
xor    %eax,%eax
cmp    -0x428(%rbp),%eax
jne    128b <CyBtldr_VerifyRow+0x14b>
movzbl -0x421(%rbp),%eax
movzbl -0x5(%rbp),%ecx
cmp    %ecx,%eax
je     128b <CyBtldr_VerifyRow+0x14b>
movl   $0x8,-0x428(%rbp)
mov    -0x428(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CyBtldr_VerifyRow>:
push   %rbp
push   %r14
push   %rbx
sub    $0x420,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
movb   $0x0,0xf(%rsp)
movb   $0x0,0xe(%rsp)
call   1040 <CyBtldr_ValidateRow@plt>
test   %eax,%eax
jne    11b8 <CyBtldr_VerifyRow+0x78>
movzbl %bl,%edi
movzwl %bp,%esi
lea    0x220(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x10(%rsp),%r8
call   1030 <CyBtldr_CreateVerifyRowCmd@plt>
test   %eax,%eax
jne    11b8 <CyBtldr_VerifyRow+0x78>
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%rcx
lea    0x220(%rsp),%rdi
lea    0x20(%rsp),%rdx
call   1060 <CyBtldr_TransferData@plt>
test   %eax,%eax
je     11d8 <CyBtldr_VerifyRow+0x98>
xor    %edx,%edx
xor    %ecx,%ecx
cmp    %r14b,%dl
setne  %cl
shl    $0x3,%ecx
test   %eax,%eax
cmovne %eax,%ecx
mov    %ecx,%eax
add    $0x420,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdi
lea    0xf(%rsp),%rdx
lea    0xe(%rsp),%rcx
call   1050 <CyBtldr_ParseVerifyRowCmdResult@plt>
movzbl 0xe(%rsp),%ecx
mov    0xf(%rsp),%dl
test   %ecx,%ecx
je     11ba <CyBtldr_VerifyRow+0x7a>
or     $0x4000,%ecx
mov    %ecx,%eax
jmp    11ba <CyBtldr_VerifyRow+0x7a>

LLVM IR (-O0):
define i32 @CyBtldr_VerifyRow(i8 zeroext %0, i16 zeroext %1, i8 zeroext %2) {
%4 = alloca i8
%5 = alloca i16
%6 = alloca i8
%7 = alloca [512 x i8]
%8 = alloca [512 x i8]
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8
%12 = alloca i8
%13 = alloca i32
store i8 %0, i8* %4
store i16 %1, i16* %5
store i8 %2, i8* %6
store i64 0, i64* %9
store i64 0, i64* %10
store i8 0, i8* %11
store i8 0, i8* %12
%14 = load i8, i8* %4
%15 = load i16, i16* %5
%16 = call i32 @CyBtldr_ValidateRow(i8 zeroext %14, i16 zeroext %15)
store i32 %16, i32* %13
%17 = load i32, i32* %13
%18 = icmp eq i32 0, %17
br i1 %18, label %19, label %24
19: ; preds = %3
%20 = load i8, i8* %4
%21 = load i16, i16* %5
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%23 = call i32 @CyBtldr_CreateVerifyRowCmd(i8 zeroext %20, i16 zeroext %21, i8* %22, i64* %9, i64* %10)
store i32 %23, i32* %13
br label %24
24: ; preds = %19, %3
%25 = load i32, i32* %13
%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]* %7, i64 0, i64 0
%29 = load i64, i64* %9
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%31 = load i64, i64* %10
%32 = call i32 @CyBtldr_TransferData(i8* %28, i64 %29, i8* %30, i64 %31)
store i32 %32, i32* %13
br label %33
33: ; preds = %27, %24
%34 = load i32, i32* %13
%35 = icmp eq i32 0, %34
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%38 = load i64, i64* %10
%39 = call i32 @CyBtldr_ParseVerifyRowCmdResult(i8* %37, i64 %38, i8* %11, i8* %12)
store i32 %39, i32* %13
br label %40
40: ; preds = %36, %33
%41 = load i8, i8* %12
%42 = zext i8 %41 to i32
%43 = icmp ne i32 0, %42
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i8, i8* %12
%46 = zext i8 %45 to i32
%47 = or i32 %46, 16384
store i32 %47, i32* %13
br label %48
48: ; preds = %44, %40
%49 = load i32, i32* %13
%50 = icmp eq i32 0, %49
br i1 %50, label %51, label %58
51: ; preds = %48
%52 = load i8, i8* %11
%53 = zext i8 %52 to i32
%54 = load i8, i8* %6
%55 = zext i8 %54 to i32
%56 = icmp ne i32 %53, %55
br i1 %56, label %57, label %58
57: ; preds = %51
store i32 8, i32* %13
br label %58
58: ; preds = %57, %51, %48
%59 = load i32, i32* %13
ret i32 %59
}

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