#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_CRC(char *, int, char *);
char MFRC522_ToCard(int, char *, int, char *, unsigned int *);
char MFRC522_SelectTag(char *serNum) {
  char i;
  char _status;
  char size;
  unsigned recvBits;
  char buffer[9];
  buffer[0] = 0x93;
  buffer[1] = 0x70;
  for (i = 2; i < 7; i++) {
    buffer[i] = *serNum++;
  }
  MFRC522_CRC(buffer, 7, &buffer[7]);
  _status = MFRC522_ToCard(0x0C, buffer, 9, buffer, &recvBits);
  if ((_status == 0) && (recvBits == 0x18)) {
    size = buffer[0];
  } else {
    size = 0;
  }
  return size;
}


x86 assembly (clang, -O0):
<MFRC522_SelectTag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x93,-0x19(%rbp)
movb   $0x70,-0x18(%rbp)
movb   $0x2,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x7,%eax
jge    116c <MFRC522_SelectTag+0x4c>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
movsbq -0x9(%rbp),%rax
mov    %cl,-0x19(%rbp,%rax,1)
mov    -0x9(%rbp),%al
add    $0x1,%al
mov    %al,-0x9(%rbp)
jmp    1138 <MFRC522_SelectTag+0x18>
lea    -0x19(%rbp),%rdi
lea    -0x19(%rbp),%rdx
add    $0x7,%rdx
mov    $0x7,%esi
call   1030 <MFRC522_CRC@plt>
lea    -0x19(%rbp),%rsi
lea    -0x19(%rbp),%rcx
mov    $0xc,%edi
mov    $0x9,%edx
lea    -0x10(%rbp),%r8
call   1040 <MFRC522_ToCard@plt>
mov    %al,-0xa(%rbp)
movsbl -0xa(%rbp),%eax
cmp    $0x0,%eax
jne    11c2 <MFRC522_SelectTag+0xa2>
cmpl   $0x18,-0x10(%rbp)
jne    11c2 <MFRC522_SelectTag+0xa2>
mov    -0x19(%rbp),%al
mov    %al,-0xb(%rbp)
jmp    11c6 <MFRC522_SelectTag+0xa6>
movb   $0x0,-0xb(%rbp)
movsbl -0xb(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MFRC522_SelectTag>:
push   %rbx
sub    $0x10,%rsp
movw   $0x7093,0x3(%rsp)
mov    (%rdi),%eax
mov    %eax,0x5(%rsp)
mov    0x4(%rdi),%al
mov    %al,0x9(%rsp)
lea    0xa(%rsp),%rdx
lea    0x3(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1030 <MFRC522_CRC@plt>
lea    0xc(%rsp),%r8
mov    $0xc,%edi
mov    %rbx,%rsi
mov    $0x9,%edx
mov    %rbx,%rcx
call   1040 <MFRC522_ToCard@plt>
xor    %edx,%edx
cmpl   $0x18,0xc(%rsp)
movzbl 0x3(%rsp),%ecx
cmovne %edx,%ecx
test   %al,%al
cmovne %edx,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define signext i8 @MFRC522_SelectTag(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i32
%7 = alloca [9 x i8]
store i8* %0, i8** %2
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
store i8 -109, i8* %8
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 1
store i8 112, i8* %9
store i8 2, i8* %3
br label %10
10: ; preds = %21, %1
%11 = load i8, i8* %3
%12 = sext i8 %11 to i32
%13 = icmp slt i32 %12, 7
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %2
%17 = load i8, i8* %15
%18 = load i8, i8* %3
%19 = sext i8 %18 to i64
%20 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 %19
store i8 %17, i8* %20
br label %21
21: ; preds = %14
%22 = load i8, i8* %3
%23 = add i8 %22, 1
store i8 %23, i8* %3
br label %10
24: ; preds = %10
%25 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%26 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 7
%27 = call i32 @MFRC522_CRC(i8* %25, i32 7, i8* %26)
%28 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%29 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%30 = call signext i8 @MFRC522_ToCard(i32 12, i8* %28, i32 9, i8* %29, i32* %6)
store i8 %30, i8* %4
%31 = load i8, i8* %4
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %24
%35 = load i32, i32* %6
%36 = icmp eq i32 %35, 24
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%39 = load i8, i8* %38
store i8 %39, i8* %5
br label %41
40: ; preds = %34, %24
store i8 0, i8* %5
br label %41
41: ; preds = %40, %37
%42 = load i8, i8* %5
ret i8 %42
}

LLVM IR (-O2):
define signext i8 @MFRC522_SelectTag(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca [9 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
store i8 -109, i8* %5
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 1
store i8 112, i8* %6
%7 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 2
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 7
%9 = call i32 @MFRC522_CRC(i8* %5, i32 7, i8* %8)
%10 = call signext i8 @MFRC522_ToCard(i32 12, i8* %5, i32 9, i8* %5, i32* %2)
%11 = icmp eq i8 %10, 0
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, 24
%14 = select i1 %11, i1 %13, i1 false
%15 = load i8, i8* %5
%16 = select i1 %14, i8 %15, i8 0
ret i8 %16
}