#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 MFRC522_Rd(int);
char MFRC522_ToCard(int, char *, int, char *, unsigned int *);
char MFRC522_Auth(char authMode, char BlockAddr, char *Sectorkey,
                  char *serNum) {
  char _status;
  unsigned recvBits;
  char i;
  char buff[12];
  buff[0] = authMode;
  buff[1] = BlockAddr;
  for (i = 2; i < 8; i++) {
    buff[i] = Sectorkey[i - 2];
  }
  for (i = 8; i < 12; i++) {
    buff[i] = serNum[i - 8];
  }
  _status = MFRC522_ToCard(0x0E, buff, 12, buff, &recvBits);
  if ((_status != 0) || !(MFRC522_Rd(0x08) & 0x08)) {
    _status = 2;
  }
  return _status;
}


x86 assembly (clang, -O0):
<MFRC522_Auth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %dil,%sil
mov    %sil,-0x1(%rbp)
mov    %al,-0x2(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x1(%rbp),%al
mov    %al,-0x2d(%rbp)
mov    -0x2(%rbp),%al
mov    %al,-0x2c(%rbp)
movb   $0x2,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x8,%eax
jge    1181 <MFRC522_Auth+0x61>
mov    -0x10(%rbp),%rax
movsbl -0x21(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movsbq -0x21(%rbp),%rax
mov    %cl,-0x2d(%rbp,%rax,1)
mov    -0x21(%rbp),%al
add    $0x1,%al
mov    %al,-0x21(%rbp)
jmp    114d <MFRC522_Auth+0x2d>
movb   $0x8,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0xc,%eax
jge    11b9 <MFRC522_Auth+0x99>
mov    -0x18(%rbp),%rax
movsbl -0x21(%rbp),%ecx
sub    $0x8,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movsbq -0x21(%rbp),%rax
mov    %cl,-0x2d(%rbp,%rax,1)
mov    -0x21(%rbp),%al
add    $0x1,%al
mov    %al,-0x21(%rbp)
jmp    1185 <MFRC522_Auth+0x65>
lea    -0x2d(%rbp),%rsi
lea    -0x2d(%rbp),%rcx
mov    $0xe,%edi
mov    $0xc,%edx
lea    -0x20(%rbp),%r8
call   1030 <MFRC522_ToCard@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    11fa <MFRC522_Auth+0xda>
mov    $0x8,%edi
call   1040 <MFRC522_Rd@plt>
and    $0x8,%eax
cmp    $0x0,%eax
jne    11fe <MFRC522_Auth+0xde>
movb   $0x2,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MFRC522_Auth>:
sub    $0x18,%rsp
mov    %dil,0x8(%rsp)
mov    %sil,0x9(%rsp)
mov    (%rdx),%eax
mov    %eax,0xa(%rsp)
movzwl 0x4(%rdx),%eax
mov    %ax,0xe(%rsp)
mov    (%rcx),%eax
mov    %eax,0x10(%rsp)
lea    0x8(%rsp),%rcx
lea    0x14(%rsp),%r8
mov    $0xe,%edi
mov    %rcx,%rsi
mov    $0xc,%edx
call   1030 <MFRC522_ToCard@plt>
test   %al,%al
jne    1171 <MFRC522_Auth+0x51>
mov    $0x8,%edi
call   1040 <MFRC522_Rd@plt>
test   $0x8,%al
jne    1178 <MFRC522_Auth+0x58>
mov    $0x2,%al
add    $0x18,%rsp
ret
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define signext i8 @MFRC522_Auth(i8 signext %0, i8 signext %1, i8* %2, i8* %3) {
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i32
%11 = alloca i8
%12 = alloca [12 x i8]
store i8 %0, i8* %5
store i8 %1, i8* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%13 = load i8, i8* %5
%14 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
store i8 %13, i8* %14
%15 = load i8, i8* %6
%16 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 1
store i8 %15, i8* %16
store i8 2, i8* %11
br label %17
17: ; preds = %32, %4
%18 = load i8, i8* %11
%19 = sext i8 %18 to i32
%20 = icmp slt i32 %19, 8
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load i8*, i8** %7
%23 = load i8, i8* %11
%24 = sext i8 %23 to i32
%25 = sub nsw i32 %24, 2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
%28 = load i8, i8* %27
%29 = load i8, i8* %11
%30 = sext i8 %29 to i64
%31 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 %30
store i8 %28, i8* %31
br label %32
32: ; preds = %21
%33 = load i8, i8* %11
%34 = add i8 %33, 1
store i8 %34, i8* %11
br label %17
35: ; preds = %17
store i8 8, i8* %11
br label %36
36: ; preds = %51, %35
%37 = load i8, i8* %11
%38 = sext i8 %37 to i32
%39 = icmp slt i32 %38, 12
br i1 %39, label %40, label %54
40: ; preds = %36
%41 = load i8*, i8** %8
%42 = load i8, i8* %11
%43 = sext i8 %42 to i32
%44 = sub nsw i32 %43, 8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %41, i64 %45
%47 = load i8, i8* %46
%48 = load i8, i8* %11
%49 = sext i8 %48 to i64
%50 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 %49
store i8 %47, i8* %50
br label %51
51: ; preds = %40
%52 = load i8, i8* %11
%53 = add i8 %52, 1
store i8 %53, i8* %11
br label %36
54: ; preds = %36
%55 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%56 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%57 = call signext i8 @MFRC522_ToCard(i32 14, i8* %55, i32 12, i8* %56, i32* %10)
store i8 %57, i8* %9
%58 = load i8, i8* %9
%59 = sext i8 %58 to i32
%60 = icmp ne i32 %59, 0
br i1 %60, label %65, label %61
61: ; preds = %54
%62 = call i32 @MFRC522_Rd(i32 8)
%63 = and i32 %62, 8
%64 = icmp ne i32 %63, 0
br i1 %64, label %66, label %65
65: ; preds = %61, %54
store i8 2, i8* %9
br label %66
66: ; preds = %65, %61
%67 = load i8, i8* %9
ret i8 %67
}

LLVM IR (-O2):
define signext i8 @MFRC522_Auth(i8 signext %0, i8 signext %1, i8* nocapture %2, i8* nocapture %3) {
%5 = alloca i32
%6 = alloca [12 x i8]
%7 = bitcast i32* %5 to i8*
%8 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
store i8 %0, i8* %8
%9 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 1
store i8 %1, i8* %9
%10 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 2
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 8
%12 = bitcast i8* %3 to i32*
%13 = bitcast i8* %11 to i32*
%14 = load i32, i32* %12
store i32 %14, i32* %13
%15 = call signext i8 @MFRC522_ToCard(i32 14, i8* %8, i32 12, i8* %8, i32* %5)
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = call i32 @MFRC522_Rd(i32 8)
%19 = and i32 %18, 8
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17, %4
br label %22
22: ; preds = %21, %17
%23 = phi i8 [ 2, %21 ], [ 0, %17 ]
ret i8 %23
}