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

/* Variables and functions */
int /*<<< orphan*/ clear_crc();
int /*<<< orphan*/ do_crc16(int /*<<< orphan*/);
int /*<<< orphan*/ get_crc_h();
int /*<<< orphan*/ get_crc_l();
void update_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++);
  }
  *ptr++ = get_crc_h();
  *ptr++ = get_crc_l();
}


x86 assembly (clang, -O0):
<update_struct_crc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <clear_crc@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    119a <update_struct_crc+0x5a>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%edi
call   1040 <do_crc16@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1165 <update_struct_crc+0x25>
mov    $0x0,%al
call   1030 <get_crc_h@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
mov    $0x0,%al
call   1060 <get_crc_l@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_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 <update_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 <update_struct_crc+0x20>
xor    %eax,%eax
call   1030 <get_crc_h@plt>
mov    %eax,(%rbx)
xor    %eax,%eax
call   1060 <get_crc_l@plt>
mov    %eax,0x4(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @update_struct_crc(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32*, i32** %3
store i32* %7, i32** %6
%8 = call i32 (...) @clear_crc()
store i32 0, i32* %5
br label %9
9: ; preds = %19, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 2
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %22
14: ; preds = %9
%15 = load i32*, i32** %6
%16 = getelementptr inbounds i32, i32* %15, i32 1
store i32* %16, i32** %6
%17 = load i32, i32* %15
%18 = call i32 @do_crc16(i32 %17)
br label %19
19: ; preds = %14
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %9
22: ; preds = %9
%23 = call i32 (...) @get_crc_h()
%24 = load i32*, i32** %6
%25 = getelementptr inbounds i32, i32* %24, i32 1
store i32* %25, i32** %6
store i32 %23, i32* %24
%26 = call i32 (...) @get_crc_l()
%27 = load i32*, i32** %6
%28 = getelementptr inbounds i32, i32* %27, i32 1
store i32* %28, i32** %6
store i32 %26, i32* %27
ret void
}

LLVM IR (-O2):
define void @update_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 = tail call i32 (...) @get_crc_h()
%17 = getelementptr inbounds i32, i32* %15, i64 1
store i32 %16, i32* %15
%18 = tail call i32 (...) @get_crc_l()
store i32 %18, i32* %17
ret void
}