#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 */
unsigned char applegcr_decode4and4(unsigned char, unsigned char);
unsigned char applegcr_calc_eor(unsigned char *buff, unsigned int len) {
  unsigned char result;
  unsigned char decoded;
  unsigned int i;
  result = 0;
  for (i = 0; i < (len / 2); i++) {
    decoded = applegcr_decode4and4(buff[i * 2], buff[(i * 2) + 1]);
    result = result ^ decoded;
  }
  return result;
}


x86 assembly (clang, -O0):
<applegcr_calc_eor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
jae    1183 <applegcr_calc_eor+0x73>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movzbl %dl,%edi
movzbl (%rax,%rcx,1),%esi
call   1030 <applegcr_decode4and4@plt>
mov    %al,-0xe(%rbp)
movzbl -0xd(%rbp),%eax
movzbl -0xe(%rbp),%ecx
xor    %ecx,%eax
mov    %al,-0xd(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112a <applegcr_calc_eor+0x1a>
movzbl -0xd(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<applegcr_calc_eor>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%esi
jae    1120 <applegcr_calc_eor+0x10>
xor    %ebp,%ebp
jmp    114c <applegcr_calc_eor+0x3c>
mov    %esi,%r14d
mov    %rdi,%r15
shr    %r14d
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   (%rax)
movzbl (%r15,%rbx,2),%edi
movzbl 0x1(%r15,%rbx,2),%esi
call   1030 <applegcr_decode4and4@plt>
xor    %al,%bpl
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <applegcr_calc_eor+0x20>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @applegcr_calc_eor(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8 0, i8* %5
store i32 0, i32* %7
br label %8
8: ; preds = %34, %2
%9 = load i32, i32* %7
%10 = load i32, i32* %4
%11 = udiv i32 %10, 2
%12 = icmp ult i32 %9, %11
br i1 %12, label %13, label %37
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = load i32, i32* %7
%16 = mul i32 %15, 2
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = load i8, i8* %18
%20 = load i8*, i8** %3
%21 = load i32, i32* %7
%22 = mul i32 %21, 2
%23 = add i32 %22, 1
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
%26 = load i8, i8* %25
%27 = call zeroext i8 @applegcr_decode4and4(i8 zeroext %19, i8 zeroext %26)
store i8 %27, i8* %6
%28 = load i8, i8* %5
%29 = zext i8 %28 to i32
%30 = load i8, i8* %6
%31 = zext i8 %30 to i32
%32 = xor i32 %29, %31
%33 = trunc i32 %32 to i8
store i8 %33, i8* %5
br label %34
34: ; preds = %13
%35 = load i32, i32* %7
%36 = add i32 %35, 1
store i32 %36, i32* %7
br label %8
37: ; preds = %8
%38 = load i8, i8* %5
ret i8 %38
}

LLVM IR (-O2):
define zeroext i8 @applegcr_calc_eor(i8* nocapture %0, i32 %1) {
%3 = icmp ult i32 %1, 2
br i1 %3, label %20, label %4
4: ; preds = %2
%5 = lshr i32 %1, 1
%6 = zext i32 %5 to i64
br label %7
7: ; preds = %4, %7
%8 = phi i64 [ 0, %4 ], [ %18, %7 ]
%9 = phi i8 [ 0, %4 ], [ %17, %7 ]
%10 = shl nuw i64 %8, 1
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = or i64 %10, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = tail call zeroext i8 @applegcr_decode4and4(i8 zeroext %12, i8 zeroext %15)
%17 = xor i8 %16, %9
%18 = add nuw nsw i64 %8, 1
%19 = icmp eq i64 %18, %6
br i1 %19, label %20, label %7
20: ; preds = %7, %2
%21 = phi i8 [ 0, %2 ], [ %17, %7 ]
ret i8 %21
}