#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 */
char shift_bit(char, char);
char crc7(char cur_val, char next_val) {
  int i;
  for (i = 7; i >= 0; i--)
    cur_val = shift_bit(cur_val, (next_val >> i) & 0x1);
  return cur_val & 0x7f;
}


x86 assembly (clang, -O0):
<crc7>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
movl   $0x7,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1166 <crc7+0x56>
mov    -0x1(%rbp),%al
mov    %al,-0x9(%rbp)
movsbl -0x2(%rbp),%eax
mov    -0x8(%rbp),%ecx
sar    %cl,%eax
mov    -0x9(%rbp),%cl
and    $0x1,%eax
movsbl %cl,%edi
movsbl %al,%esi
call   1030 <shift_bit@plt>
mov    %al,-0x1(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    112b <crc7+0x1b>
movsbl -0x1(%rbp),%eax
and    $0x7f,%eax
movsbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crc7>:
push   %rbx
mov    %esi,%ebx
mov    %ebx,%eax
shr    $0x7,%al
movzbl %al,%esi
call   1030 <shift_bit@plt>
mov    %ebx,%ecx
shr    $0x6,%cl
and    $0x1,%cl
movsbl %al,%edi
movzbl %cl,%esi
call   1030 <shift_bit@plt>
mov    %ebx,%ecx
shr    $0x5,%cl
and    $0x1,%cl
movsbl %al,%edi
movzbl %cl,%esi
call   1030 <shift_bit@plt>
mov    %ebx,%ecx
shr    $0x4,%cl
and    $0x1,%cl
movsbl %al,%edi
movzbl %cl,%esi
call   1030 <shift_bit@plt>
mov    %ebx,%ecx
shr    $0x3,%cl
and    $0x1,%cl
movsbl %al,%edi
movzbl %cl,%esi
call   1030 <shift_bit@plt>
mov    %ebx,%ecx
shr    $0x2,%cl
and    $0x1,%cl
movsbl %al,%edi
movzbl %cl,%esi
call   1030 <shift_bit@plt>
mov    %ebx,%ecx
shr    %cl
and    $0x1,%cl
movsbl %al,%edi
movzbl %cl,%esi
call   1030 <shift_bit@plt>
movsbl %al,%edi
and    $0x1,%ebx
mov    %ebx,%esi
call   1030 <shift_bit@plt>
and    $0x7f,%al
pop    %rbx
ret

LLVM IR (-O0):
define signext i8 @crc7(i8 signext %0, i8 signext %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
store i8 %0, i8* %3
store i8 %1, i8* %4
store i32 7, i32* %5
br label %6
6: ; preds = %18, %2
%7 = load i32, i32* %5
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = load i8, i8* %3
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
%13 = load i32, i32* %5
%14 = ashr i32 %12, %13
%15 = and i32 %14, 1
%16 = trunc i32 %15 to i8
%17 = call signext i8 @shift_bit(i8 signext %10, i8 signext %16)
store i8 %17, i8* %3
br label %18
18: ; preds = %9
%19 = load i32, i32* %5
%20 = add nsw i32 %19, -1
store i32 %20, i32* %5
br label %6
21: ; preds = %6
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = and i32 %23, 127
%25 = trunc i32 %24 to i8
ret i8 %25
}

LLVM IR (-O2):
define signext i8 @crc7(i8 signext %0, i8 signext %1) {
%3 = lshr i8 %1, 7
%4 = tail call signext i8 @shift_bit(i8 signext %0, i8 signext %3)
%5 = lshr i8 %1, 6
%6 = and i8 %5, 1
%7 = tail call signext i8 @shift_bit(i8 signext %4, i8 signext %6)
%8 = lshr i8 %1, 5
%9 = and i8 %8, 1
%10 = tail call signext i8 @shift_bit(i8 signext %7, i8 signext %9)
%11 = lshr i8 %1, 4
%12 = and i8 %11, 1
%13 = tail call signext i8 @shift_bit(i8 signext %10, i8 signext %12)
%14 = lshr i8 %1, 3
%15 = and i8 %14, 1
%16 = tail call signext i8 @shift_bit(i8 signext %13, i8 signext %15)
%17 = lshr i8 %1, 2
%18 = and i8 %17, 1
%19 = tail call signext i8 @shift_bit(i8 signext %16, i8 signext %18)
%20 = lshr i8 %1, 1
%21 = and i8 %20, 1
%22 = tail call signext i8 @shift_bit(i8 signext %19, i8 signext %21)
%23 = and i8 %1, 1
%24 = tail call signext i8 @shift_bit(i8 signext %22, i8 signext %23)
%25 = and i8 %24, 127
ret i8 %25
}