#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_AntennaOn();
int /*<<< orphan*/ MFRC522_ClearBitMask(int, int);
int /*<<< orphan*/ MFRC522_HAL_Delay(int);
char MFRC522_ReadRegister(int);
int /*<<< orphan*/ MFRC522_Reset();
int /*<<< orphan*/ MFRC522_WriteRegister(int, int);
int MFRC522_Setup(char Type) {
  MFRC522_Reset();
  MFRC522_HAL_Delay(200);
  MFRC522_WriteRegister(0x2B, 0x3E);
  {
    volatile char test;
    test = MFRC522_ReadRegister(0x2B);
    if (test != 0x3E) {
      return -1;
    }
  }
  MFRC522_WriteRegister(0x2A, 0x8D);
  MFRC522_WriteRegister(0x2D, 30);
  MFRC522_WriteRegister(0x2C, 0);
  MFRC522_WriteRegister(0x15, 0x40);
  MFRC522_WriteRegister(0x11, 0x3D);
  if (Type == 'A') {
    MFRC522_ClearBitMask(0x08, 0x08);
    MFRC522_WriteRegister(0x11, 0x3D);
    MFRC522_WriteRegister(0x17, 0x86);
    MFRC522_WriteRegister(0x26, 0x7F);
    MFRC522_WriteRegister(0x2D, 30);
    MFRC522_WriteRegister(0x2C, 0);
    MFRC522_WriteRegister(0x2A, 0x8D);
    MFRC522_WriteRegister(0x2B, 0x3E);
  }
  MFRC522_AntennaOn();
  return 0;
}


