#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 */
int /*<<< orphan*/ ClearBitMask(int, int);
unsigned char Read_MFRC522(int);
int /*<<< orphan*/ SetBitMask(int, int);
int /*<<< orphan*/ Write_MFRC522(int, int);
void CalulateCRC(unsigned char *pIndata, unsigned char len,
                 unsigned char *pOutData) {
  unsigned char i, n;
  ClearBitMask(0x05, 0x04);
  SetBitMask(0x0A, 0x80);
  for (i = 0; i < len; i++) {
    Write_MFRC522(0x09, *(pIndata + i));
  }
  Write_MFRC522(0x01, 0x03);
  i = 0xFF;
  do {
    n = Read_MFRC522(0x05);
    i--;
  } while ((i != 0) && !(n & 0x04));
  pOutData[0] = Read_MFRC522(0x22);
  pOutData[1] = Read_MFRC522(0x21);
}


x86 assembly (clang, -O0):
<CalulateCRC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x5,%edi
mov    $0x4,%esi
call   1060 <ClearBitMask@plt>
mov    $0xa,%edi
mov    $0x80,%esi
call   1040 <SetBitMask@plt>
movb   $0x0,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
movzbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jge    11ae <CalulateCRC+0x6e>
mov    -0x8(%rbp),%rax
movzbl -0x19(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%esi
mov    $0x9,%edi
call   1050 <Write_MFRC522@plt>
mov    -0x19(%rbp),%al
add    $0x1,%al
mov    %al,-0x19(%rbp)
jmp    1178 <CalulateCRC+0x38>
mov    $0x1,%edi
mov    $0x3,%esi
call   1050 <Write_MFRC522@plt>
movb   $0xff,-0x19(%rbp)
mov    $0x5,%edi
call   1030 <Read_MFRC522@plt>
mov    %al,-0x1a(%rbp)
mov    -0x19(%rbp),%al
add    $0xff,%al
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1b(%rbp)
je     11fa <CalulateCRC+0xba>
movzbl -0x1a(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1b(%rbp)
mov    -0x1b(%rbp),%al
test   $0x1,%al
jne    11c1 <CalulateCRC+0x81>
mov    $0x22,%edi
call   1030 <Read_MFRC522@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    $0x21,%edi
call   1030 <Read_MFRC522@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalulateCRC>:
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   1060 <ClearBitMask@plt>
mov    $0xa,%edi
mov    $0x80,%esi
call   1040 <SetBitMask@plt>
test   %ebp,%ebp
je     1198 <CalulateCRC+0x58>
movzbl %bpl,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%esi
mov    $0x9,%edi
call   1050 <Write_MFRC522@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <CalulateCRC+0x40>
mov    $0x1,%edi
mov    $0x3,%esi
call   1050 <Write_MFRC522@plt>
mov    $0x2,%bl
nopl   0x0(%rax)
mov    $0x5,%edi
call   1030 <Read_MFRC522@plt>
test   %bl,%bl
je     11c7 <CalulateCRC+0x87>
and    $0x4,%al
add    $0x1,%bl
test   %al,%al
je     11b0 <CalulateCRC+0x70>
mov    $0x22,%edi
call   1030 <Read_MFRC522@plt>
mov    %al,(%r14)
mov    $0x21,%edi
call   1030 <Read_MFRC522@plt>
mov    %al,0x1(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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