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


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

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

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

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