#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*/ CalulateCRC(unsigned char *, int, unsigned char *);
unsigned char MFRC522_ToCard(int, unsigned char *, int, unsigned char *,
                             unsigned int *);
int /*<<< orphan*/ printf(char *, unsigned int);
unsigned char MFRC522_SelectTag(unsigned char *serNum, unsigned char *sak) {
  unsigned char i;
  unsigned char status;
  unsigned int recvBits;
  unsigned char buffer[9];
  buffer[0] = 0x93;
  buffer[1] = 0x70;
  for (i = 0; i < 5; i++) {
    buffer[i + 2] = *(serNum + i);
  }
  CalulateCRC(buffer, 7, &buffer[7]);
  status = MFRC522_ToCard(0x0C, buffer, 9, buffer, &recvBits);
  status = 0;
  printf("recvBits: %d \n", recvBits);
  *sak = buffer[0];
  return status;
}


x86 assembly (clang, -O0):
<MFRC522_SelectTag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x93,-0x21(%rbp)
movb   $0x70,-0x20(%rbp)
movb   $0x0,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x5,%eax
jge    1181 <MFRC522_SelectTag+0x51>
mov    -0x8(%rbp),%rax
movzbl -0x11(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movzbl -0x11(%rbp),%eax
add    $0x2,%eax
cltq
mov    %cl,-0x21(%rbp,%rax,1)
mov    -0x11(%rbp),%al
add    $0x1,%al
mov    %al,-0x11(%rbp)
jmp    114c <MFRC522_SelectTag+0x1c>
lea    -0x21(%rbp),%rdi
lea    -0x21(%rbp),%rdx
add    $0x7,%rdx
mov    $0x7,%esi
call   1050 <CalulateCRC@plt>
lea    -0x21(%rbp),%rsi
lea    -0x21(%rbp),%rcx
mov    $0xc,%edi
mov    $0x9,%edx
lea    -0x18(%rbp),%r8
call   1030 <MFRC522_ToCard@plt>
mov    %al,-0x12(%rbp)
movb   $0x0,-0x12(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x21(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movzbl -0x12(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MFRC522_SelectTag>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
movw   $0x7093,0xb(%rsp)
mov    (%rdi),%eax
mov    %eax,0xd(%rsp)
mov    0x4(%rdi),%al
mov    %al,0x11(%rsp)
lea    0x12(%rsp),%rdx
lea    0xb(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1050 <CalulateCRC@plt>
lea    0x14(%rsp),%r8
mov    $0xc,%edi
mov    %rbx,%rsi
mov    $0x9,%edx
mov    %rbx,%rcx
call   1030 <MFRC522_ToCard@plt>
mov    0x14(%rsp),%esi
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
mov    0xb(%rsp),%al
mov    %al,(%r14)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"recvBits: %d \0A\00"
define zeroext i8 @MFRC522_SelectTag(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca [9 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
store i8 -109, i8* %6
%7 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 1
store i8 112, i8* %7
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 2
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 7
%10 = call i32 @CalulateCRC(i8* %6, i32 7, i8* %9)
%11 = call zeroext i8 @MFRC522_ToCard(i32 12, i8* %6, i32 9, i8* %6, i32* %3)
%12 = load i32, i32* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i8, i8* %6
store i8 %14, i8* %1
ret i8 0
}