#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 */
typedef int uint8_t;
typedef int int16_t;

/* Variables and functions */
int /*<<< orphan*/ clear_crc();
int /*<<< orphan*/ do_crc16(int /*<<< orphan*/);
scalar_t__ get_crc_h();
scalar_t__ get_crc_l();
uint8_t check_struct_crc(uint8_t *sp, int16_t size) {
  int16_t i;
  uint8_t *ptr = sp;
  clear_crc();
  for (i = 0; i < size - 2; i++) {
    do_crc16(*ptr++);
  }
  if (*ptr++ != get_crc_h())
    return 1;
  ;
  if (*ptr++ != get_crc_l())
    return 1;
  ;
  return 0;
}


x86 assembly (clang, -O0):
<check_struct_crc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <clear_crc@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    119a <check_struct_crc+0x5a>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%edi
call   1040 <do_crc16@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1165 <check_struct_crc+0x25>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
movslq (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <get_crc_h@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     11d3 <check_struct_crc+0x93>
movl   $0x1,-0x4(%rbp)
jmp    1213 <check_struct_crc+0xd3>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
movslq (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1060 <get_crc_l@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
je     120c <check_struct_crc+0xcc>
movl   $0x1,-0x4(%rbp)
jmp    1213 <check_struct_crc+0xd3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_struct_crc>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <clear_crc@plt>
cmp    $0x3,%ebp
jl     1170 <check_struct_crc+0x30>
add    $0xfffffffe,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%edi
add    $0x4,%rbx
call   1040 <do_crc16@plt>
add    $0xffffffff,%ebp
jne    1160 <check_struct_crc+0x20>
movslq (%rbx),%rbp
xor    %eax,%eax
call   1030 <get_crc_h@plt>
mov    %rax,%rcx
mov    $0x1,%eax
cmp    %rbp,%rcx
jne    119d <check_struct_crc+0x5d>
movslq 0x4(%rbx),%rbx
xor    %eax,%eax
call   1060 <get_crc_l@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rbx,%rcx
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_struct_crc(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32*, i32** %4
store i32* %8, i32** %7
%9 = call i32 (...) @clear_crc()
store i32 0, i32* %6
br label %10
10: ; preds = %20, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = sub nsw i32 %12, 2
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %23
15: ; preds = %10
%16 = load i32*, i32** %7
%17 = getelementptr inbounds i32, i32* %16, i32 1
store i32* %17, i32** %7
%18 = load i32, i32* %16
%19 = call i32 @do_crc16(i32 %18)
br label %20
20: ; preds = %15
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %10
23: ; preds = %10
%24 = load i32*, i32** %7
%25 = getelementptr inbounds i32, i32* %24, i32 1
store i32* %25, i32** %7
%26 = load i32, i32* %24
%27 = sext i32 %26 to i64
%28 = call i64 (...) @get_crc_h()
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %23
store i32 1, i32* %3
br label %40
31: ; preds = %23
%32 = load i32*, i32** %7
%33 = getelementptr inbounds i32, i32* %32, i32 1
store i32* %33, i32** %7
%34 = load i32, i32* %32
%35 = sext i32 %34 to i64
%36 = call i64 (...) @get_crc_l()
%37 = icmp ne i64 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %31
store i32 1, i32* %3
br label %40
39: ; preds = %31
store i32 0, i32* %3
br label %40
40: ; preds = %39, %38, %30
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
define i32 @check_struct_crc(i32* nocapture %0, i32 %1) {
%3 = tail call i32 (...) @clear_crc()
%4 = add i32 %1, -2
%5 = icmp sgt i32 %1, 2
br i1 %5, label %6, label %14
6: ; preds = %2, %6
%7 = phi i32* [ %9, %6 ], [ %0, %2 ]
%8 = phi i32 [ %12, %6 ], [ 0, %2 ]
%9 = getelementptr inbounds i32, i32* %7, i64 1
%10 = load i32, i32* %7
%11 = tail call i32 @do_crc16(i32 %10)
%12 = add nuw nsw i32 %8, 1
%13 = icmp eq i32 %12, %4
br i1 %13, label %14, label %6
14: ; preds = %6, %2
%15 = phi i32* [ %0, %2 ], [ %9, %6 ]
%16 = load i32, i32* %15
%17 = sext i32 %16 to i64
%18 = tail call i64 (...) @get_crc_h()
%19 = icmp eq i64 %18, %17
br i1 %19, label %20, label %27
20: ; preds = %14
%21 = getelementptr inbounds i32, i32* %15, i64 1
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = tail call i64 (...) @get_crc_l()
%25 = icmp ne i64 %24, %23
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %20, %14
%28 = phi i32 [ 1, %14 ], [ %26, %20 ]
ret i32 %28
}