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


x86 assembly (clang, -O0):
<MFRC522_Anticoll2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0xb(%rbp)
mov    $0xd,%edi
xor    %esi,%esi
call   1040 <Write_MFRC522@plt>
mov    -0x8(%rbp),%rax
movb   $0x95,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x20,0x1(%rax)
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)
movzbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jne    11ca <MFRC522_Anticoll2+0xaa>
movb   $0x0,-0xa(%rbp)
movzbl -0xa(%rbp),%eax
cmp    $0x4,%eax
jge    11a9 <MFRC522_Anticoll2+0x89>
mov    -0x8(%rbp),%rax
movzbl -0xa(%rbp),%ecx
movzbl (%rax,%rcx,1),%ecx
movzbl -0xb(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0xb(%rbp)
mov    -0xa(%rbp),%al
add    $0x1,%al
mov    %al,-0xa(%rbp)
jmp    117a <MFRC522_Anticoll2+0x5a>
movzbl -0xb(%rbp),%eax
mov    -0x8(%rbp),%rcx
movzbl -0xa(%rbp),%edx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11c5 <MFRC522_Anticoll2+0xa5>
movb   $0x2,-0x9(%rbp)
jmp    11ca <MFRC522_Anticoll2+0xaa>
movzbl -0x9(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MFRC522_Anticoll2>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0xd,%edi
xor    %esi,%esi
call   1040 <Write_MFRC522@plt>
movw   $0x2095,(%rbx)
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    1181 <MFRC522_Anticoll2+0x61>
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 zeroext i8 @MFRC522_Anticoll2(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 @Write_MFRC522(i32 13, i32 0)
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 0
store i8 -107, i8* %9
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8 32, i8* %11
%12 = load i8*, i8** %2
%13 = load i8*, i8** %2
%14 = call zeroext i8 @MFRC522_ToCard(i32 12, i8* %12, i32 2, i8* %13, i32* %6)
store i8 %14, i8* %3
%15 = load i8, i8* %3
%16 = zext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %49
18: ; preds = %1
store i8 0, i8* %4
br label %19
19: ; preds = %34, %18
%20 = load i8, i8* %4
%21 = zext i8 %20 to i32
%22 = icmp slt i32 %21, 4
br i1 %22, label %23, label %37
23: ; preds = %19
%24 = load i8*, i8** %2
%25 = load i8, i8* %4
%26 = zext i8 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = load i8, i8* %5
%31 = zext i8 %30 to i32
%32 = xor i32 %31, %29
%33 = trunc i32 %32 to i8
store i8 %33, i8* %5
br label %34
34: ; preds = %23
%35 = load i8, i8* %4
%36 = add i8 %35, 1
store i8 %36, i8* %4
br label %19
37: ; preds = %19
%38 = load i8, i8* %5
%39 = zext i8 %38 to i32
%40 = load i8*, i8** %2
%41 = load i8, i8* %4
%42 = zext i8 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = icmp ne i32 %39, %45
br i1 %46, label %47, label %48
47: ; preds = %37
store i8 2, i8* %3
br label %48
48: ; preds = %47, %37
br label %49
49: ; preds = %48, %1
%50 = load i8, i8* %3
ret i8 %50
}

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