#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*/ MFRC522_Clear_Bit(int, int);
char MFRC522_ToCard(int, char *, int, char *, unsigned int *);
int /*<<< orphan*/ MFRC522_Wr(int, int);
char MFRC522_AntiColl(char *serNum) {
  char _status;
  char i;
  char serNumCheck = 0;
  unsigned unLen;
  MFRC522_Wr(0x0D, 0x00);
  serNum[0] = 0x93;
  serNum[1] = 0x20;
  MFRC522_Clear_Bit(0x08, 0x08);
  _status = MFRC522_ToCard(0x0C, serNum, 2, serNum, &unLen);
  if (_status == 0) {
    for (i = 0; i < 4; i++) {
      serNumCheck ^= serNum[i];
    }
    if (serNumCheck != serNum[4]) {
      _status = 2;
    }
  }
  return _status;
}


x86 assembly (clang, -O0):
<MFRC522_AntiColl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0xb(%rbp)
mov    $0xd,%edi
xor    %esi,%esi
call   1050 <MFRC522_Wr@plt>
mov    -0x8(%rbp),%rax
movb   $0x93,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x20,0x1(%rax)
mov    $0x8,%esi
mov    %esi,%edi
call   1040 <MFRC522_Clear_Bit@plt>
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rcx
mov    $0xc,%edi
mov    $0x2,%edx
lea    -0x10(%rbp),%r8
call   1030 <MFRC522_ToCard@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jne    11e3 <MFRC522_AntiColl+0xb3>
movb   $0x0,-0xa(%rbp)
movsbl -0xa(%rbp),%eax
cmp    $0x4,%eax
jge    11c6 <MFRC522_AntiColl+0x96>
mov    -0x8(%rbp),%rax
movsbq -0xa(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
movsbl -0xb(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0xb(%rbp)
mov    -0xa(%rbp),%al
add    $0x1,%al
mov    %al,-0xa(%rbp)
jmp    1196 <MFRC522_AntiColl+0x66>
movsbl -0xb(%rbp),%eax
mov    -0x8(%rbp),%rcx
movsbl 0x4(%rcx),%ecx
cmp    %ecx,%eax
je     11de <MFRC522_AntiColl+0xae>
movb   $0x2,-0x9(%rbp)
jmp    11e3 <MFRC522_AntiColl+0xb3>
movsbl -0x9(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MFRC522_AntiColl>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0xd,%edi
xor    %esi,%esi
call   1050 <MFRC522_Wr@plt>
movw   $0x2093,(%rbx)
mov    $0x8,%edi
mov    $0x8,%esi
call   1040 <MFRC522_Clear_Bit@plt>
lea    0xc(%rsp),%r8
mov    $0xc,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
mov    %rbx,%rcx
call   1030 <MFRC522_ToCard@plt>
test   %al,%al
jne    11a0 <MFRC522_AntiColl+0x70>
movd   (%rbx),%xmm0
movdqa %xmm0,%xmm1
psrld  $0x10,%xmm1
pxor   %xmm0,%xmm1
movdqa %xmm1,%xmm0
psrlw  $0x8,%xmm0
pxor   %xmm1,%xmm0
movd   %xmm0,%eax
cmp    0x4(%rbx),%al
setne  %al
add    %al,%al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define signext i8 @MFRC522_AntiColl(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i32
store i8* %0, i8** %2
store i8 0, i8* %5
%7 = call i32 @MFRC522_Wr(i32 13, i32 0)
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 0
store i8 -109, i8* %9
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8 32, i8* %11
%12 = call i32 @MFRC522_Clear_Bit(i32 8, i32 8)
%13 = load i8*, i8** %2
%14 = load i8*, i8** %2
%15 = call signext i8 @MFRC522_ToCard(i32 12, i8* %13, i32 2, i8* %14, i32* %6)
store i8 %15, i8* %3
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %48
19: ; preds = %1
store i8 0, i8* %4
br label %20
20: ; preds = %35, %19
%21 = load i8, i8* %4
%22 = sext i8 %21 to i32
%23 = icmp slt i32 %22, 4
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load i8*, i8** %2
%26 = load i8, i8* %4
%27 = sext i8 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = load i8, i8* %5
%32 = sext i8 %31 to i32
%33 = xor i32 %32, %30
%34 = trunc i32 %33 to i8
store i8 %34, i8* %5
br label %35
35: ; preds = %24
%36 = load i8, i8* %4
%37 = add i8 %36, 1
store i8 %37, i8* %4
br label %20
38: ; preds = %20
%39 = load i8, i8* %5
%40 = sext i8 %39 to i32
%41 = load i8*, i8** %2
%42 = getelementptr inbounds i8, i8* %41, i64 4
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %40, %44
br i1 %45, label %46, label %47
46: ; preds = %38
store i8 2, i8* %3
br label %47
47: ; preds = %46, %38
br label %48
48: ; preds = %47, %1
%49 = load i8, i8* %3
ret i8 %49
}

LLVM IR (-O2):
define signext i8 @MFRC522_AntiColl(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @MFRC522_Wr(i32 13, i32 0)
store i8 -109, i8* %0
%5 = getelementptr inbounds i8, i8* %0, i64 1
store i8 32, i8* %5
%6 = tail call i32 @MFRC522_Clear_Bit(i32 8, i32 8)
%7 = call signext i8 @MFRC522_ToCard(i32 12, i8* %0, i32 2, i8* %0, i32* %2)
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = bitcast i8* %0 to <4 x i8>*
%11 = load <4 x i8>, <4 x i8>* %10
%12 = call i8 @llvm.vector.reduce.xor.v4i8(<4 x i8> %11)
%13 = getelementptr inbounds i8, i8* %0, i64 4
%14 = load i8, i8* %13
%15 = icmp eq i8 %12, %14
%16 = select i1 %15, i8 0, i8 2
br label %17
17: ; preds = %9, %1
%18 = phi i8 [ %7, %1 ], [ %16, %9 ]
ret i8 %18
}