#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ ror6502(int *, int *);
uint16_t _sum_calc(uint16_t cksum, uint8_t byte) {
  uint8_t _tmp4 = cksum & 0xFF;
  uint8_t _tmp5 = (cksum >> 8);
  for (int i = 0; i < 8; i++) {
    bool carry = (byte & 1);
    byte >>= 1;
    ror6502(&_tmp5, &carry);
    ror6502(&_tmp4, &carry);
    if (carry) {
      _tmp4 ^= 0x05;
      _tmp5 ^= 0xC0;
    }
  }
  uint16_t r = _tmp4 + (_tmp5 << 8);
  return r;
}


x86 assembly (clang, -O0):
<_sum_calc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    11a0 <_sum_calc+0x90>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <ror6502@plt>
lea    -0xc(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <ror6502@plt>
cmpl   $0x0,-0x18(%rbp)
je     118d <_sum_calc+0x7d>
mov    -0xc(%rbp),%eax
xor    $0x5,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
xor    $0xc0,%eax
mov    %eax,-0x10(%rbp)
jmp    1192 <_sum_calc+0x82>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <_sum_calc+0x29>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sum_calc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
movzbl %dil,%eax
mov    %eax,0x8(%rsp)
sar    $0x8,%edi
mov    %edi,0x4(%rsp)
mov    $0x8,%ebp
lea    0x4(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
jmp    1157 <_sum_calc+0x47>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
sar    %ebx
add    $0xffffffff,%ebp
je     1189 <_sum_calc+0x79>
mov    %ebx,%eax
and    $0x1,%eax
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <ror6502@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <ror6502@plt>
cmpl   $0x0,0xc(%rsp)
je     1150 <_sum_calc+0x40>
xorb   $0x5,0x8(%rsp)
xorb   $0xc0,0x4(%rsp)
jmp    1150 <_sum_calc+0x40>
mov    0x4(%rsp),%eax
shl    $0x8,%eax
add    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_sum_calc(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%10 = load i32, i32* %3
%11 = and i32 %10, 255
store i32 %11, i32* %5
%12 = load i32, i32* %3
%13 = ashr i32 %12, 8
store i32 %13, i32* %6
store i32 0, i32* %7
br label %14
14: ; preds = %32, %2
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 8
br i1 %16, label %17, label %35
17: ; preds = %14
%18 = load i32, i32* %4
%19 = and i32 %18, 1
store i32 %19, i32* %8
%20 = load i32, i32* %4
%21 = ashr i32 %20, 1
store i32 %21, i32* %4
%22 = call i32 @ror6502(i32* %6, i32* %8)
%23 = call i32 @ror6502(i32* %5, i32* %8)
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %17
%27 = load i32, i32* %5
%28 = xor i32 %27, 5
store i32 %28, i32* %5
%29 = load i32, i32* %6
%30 = xor i32 %29, 192
store i32 %30, i32* %6
br label %31
31: ; preds = %26, %17
br label %32
32: ; preds = %31
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %14
35: ; preds = %14
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = shl i32 %37, 8
%39 = add nsw i32 %36, %38
store i32 %39, i32* %9
%40 = load i32, i32* %9
ret i32 %40
}

LLVM IR (-O2):
define i32 @_sum_calc(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = and i32 %0, 255
store i32 %7, i32* %3
%8 = bitcast i32* %4 to i8*
%9 = ashr i32 %0, 8
store i32 %9, i32* %4
%10 = bitcast i32* %5 to i8*
br label %16
11: ; preds = %30
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = shl i32 %13, 8
%15 = add nsw i32 %14, %12
ret i32 %15
16: ; preds = %2, %30
%17 = phi i32 [ %1, %2 ], [ %20, %30 ]
%18 = phi i32 [ 0, %2 ], [ %31, %30 ]
%19 = and i32 %17, 1
store i32 %19, i32* %5
%20 = ashr i32 %17, 1
%21 = call i32 @ror6502(i32* %4, i32* %5)
%22 = call i32 @ror6502(i32* %3, i32* %5)
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %16
%26 = load i32, i32* %3
%27 = xor i32 %26, 5
store i32 %27, i32* %3
%28 = load i32, i32* %4
%29 = xor i32 %28, 192
store i32 %29, i32* %4
br label %30
30: ; preds = %25, %16
%31 = add nuw nsw i32 %18, 1
%32 = icmp eq i32 %31, 8
br i1 %32, label %11, label %16
}