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

/* Variables and functions */
int /*<<< orphan*/ MFRC522_ClearBitMask(int, int);
int MFRC522_ReadRegister(int);
int /*<<< orphan*/ MFRC522_SetBitMask(int, int);
int /*<<< orphan*/ MFRC522_WriteRegister(int, int);
void MFRC522_CalculateCRC(uint8_t *pIndata, uint8_t len, uint8_t *pOutData) {
  uint8_t i, n;
  MFRC522_ClearBitMask(0x05, 0x04);
  MFRC522_SetBitMask(0x0A, 0x80);
  for (i = 0; i < len; i++) {
    MFRC522_WriteRegister(0x09, *(pIndata + i));
  }
  MFRC522_WriteRegister(0x01, 0x03);
  i = 0xFF;
  do {
    n = MFRC522_ReadRegister(0x05);
    i--;
  } while ((i != 0) && !(n & 0x04));
  pOutData[0] = MFRC522_ReadRegister(0x22);
  pOutData[1] = MFRC522_ReadRegister(0x21);
}


x86 assembly (clang, -O0):
<MFRC522_CalculateCRC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x5,%edi
mov    $0x4,%esi
call   1030 <MFRC522_ClearBitMask@plt>
mov    $0xa,%edi
mov    $0x80,%esi
call   1050 <MFRC522_SetBitMask@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a7 <MFRC522_CalculateCRC+0x67>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    $0x9,%edi
call   1060 <MFRC522_WriteRegister@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <MFRC522_CalculateCRC+0x38>
mov    $0x1,%edi
mov    $0x3,%esi
call   1060 <MFRC522_WriteRegister@plt>
movl   $0xff,-0x1c(%rbp)
mov    $0x5,%edi
call   1040 <MFRC522_ReadRegister@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x21(%rbp)
je     11f3 <MFRC522_CalculateCRC+0xb3>
mov    -0x20(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11bd <MFRC522_CalculateCRC+0x7d>
mov    $0x22,%edi
call   1040 <MFRC522_ReadRegister@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x21,%edi
call   1040 <MFRC522_ReadRegister@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MFRC522_CalculateCRC>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
mov    $0x5,%edi
mov    $0x4,%esi
call   1030 <MFRC522_ClearBitMask@plt>
mov    $0xa,%edi
mov    $0x80,%esi
call   1050 <MFRC522_SetBitMask@plt>
test   %ebp,%ebp
jle    1197 <MFRC522_CalculateCRC+0x57>
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%rbx,4),%esi
mov    $0x9,%edi
call   1060 <MFRC522_WriteRegister@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <MFRC522_CalculateCRC+0x40>
mov    $0x1,%edi
mov    $0x3,%esi
call   1060 <MFRC522_WriteRegister@plt>
mov    $0xffffff02,%ebx
nopl   0x0(%rax,%rax,1)
mov    $0x5,%edi
call   1040 <MFRC522_ReadRegister@plt>
test   %ebx,%ebx
je     11c8 <MFRC522_CalculateCRC+0x88>
and    $0x4,%eax
add    $0x1,%ebx
test   %eax,%eax
je     11b0 <MFRC522_CalculateCRC+0x70>
mov    $0x22,%edi
call   1040 <MFRC522_ReadRegister@plt>
mov    %eax,(%r14)
mov    $0x21,%edi
call   1040 <MFRC522_ReadRegister@plt>
mov    %eax,0x4(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @MFRC522_CalculateCRC(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%9 = call i32 @MFRC522_ClearBitMask(i32 5, i32 4)
%10 = call i32 @MFRC522_SetBitMask(i32 10, i32 128)
store i32 0, i32* %7
br label %11
11: ; preds = %22, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i32*, i32** %4
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = call i32 @MFRC522_WriteRegister(i32 9, i32 %20)
br label %22
22: ; preds = %15
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %11
25: ; preds = %11
%26 = call i32 @MFRC522_WriteRegister(i32 1, i32 3)
store i32 255, i32* %7
br label %27
27: ; preds = %39, %25
%28 = call i32 @MFRC522_ReadRegister(i32 5)
store i32 %28, i32* %8
%29 = load i32, i32* %7
%30 = add nsw i32 %29, -1
store i32 %30, i32* %7
br label %31
31: ; preds = %27
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i32, i32* %8
%36 = and i32 %35, 4
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br label %39
39: ; preds = %34, %31
%40 = phi i1 [ false, %31 ], [ %38, %34 ]
br i1 %40, label %27, label %41
41: ; preds = %39
%42 = call i32 @MFRC522_ReadRegister(i32 34)
%43 = load i32*, i32** %6
%44 = getelementptr inbounds i32, i32* %43, i64 0
store i32 %42, i32* %44
%45 = call i32 @MFRC522_ReadRegister(i32 33)
%46 = load i32*, i32** %6
%47 = getelementptr inbounds i32, i32* %46, i64 1
store i32 %45, i32* %47
ret void
}

LLVM IR (-O2):
define void @MFRC522_CalculateCRC(i32* nocapture %0, i32 %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @MFRC522_ClearBitMask(i32 5, i32 4)
%5 = tail call i32 @MFRC522_SetBitMask(i32 10, i32 128)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %16
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %14, %9 ]
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = load i32, i32* %11
%13 = tail call i32 @MFRC522_WriteRegister(i32 9, i32 %12)
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %16, label %9
16: ; preds = %9, %3
%17 = tail call i32 @MFRC522_WriteRegister(i32 1, i32 3)
br label %18
18: ; preds = %18, %16
%19 = phi i32 [ 255, %16 ], [ %21, %18 ]
%20 = tail call i32 @MFRC522_ReadRegister(i32 5)
%21 = add nsw i32 %19, -1
%22 = icmp ne i32 %21, 0
%23 = and i32 %20, 4
%24 = icmp eq i32 %23, 0
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %18, label %26
26: ; preds = %18
%27 = tail call i32 @MFRC522_ReadRegister(i32 34)
store i32 %27, i32* %2
%28 = tail call i32 @MFRC522_ReadRegister(i32 33)
%29 = getelementptr inbounds i32, i32* %2, i64 1
store i32 %28, i32* %29
ret void
}