#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 */
scalar_t__ fmem_get_byte(int /*<<< orphan*/);
int /*<<< orphan*/ fmem_set_byte(int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ msg(char *, unsigned long, unsigned long);
void arm_calculate_vector_table_crc(void) {
  int i;
  unsigned long crc;
  unsigned long vector;
  unsigned long adr;
  crc = 0UL;
  adr = 0UL;
  for (i = 0; i < 7; i++) {
    vector = (unsigned long)fmem_get_byte(adr++);
    vector |= ((unsigned long)fmem_get_byte(adr++)) << 8;
    vector |= ((unsigned long)fmem_get_byte(adr++)) << 16;
    vector |= ((unsigned long)fmem_get_byte(adr++)) << 24;
    crc += vector;
  }
  crc = 0 - crc;
  vector = (unsigned long)fmem_get_byte(adr++);
  vector |= ((unsigned long)fmem_get_byte(adr++)) << 8;
  vector |= ((unsigned long)fmem_get_byte(adr++)) << 16;
  vector |= ((unsigned long)fmem_get_byte(adr++)) << 24;
  msg("LPC crc calculated = 0x%08lx, crc found = 0x%08lx", crc, vector);
  adr = 7 * 4;
  fmem_set_byte(adr++, (crc >> 0) & 255);
  fmem_set_byte(adr++, (crc >> 8) & 255);
  fmem_set_byte(adr++, (crc >> 16) & 255);
  fmem_set_byte(adr++, (crc >> 24) & 255);
}


x86 assembly (clang, -O0):
<arm_calculate_vector_table_crc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x7,-0x4(%rbp)
jge    11f3 <arm_calculate_vector_table_crc+0xc3>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x8,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x10,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x18,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114f <arm_calculate_vector_table_crc+0x1f>
xor    %eax,%eax
sub    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x8,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x10,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x18,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd74(%rip),%rdi
call   1050 <msg@plt>
movq   $0x1c,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
shr    $0x0,%rsi
and    $0xff,%rsi
call   1030 <fmem_set_byte@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
shr    $0x8,%rsi
and    $0xff,%rsi
call   1030 <fmem_set_byte@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
shr    $0x10,%rsi
and    $0xff,%rsi
call   1030 <fmem_set_byte@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
shr    $0x18,%rsi
and    $0xff,%rsi
call   1030 <fmem_set_byte@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arm_calculate_vector_table_crc>:
push   %r15
push   %r14
push   %rbx
xor    %edi,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x8,%rax
or     %rax,%rbx
mov    $0x2,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%r14
shl    $0x10,%r14
mov    $0x3,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x18,%rax
or     %rax,%r14
or     %rbx,%r14
mov    $0x4,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%r15
mov    $0x5,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x8,%rax
or     %rax,%r15
mov    $0x6,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%rbx
shl    $0x10,%rbx
mov    $0x7,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x18,%rax
or     %rax,%rbx
or     %r15,%rbx
add    %r14,%rbx
mov    $0x8,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%r15
mov    $0x9,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x8,%rax
or     %rax,%r15
mov    $0xa,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%r14
shl    $0x10,%r14
mov    $0xb,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x18,%rax
or     %rax,%r14
or     %r15,%r14
add    %rbx,%r14
mov    $0xc,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%r15
mov    $0xd,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x8,%rax
or     %rax,%r15
mov    $0xe,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%rbx
shl    $0x10,%rbx
mov    $0xf,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x18,%rax
or     %rax,%rbx
or     %r15,%rbx
add    %r14,%rbx
mov    $0x10,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%r15
mov    $0x11,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x8,%rax
or     %rax,%r15
mov    $0x12,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%r14
shl    $0x10,%r14
mov    $0x13,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x18,%rax
or     %rax,%r14
or     %r15,%r14
add    %rbx,%r14
mov    $0x14,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%rbx
mov    $0x15,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x8,%rax
or     %rax,%rbx
mov    $0x16,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%r15
shl    $0x10,%r15
mov    $0x17,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x18,%rax
or     %rax,%r15
or     %rbx,%r15
add    %r14,%r15
mov    $0x18,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%r14
mov    $0x19,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x8,%rax
or     %rax,%r14
mov    $0x1a,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%rbx
shl    $0x10,%rbx
mov    $0x1b,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x18,%rax
or     %rax,%rbx
or     %r14,%rbx
add    %r15,%rbx
neg    %rbx
mov    %rbx,%r15
mov    $0x1c,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%r14
mov    $0x1d,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x8,%rax
or     %rax,%r14
mov    $0x1e,%edi
call   1040 <fmem_get_byte@plt>
mov    %rax,%rbx
shl    $0x10,%rbx
mov    $0x1f,%edi
call   1040 <fmem_get_byte@plt>
shl    $0x18,%rax
or     %rax,%rbx
or     %r14,%rbx
lea    0xc97(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <msg@plt>
mov    %r15,%rbx
movzbl %bl,%esi
mov    $0x1c,%edi
call   1030 <fmem_set_byte@plt>
movzbl %bh,%esi
mov    $0x1d,%edi
call   1030 <fmem_set_byte@plt>
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%esi
mov    $0x1e,%edi
call   1030 <fmem_set_byte@plt>
shr    $0x18,%ebx
mov    $0x1f,%edi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fmem_set_byte@plt>

LLVM IR (-O0):
@.str = [50 x i8] c"LPC crc calculated = 0x%08lx, crc found = 0x%08lx\00"
define void @arm_calculate_vector_table_crc() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 0, i64* %2
store i64 0, i64* %4
store i32 0, i32* %1
br label %5
5: ; preds = %37, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 7
br i1 %7, label %8, label %40
8: ; preds = %5
%9 = load i64, i64* %4
%10 = add i64 %9, 1
store i64 %10, i64* %4
%11 = trunc i64 %9 to i32
%12 = call i64 @fmem_get_byte(i32 %11)
store i64 %12, i64* %3
%13 = load i64, i64* %4
%14 = add i64 %13, 1
store i64 %14, i64* %4
%15 = trunc i64 %13 to i32
%16 = call i64 @fmem_get_byte(i32 %15)
%17 = shl i64 %16, 8
%18 = load i64, i64* %3
%19 = or i64 %18, %17
store i64 %19, i64* %3
%20 = load i64, i64* %4
%21 = add i64 %20, 1
store i64 %21, i64* %4
%22 = trunc i64 %20 to i32
%23 = call i64 @fmem_get_byte(i32 %22)
%24 = shl i64 %23, 16
%25 = load i64, i64* %3
%26 = or i64 %25, %24
store i64 %26, i64* %3
%27 = load i64, i64* %4
%28 = add i64 %27, 1
store i64 %28, i64* %4
%29 = trunc i64 %27 to i32
%30 = call i64 @fmem_get_byte(i32 %29)
%31 = shl i64 %30, 24
%32 = load i64, i64* %3
%33 = or i64 %32, %31
store i64 %33, i64* %3
%34 = load i64, i64* %3
%35 = load i64, i64* %2
%36 = add i64 %35, %34
store i64 %36, i64* %2
br label %37
37: ; preds = %8
%38 = load i32, i32* %1
%39 = add nsw i32 %38, 1
store i32 %39, i32* %1
br label %5
40: ; preds = %5
%41 = load i64, i64* %2
%42 = sub i64 0, %41
store i64 %42, i64* %2
%43 = load i64, i64* %4
%44 = add i64 %43, 1
store i64 %44, i64* %4
%45 = trunc i64 %43 to i32
%46 = call i64 @fmem_get_byte(i32 %45)
store i64 %46, i64* %3
%47 = load i64, i64* %4
%48 = add i64 %47, 1
store i64 %48, i64* %4
%49 = trunc i64 %47 to i32
%50 = call i64 @fmem_get_byte(i32 %49)
%51 = shl i64 %50, 8
%52 = load i64, i64* %3
%53 = or i64 %52, %51
store i64 %53, i64* %3
%54 = load i64, i64* %4
%55 = add i64 %54, 1
store i64 %55, i64* %4
%56 = trunc i64 %54 to i32
%57 = call i64 @fmem_get_byte(i32 %56)
%58 = shl i64 %57, 16
%59 = load i64, i64* %3
%60 = or i64 %59, %58
store i64 %60, i64* %3
%61 = load i64, i64* %4
%62 = add i64 %61, 1
store i64 %62, i64* %4
%63 = trunc i64 %61 to i32
%64 = call i64 @fmem_get_byte(i32 %63)
%65 = shl i64 %64, 24
%66 = load i64, i64* %3
%67 = or i64 %66, %65
store i64 %67, i64* %3
%68 = load i64, i64* %2
%69 = load i64, i64* %3
%70 = call i32 @msg(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i64 %68, i64 %69)
store i64 28, i64* %4
%71 = load i64, i64* %4
%72 = add i64 %71, 1
store i64 %72, i64* %4
%73 = trunc i64 %71 to i32
%74 = load i64, i64* %2
%75 = lshr i64 %74, 0
%76 = and i64 %75, 255
%77 = call i32 @fmem_set_byte(i32 %73, i64 %76)
%78 = load i64, i64* %4
%79 = add i64 %78, 1
store i64 %79, i64* %4
%80 = trunc i64 %78 to i32
%81 = load i64, i64* %2
%82 = lshr i64 %81, 8
%83 = and i64 %82, 255
%84 = call i32 @fmem_set_byte(i32 %80, i64 %83)
%85 = load i64, i64* %4
%86 = add i64 %85, 1
store i64 %86, i64* %4
%87 = trunc i64 %85 to i32
%88 = load i64, i64* %2
%89 = lshr i64 %88, 16
%90 = and i64 %89, 255
%91 = call i32 @fmem_set_byte(i32 %87, i64 %90)
%92 = load i64, i64* %4
%93 = add i64 %92, 1
store i64 %93, i64* %4
%94 = trunc i64 %92 to i32
%95 = load i64, i64* %2
%96 = lshr i64 %95, 24
%97 = and i64 %96, 255
%98 = call i32 @fmem_set_byte(i32 %94, i64 %97)
ret void
}

LLVM IR (-O2):
@.str = [50 x i8] c"LPC crc calculated = 0x%08lx, crc found = 0x%08lx\00"
define void @arm_calculate_vector_table_crc() {
%1 = tail call i64 @fmem_get_byte(i32 0)
%2 = tail call i64 @fmem_get_byte(i32 1)
%3 = shl i64 %2, 8
%4 = or i64 %3, %1
%5 = tail call i64 @fmem_get_byte(i32 2)
%6 = shl i64 %5, 16
%7 = or i64 %4, %6
%8 = tail call i64 @fmem_get_byte(i32 3)
%9 = shl i64 %8, 24
%10 = or i64 %7, %9
%11 = tail call i64 @fmem_get_byte(i32 4)
%12 = tail call i64 @fmem_get_byte(i32 5)
%13 = shl i64 %12, 8
%14 = or i64 %13, %11
%15 = tail call i64 @fmem_get_byte(i32 6)
%16 = shl i64 %15, 16
%17 = or i64 %14, %16
%18 = tail call i64 @fmem_get_byte(i32 7)
%19 = shl i64 %18, 24
%20 = or i64 %17, %19
%21 = add i64 %20, %10
%22 = tail call i64 @fmem_get_byte(i32 8)
%23 = tail call i64 @fmem_get_byte(i32 9)
%24 = shl i64 %23, 8
%25 = or i64 %24, %22
%26 = tail call i64 @fmem_get_byte(i32 10)
%27 = shl i64 %26, 16
%28 = or i64 %25, %27
%29 = tail call i64 @fmem_get_byte(i32 11)
%30 = shl i64 %29, 24
%31 = or i64 %28, %30
%32 = add i64 %31, %21
%33 = tail call i64 @fmem_get_byte(i32 12)
%34 = tail call i64 @fmem_get_byte(i32 13)
%35 = shl i64 %34, 8
%36 = or i64 %35, %33
%37 = tail call i64 @fmem_get_byte(i32 14)
%38 = shl i64 %37, 16
%39 = or i64 %36, %38
%40 = tail call i64 @fmem_get_byte(i32 15)
%41 = shl i64 %40, 24
%42 = or i64 %39, %41
%43 = add i64 %42, %32
%44 = tail call i64 @fmem_get_byte(i32 16)
%45 = tail call i64 @fmem_get_byte(i32 17)
%46 = shl i64 %45, 8
%47 = or i64 %46, %44
%48 = tail call i64 @fmem_get_byte(i32 18)
%49 = shl i64 %48, 16
%50 = or i64 %47, %49
%51 = tail call i64 @fmem_get_byte(i32 19)
%52 = shl i64 %51, 24
%53 = or i64 %50, %52
%54 = add i64 %53, %43
%55 = tail call i64 @fmem_get_byte(i32 20)
%56 = tail call i64 @fmem_get_byte(i32 21)
%57 = shl i64 %56, 8
%58 = or i64 %57, %55
%59 = tail call i64 @fmem_get_byte(i32 22)
%60 = shl i64 %59, 16
%61 = or i64 %58, %60
%62 = tail call i64 @fmem_get_byte(i32 23)
%63 = shl i64 %62, 24
%64 = or i64 %61, %63
%65 = add i64 %64, %54
%66 = tail call i64 @fmem_get_byte(i32 24)
%67 = tail call i64 @fmem_get_byte(i32 25)
%68 = shl i64 %67, 8
%69 = or i64 %68, %66
%70 = tail call i64 @fmem_get_byte(i32 26)
%71 = shl i64 %70, 16
%72 = or i64 %69, %71
%73 = tail call i64 @fmem_get_byte(i32 27)
%74 = shl i64 %73, 24
%75 = or i64 %72, %74
%76 = add i64 %75, %65
%77 = sub i64 0, %76
%78 = tail call i64 @fmem_get_byte(i32 28)
%79 = tail call i64 @fmem_get_byte(i32 29)
%80 = shl i64 %79, 8
%81 = or i64 %80, %78
%82 = tail call i64 @fmem_get_byte(i32 30)
%83 = shl i64 %82, 16
%84 = or i64 %81, %83
%85 = tail call i64 @fmem_get_byte(i32 31)
%86 = shl i64 %85, 24
%87 = or i64 %84, %86
%88 = tail call i32 @msg(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i64 %77, i64 %87)
%89 = and i64 %77, 255
%90 = tail call i32 @fmem_set_byte(i32 28, i64 %89)
%91 = lshr i64 %77, 8
%92 = and i64 %91, 255
%93 = tail call i32 @fmem_set_byte(i32 29, i64 %92)
%94 = lshr i64 %77, 16
%95 = and i64 %94, 255
%96 = tail call i32 @fmem_set_byte(i32 30, i64 %95)
%97 = lshr i64 %77, 24
%98 = and i64 %97, 255
%99 = tail call i32 @fmem_set_byte(i32 31, i64 %98)
ret void
}