#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 */
unsigned short CyBtldr_ComputeChecksum(unsigned char *, unsigned int const);
int CyBtldr_CreateGetFlashSizeCmd(unsigned char arrayId, unsigned char *cmdBuf,
                                  unsigned long *cmdSize,
                                  unsigned long *resSize) {
  const unsigned long RESULT_DATA_SIZE = 4;
  const unsigned long COMMAND_DATA_SIZE = 1;
  const unsigned int COMMAND_SIZE = 0x07 + COMMAND_DATA_SIZE;
  unsigned short checksum;
  *resSize = 0x07 + RESULT_DATA_SIZE;
  *cmdSize = COMMAND_SIZE;
  cmdBuf[0] = 0x01;
  cmdBuf[1] = 0x32;
  cmdBuf[2] = (unsigned char)COMMAND_DATA_SIZE;
  cmdBuf[3] = (unsigned char)(COMMAND_DATA_SIZE >> 8);
  cmdBuf[4] = arrayId;
  checksum = CyBtldr_ComputeChecksum(cmdBuf, COMMAND_SIZE - 3);
  cmdBuf[5] = (unsigned char)checksum;
  cmdBuf[6] = (unsigned char)(checksum >> 8);
  cmdBuf[7] = 0x17;
  return 0x00;
}


x86 assembly (clang, -O0):
<CyBtldr_CreateGetFlashSizeCmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x4,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
movl   $0x8,-0x34(%rbp)
mov    -0x20(%rbp),%rax
movq   $0xb,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x8,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x1,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x32,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x1,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x1(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
call   1030 <CyBtldr_ComputeChecksum@plt>
mov    %ax,-0x36(%rbp)
mov    -0x36(%rbp),%ax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x5(%rax)
movzwl -0x36(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x10(%rbp),%rax
movb   $0x17,0x7(%rax)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CyBtldr_CreateGetFlashSizeCmd>:
push   %rbx
mov    %rsi,%rbx
movq   $0xb,(%rcx)
movq   $0x8,(%rdx)
movl   $0x13201,(%rsi)
mov    %dil,0x4(%rsi)
mov    %rsi,%rdi
mov    $0x5,%esi
call   1030 <CyBtldr_ComputeChecksum@plt>
mov    %al,0x5(%rbx)
mov    %ah,0x6(%rbx)
movb   $0x17,0x7(%rbx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @CyBtldr_CreateGetFlashSizeCmd(i8 zeroext %0, i8* %1, i64* %2, i64* %3) {
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i16
store i8 %0, i8* %5
store i8* %1, i8** %6
store i64* %2, i64** %7
store i64* %3, i64** %8
store i64 4, i64* %9
store i64 1, i64* %10
store i32 8, i32* %11
%13 = load i64*, i64** %8
store i64 11, i64* %13
%14 = load i64*, i64** %7
store i64 8, i64* %14
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 1, i8* %16
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 50, i8* %18
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 2
store i8 1, i8* %20
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 3
store i8 0, i8* %22
%23 = load i8, i8* %5
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 4
store i8 %23, i8* %25
%26 = load i8*, i8** %6
%27 = call zeroext i16 @CyBtldr_ComputeChecksum(i8* %26, i32 5)
store i16 %27, i16* %12
%28 = load i16, i16* %12
%29 = trunc i16 %28 to i8
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 5
store i8 %29, i8* %31
%32 = load i16, i16* %12
%33 = zext i16 %32 to i32
%34 = ashr i32 %33, 8
%35 = trunc i32 %34 to i8
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i64 6
store i8 %35, i8* %37
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i64 7
store i8 23, i8* %39
ret i32 0
}

LLVM IR (-O2):
define i32 @CyBtldr_CreateGetFlashSizeCmd(i8 zeroext %0, i8* %1, i64* nocapture writeonly %2, i64* nocapture writeonly %3) {
store i64 11, i64* %3
store i64 8, i64* %2
store i8 1, i8* %1
%5 = getelementptr inbounds i8, i8* %1, i64 1
store i8 50, i8* %5
%6 = getelementptr inbounds i8, i8* %1, i64 2
store i8 1, i8* %6
%7 = getelementptr inbounds i8, i8* %1, i64 3
store i8 0, i8* %7
%8 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %0, i8* %8
%9 = tail call zeroext i16 @CyBtldr_ComputeChecksum(i8* %1, i32 5)
%10 = trunc i16 %9 to i8
%11 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %10, i8* %11
%12 = lshr i16 %9, 8
%13 = trunc i16 %12 to i8
%14 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %13, i8* %14
%15 = getelementptr inbounds i8, i8* %1, i64 7
store i8 23, i8* %15
ret i32 0
}