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


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

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

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

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