#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 Read_MFRC522(int);
unsigned char MFRC522_Auth(unsigned char authMode, unsigned char BlockAddr,
                           unsigned char *Sectorkey, unsigned char *serNum) {
  unsigned char status;
  unsigned int recvBits;
  unsigned char i;
  unsigned char buff[12];
  buff[0] = authMode;
  buff[1] = BlockAddr;
  for (i = 0; i < 6; i++) {
    buff[i + 2] = *(Sectorkey + i);
  }
  for (i = 0; i < 4; i++) {
    buff[i + 8] = *(serNum + i);
  }
  status = MFRC522_ToCard(0x0E, buff, 12, buff, &recvBits);
  if ((status != 0) || (!(Read_MFRC522(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   $0x0,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
cmp    $0x6,%eax
jge    1182 <MFRC522_Auth+0x62>
mov    -0x10(%rbp),%rax
movzbl -0x21(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movzbl -0x21(%rbp),%eax
add    $0x2,%eax
cltq
mov    %cl,-0x2d(%rbp,%rax,1)
mov    -0x21(%rbp),%al
add    $0x1,%al
mov    %al,-0x21(%rbp)
jmp    114d <MFRC522_Auth+0x2d>
movb   $0x0,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
cmp    $0x4,%eax
jge    11bb <MFRC522_Auth+0x9b>
mov    -0x18(%rbp),%rax
movzbl -0x21(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movzbl -0x21(%rbp),%eax
add    $0x8,%eax
cltq
mov    %cl,-0x2d(%rbp,%rax,1)
mov    -0x21(%rbp),%al
add    $0x1,%al
mov    %al,-0x21(%rbp)
jmp    1186 <MFRC522_Auth+0x66>
lea    -0x2d(%rbp),%rsi
lea    -0x2d(%rbp),%rcx
mov    $0xe,%edi
mov    $0xc,%edx
lea    -0x20(%rbp),%r8
call   1040 <MFRC522_ToCard@plt>
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    11fc <MFRC522_Auth+0xdc>
mov    $0x8,%edi
call   1030 <Read_MFRC522@plt>
and    $0x8,%eax
cmp    $0x0,%eax
jne    1200 <MFRC522_Auth+0xe0>
movb   $0x2,-0x19(%rbp)
movzbl -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   1040 <MFRC522_ToCard@plt>
test   %al,%al
jne    1171 <MFRC522_Auth+0x51>
mov    $0x8,%edi
call   1030 <Read_MFRC522@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 zeroext i8 @MFRC522_Auth(i8 zeroext %0, i8 zeroext %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 0, i8* %11
br label %17
17: ; preds = %33, %4
%18 = load i8, i8* %11
%19 = zext i8 %18 to i32
%20 = icmp slt i32 %19, 6
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = load i8*, i8** %7
%23 = load i8, i8* %11
%24 = zext i8 %23 to i32
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
%28 = load i8, i8* %11
%29 = zext i8 %28 to i32
%30 = add nsw i32 %29, 2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 %31
store i8 %27, i8* %32
br label %33
33: ; preds = %21
%34 = load i8, i8* %11
%35 = add i8 %34, 1
store i8 %35, i8* %11
br label %17
36: ; preds = %17
store i8 0, i8* %11
br label %37
37: ; preds = %53, %36
%38 = load i8, i8* %11
%39 = zext i8 %38 to i32
%40 = icmp slt i32 %39, 4
br i1 %40, label %41, label %56
41: ; preds = %37
%42 = load i8*, i8** %8
%43 = load i8, i8* %11
%44 = zext i8 %43 to i32
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
%47 = load i8, i8* %46
%48 = load i8, i8* %11
%49 = zext i8 %48 to i32
%50 = add nsw i32 %49, 8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 %51
store i8 %47, i8* %52
br label %53
53: ; preds = %41
%54 = load i8, i8* %11
%55 = add i8 %54, 1
store i8 %55, i8* %11
br label %37
56: ; preds = %37
%57 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%58 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%59 = call zeroext i8 @MFRC522_ToCard(i32 14, i8* %57, i32 12, i8* %58, i32* %10)
store i8 %59, i8* %9
%60 = load i8, i8* %9
%61 = zext i8 %60 to i32
%62 = icmp ne i32 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %56
%64 = call i32 @Read_MFRC522(i32 8)
%65 = and i32 %64, 8
%66 = icmp ne i32 %65, 0
br i1 %66, label %68, label %67
67: ; preds = %63, %56
store i8 2, i8* %9
br label %68
68: ; preds = %67, %63
%69 = load i8, i8* %9
ret i8 %69
}

LLVM IR (-O2):
define zeroext i8 @MFRC522_Auth(i8 zeroext %0, i8 zeroext %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 zeroext 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 @Read_MFRC522(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
}