#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ MFRC522_ParseType(int);
int MFRC522_SelectTag(int *);
char *MFRC522_TypeToString(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int tag_select(uint8_t *CardID) {
  int ret_int;
  printf("Card detected    0x%02X 0x%02X 0x%02X 0x%02X, Check Sum = 0x%02X\r\n",
         CardID[0], CardID[1], CardID[2], CardID[3], CardID[4]);
  ret_int = MFRC522_SelectTag(CardID);
  if (ret_int == 0) {
    printf("Card Select Failed\r\n");
    return -1;
  } else {
    printf("Card Selected, Type:%s\r\n",
           MFRC522_TypeToString(MFRC522_ParseType(ret_int)));
  }
  ret_int = 0;
  return ret_int;
}


x86 assembly (clang, -O0):
<tag_select>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r9d
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <MFRC522_SelectTag@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11ae <tag_select+0x6e>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <tag_select+0x9b>
mov    -0x14(%rbp),%edi
call   1060 <MFRC522_ParseType@plt>
mov    %eax,%edi
call   1050 <MFRC522_TypeToString@plt>
mov    %rax,%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tag_select>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%esi
mov    0x4(%rdi),%edx
mov    0x8(%rdi),%ecx
mov    0xc(%rdi),%r8d
mov    0x10(%rdi),%r9d
lea    0xe93(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <MFRC522_SelectTag@plt>
test   %eax,%eax
je     11a3 <tag_select+0x53>
mov    %eax,%edi
call   1070 <MFRC522_ParseType@plt>
mov    %eax,%edi
call   1060 <MFRC522_TypeToString@plt>
lea    0xeac(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11b4 <tag_select+0x64>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [67 x i8] c"Card detected 0x%02X 0x%02X 0x%02X 0x%02X, Check Sum = 0x%02X\0D\0A\00"
@.str.1 = [21 x i8] c"Card Select Failed\0D\0A\00"
@.str.2 = [25 x i8] c"Card Selected, Type:%s\0D\0A\00"
define i32 @tag_select(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = getelementptr inbounds i32, i32* %5, i64 0
%7 = load i32, i32* %6
%8 = load i32*, i32** %3
%9 = getelementptr inbounds i32, i32* %8, i64 1
%10 = load i32, i32* %9
%11 = load i32*, i32** %3
%12 = getelementptr inbounds i32, i32* %11, i64 2
%13 = load i32, i32* %12
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 3
%16 = load i32, i32* %15
%17 = load i32*, i32** %3
%18 = getelementptr inbounds i32, i32* %17, i64 4
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10, i32 %13, i32 %16, i32 %19)
%21 = load i32*, i32** %3
%22 = call i32 @MFRC522_SelectTag(i32* %21)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %1
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %34
27: ; preds = %1
%28 = load i32, i32* %4
%29 = call i32 @MFRC522_ParseType(i32 %28)
%30 = call i8* @MFRC522_TypeToString(i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %27
store i32 0, i32* %4
%33 = load i32, i32* %4
store i32 %33, i32* %2
br label %34
34: ; preds = %32, %25
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [67 x i8] c"Card detected 0x%02X 0x%02X 0x%02X 0x%02X, Check Sum = 0x%02X\0D\0A\00"
@.str.2 = [25 x i8] c"Card Selected, Type:%s\0D\0A\00"
@str = [20 x i8] c"Card Select Failed\0D\00"
define i32 @tag_select(i32* %0) {
%2 = load i32, i32* %0
%3 = getelementptr inbounds i32, i32* %0, i64 1
%4 = load i32, i32* %3
%5 = getelementptr inbounds i32, i32* %0, i64 2
%6 = load i32, i32* %5
%7 = getelementptr inbounds i32, i32* %0, i64 3
%8 = load i32, i32* %7
%9 = getelementptr inbounds i32, i32* %0, i64 4
%10 = load i32, i32* %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %4, i32 %6, i32 %8, i32 %10)
%12 = tail call i32 @MFRC522_SelectTag(i32* %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %20
16: ; preds = %1
%17 = tail call i32 @MFRC522_ParseType(i32 %12)
%18 = tail call i8* @MFRC522_TypeToString(i32 %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %16, %14
%21 = phi i32 [ -1, %14 ], [ 0, %16 ]
ret i32 %21
}