x86 assembly (clang, -O0):
<MFRC522_Setup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    $0x0,%al
call   1080 <MFRC522_Reset@plt>
mov    $0xc8,%edi
call   1040 <MFRC522_HAL_Delay@plt>
mov    $0x2b,%edi
mov    $0x3e,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2b,%edi
call   1050 <MFRC522_ReadRegister@plt>
mov    %al,-0x6(%rbp)
mov    -0x6(%rbp),%al
movsbl %al,%eax
cmp    $0x3e,%eax
je     11b6 <MFRC522_Setup+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    128b <MFRC522_Setup+0x12b>
mov    $0x2a,%edi
mov    $0x8d,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2d,%edi
mov    $0x1e,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2c,%edi
xor    %esi,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x15,%edi
mov    $0x40,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x11,%edi
mov    $0x3d,%esi
call   1070 <MFRC522_WriteRegister@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
jne    127d <MFRC522_Setup+0x11d>
mov    $0x8,%esi
mov    %esi,%edi
call   1030 <MFRC522_ClearBitMask@plt>
mov    $0x11,%edi
mov    $0x3d,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x17,%edi
mov    $0x86,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x26,%edi
mov    $0x7f,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2d,%edi
mov    $0x1e,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2c,%edi
xor    %esi,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2a,%edi
mov    $0x8d,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2b,%edi
mov    $0x3e,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x0,%al
call   1060 <MFRC522_AntennaOn@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MFRC522_Setup>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   1080 <MFRC522_Reset@plt>
mov    $0xc8,%edi
call   1040 <MFRC522_HAL_Delay@plt>
mov    $0x2b,%edi
mov    $0x3e,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2b,%edi
call   1050 <MFRC522_ReadRegister@plt>
mov    %al,0x7(%rsp)
mov    0x7(%rsp),%al
mov    $0xffffffff,%ebx
cmp    $0x3e,%al
jne    1270 <MFRC522_Setup+0x110>
mov    $0x2a,%edi
mov    $0x8d,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2d,%edi
mov    $0x1e,%esi
call   1070 <MFRC522_WriteRegister@plt>
xor    %ebx,%ebx
mov    $0x2c,%edi
xor    %esi,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x15,%edi
mov    $0x40,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x11,%edi
mov    $0x3d,%esi
call   1070 <MFRC522_WriteRegister@plt>
cmp    $0x41,%bpl
jne    1269 <MFRC522_Setup+0x109>
mov    $0x8,%edi
mov    $0x8,%esi
call   1030 <MFRC522_ClearBitMask@plt>
mov    $0x11,%edi
mov    $0x3d,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x17,%edi
mov    $0x86,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x26,%edi
mov    $0x7f,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2d,%edi
mov    $0x1e,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2c,%edi
xor    %esi,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2a,%edi
mov    $0x8d,%esi
call   1070 <MFRC522_WriteRegister@plt>
mov    $0x2b,%edi
mov    $0x3e,%esi
call   1070 <MFRC522_WriteRegister@plt>
xor    %eax,%eax
call   1060 <MFRC522_AntennaOn@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @MFRC522_Setup(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8
store i8 %0, i8* %3
%5 = call i32 (...) @MFRC522_Reset()
%6 = call i32 @MFRC522_HAL_Delay(i32 200)
%7 = call i32 @MFRC522_WriteRegister(i32 43, i32 62)
%8 = call signext i8 @MFRC522_ReadRegister(i32 43)
store volatile i8 %8, i8* %4
%9 = load volatile i8, i8* %4
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 62
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %33
13: ; preds = %1
%14 = call i32 @MFRC522_WriteRegister(i32 42, i32 141)
%15 = call i32 @MFRC522_WriteRegister(i32 45, i32 30)
%16 = call i32 @MFRC522_WriteRegister(i32 44, i32 0)
%17 = call i32 @MFRC522_WriteRegister(i32 21, i32 64)
%18 = call i32 @MFRC522_WriteRegister(i32 17, i32 61)
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 65
br i1 %21, label %22, label %31
22: ; preds = %13
%23 = call i32 @MFRC522_ClearBitMask(i32 8, i32 8)
%24 = call i32 @MFRC522_WriteRegister(i32 17, i32 61)
%25 = call i32 @MFRC522_WriteRegister(i32 23, i32 134)
%26 = call i32 @MFRC522_WriteRegister(i32 38, i32 127)
%27 = call i32 @MFRC522_WriteRegister(i32 45, i32 30)
%28 = call i32 @MFRC522_WriteRegister(i32 44, i32 0)
%29 = call i32 @MFRC522_WriteRegister(i32 42, i32 141)
%30 = call i32 @MFRC522_WriteRegister(i32 43, i32 62)
br label %31
31: ; preds = %22, %13
%32 = call i32 (...) @MFRC522_AntennaOn()
store i32 0, i32* %2
br label %33
33: ; preds = %31, %12
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
define i32 @MFRC522_Setup(i8 signext %0) {
%2 = alloca i8
%3 = tail call i32 (...) @MFRC522_Reset()
%4 = tail call i32 @MFRC522_HAL_Delay(i32 200)
%5 = tail call i32 @MFRC522_WriteRegister(i32 43, i32 62)
%6 = tail call signext i8 @MFRC522_ReadRegister(i32 43)
store volatile i8 %6, i8* %2
%7 = load volatile i8, i8* %2
%8 = icmp eq i8 %7, 62
br i1 %8, label %9, label %27
9: ; preds = %1
%10 = tail call i32 @MFRC522_WriteRegister(i32 42, i32 141)
%11 = tail call i32 @MFRC522_WriteRegister(i32 45, i32 30)
%12 = tail call i32 @MFRC522_WriteRegister(i32 44, i32 0)
%13 = tail call i32 @MFRC522_WriteRegister(i32 21, i32 64)
%14 = tail call i32 @MFRC522_WriteRegister(i32 17, i32 61)
%15 = icmp eq i8 %0, 65
br i1 %15, label %16, label %25
16: ; preds = %9
%17 = tail call i32 @MFRC522_ClearBitMask(i32 8, i32 8)
%18 = tail call i32 @MFRC522_WriteRegister(i32 17, i32 61)
%19 = tail call i32 @MFRC522_WriteRegister(i32 23, i32 134)
%20 = tail call i32 @MFRC522_WriteRegister(i32 38, i32 127)
%21 = tail call i32 @MFRC522_WriteRegister(i32 45, i32 30)
%22 = tail call i32 @MFRC522_WriteRegister(i32 44, i32 0)
%23 = tail call i32 @MFRC522_WriteRegister(i32 42, i32 141)
%24 = tail call i32 @MFRC522_WriteRegister(i32 43, i32 62)
br label %25
25: ; preds = %16, %9
%26 = tail call i32 (...) @MFRC522_AntennaOn()
br label %27
27: ; preds = %1, %25
%28 = phi i32 [ -1, %1 ], [ 0, %25 ]
ret i32 %28
}