#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_FromAscii(unsigned int, unsigned char *, unsigned short *,
                      unsigned char *);
int CyBtldr_ParseHeader(unsigned int bufSize, unsigned char *buffer,
                        unsigned long *siliconId, unsigned char *siliconRev,
                        unsigned char *chksum) {
  const unsigned int LENGTH_ID = 5;
  const unsigned int LENGTH_CHKSUM = LENGTH_ID + 1;
  unsigned short rowSize;
  unsigned char rowData[768];
  int err = CyBtldr_FromAscii(bufSize, buffer, &rowSize, rowData);
  if (0x00 == err) {
    if (rowSize >= LENGTH_CHKSUM)
      *chksum = rowData[5];
    if (rowSize >= LENGTH_ID) {
      *siliconId = (rowData[0] << 24) | (rowData[1] << 16) | (rowData[2] << 8) |
                   (rowData[3]);
      *siliconRev = rowData[4];
    } else
      err = 0x03;
  }
  return err;
}


x86 assembly (clang, -O0):
<CyBtldr_ParseHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x5,-0x2c(%rbp)
movl   $0x6,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x340(%rbp),%rcx
lea    -0x32(%rbp),%rdx
call   1030 <CyBtldr_FromAscii@plt>
mov    %eax,-0x344(%rbp)
xor    %eax,%eax
cmp    -0x344(%rbp),%eax
jne    11e2 <CyBtldr_ParseHeader+0xd2>
movzwl -0x32(%rbp),%eax
cmp    $0x6,%eax
jb     1180 <CyBtldr_ParseHeader+0x70>
mov    -0x33b(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
movzwl -0x32(%rbp),%eax
cmp    $0x5,%eax
jb     11d3 <CyBtldr_ParseHeader+0xc3>
movzbl -0x340(%rbp),%eax
shl    $0x18,%eax
movzbl -0x33f(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movzbl -0x33e(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movzbl -0x33d(%rbp),%ecx
or     %ecx,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x33c(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
jmp    11dd <CyBtldr_ParseHeader+0xcd>
movl   $0x3,-0x344(%rbp)
jmp    11e2 <CyBtldr_ParseHeader+0xd2>
mov    -0x344(%rbp),%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CyBtldr_ParseHeader>:
push   %r15
push   %r14
push   %rbx
sub    $0x310,%rsp
mov    %r8,%rbx
mov    %rcx,%r14
mov    %rdx,%r15
lea    0xe(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1030 <CyBtldr_FromAscii@plt>
test   %eax,%eax
jne    118b <CyBtldr_ParseHeader+0x7b>
movzwl 0xe(%rsp),%ecx
cmp    $0x6,%cx
jb     114b <CyBtldr_ParseHeader+0x3b>
mov    0x15(%rsp),%al
mov    %al,(%rbx)
jmp    1156 <CyBtldr_ParseHeader+0x46>
mov    $0x3,%eax
cmp    $0x5,%cx
jne    118b <CyBtldr_ParseHeader+0x7b>
mov    0x10(%rsp),%eax
shl    $0x18,%eax
movzbl 0x11(%rsp),%ecx
shl    $0x10,%rcx
cltq
or     %rcx,%rax
movzbl 0x12(%rsp),%ecx
shl    $0x8,%rcx
or     %rax,%rcx
movzbl 0x13(%rsp),%eax
or     %rcx,%rax
mov    %rax,(%r15)
mov    0x14(%rsp),%al
mov    %al,(%r14)
xor    %eax,%eax
add    $0x310,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @CyBtldr_ParseHeader(i32 %0, i8* %1, i64* nocapture writeonly %2, i8* nocapture writeonly %3, i8* nocapture writeonly %4) {
%6 = alloca i16
%7 = alloca [768 x i8]
%8 = bitcast i16* %6 to i8*
%9 = getelementptr inbounds [768 x i8], [768 x i8]* %7, i64 0, i64 0
%10 = call i32 @CyBtldr_FromAscii(i32 %0, i8* %1, i16* %6, i8* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %41
12: ; preds = %5
%13 = load i16, i16* %6
%14 = icmp ugt i16 %13, 5
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = getelementptr inbounds [768 x i8], [768 x i8]* %7, i64 0, i64 5
%17 = load i8, i8* %16
store i8 %17, i8* %4
br label %20
18: ; preds = %12
%19 = icmp eq i16 %13, 5
br i1 %19, label %20, label %41
20: ; preds = %15, %18
%21 = load i8, i8* %9
%22 = zext i8 %21 to i32
%23 = shl nuw i32 %22, 24
%24 = getelementptr inbounds [768 x i8], [768 x i8]* %7, i64 0, i64 1
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = shl nuw nsw i32 %26, 16
%28 = or i32 %27, %23
%29 = getelementptr inbounds [768 x i8], [768 x i8]* %7, i64 0, i64 2
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = shl nuw nsw i32 %31, 8
%33 = or i32 %28, %32
%34 = getelementptr inbounds [768 x i8], [768 x i8]* %7, i64 0, i64 3
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = or i32 %33, %36
%38 = sext i32 %37 to i64
store i64 %38, i64* %2
%39 = getelementptr inbounds [768 x i8], [768 x i8]* %7, i64 0, i64 4
%40 = load i8, i8* %39
store i8 %40, i8* %3
br label %41
41: ; preds = %18, %20, %5
%42 = phi i32 [ 0, %20 ], [ %10, %5 ], [ 3, %18 ]
ret i32 %42
}