#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*/ ClearBitMask(int, int);
int Read_MFRC522(int);
int /*<<< orphan*/ SetBitMask(int, int);
int /*<<< orphan*/ Write_MFRC522(int, unsigned char);
int /*<<< orphan*/ printf(char *, ...);
unsigned char MFRC522_ToCard(unsigned char command, unsigned char *sendData,
                             unsigned char sendLen, unsigned char *backData,
                             unsigned int *backLen) {
  unsigned char status = 2;
  unsigned char irqEn = 0x00;
  unsigned char waitIRq = 0x00;
  unsigned char lastBits;
  unsigned char n;
  unsigned int i;
  switch (command) {
  case 0x0E: {
    irqEn = 0x12;
    waitIRq = 0x10;
    break;
  }
  case 0x0C: {
    irqEn = 0x77;
    waitIRq = 0x30;
    break;
  }
  default:
    break;
  }
  Write_MFRC522(0x02, irqEn | 0x80);
  ClearBitMask(0x04, 0x80);
  SetBitMask(0x0A, 0x80);
  Write_MFRC522(0x01, 0x00);
  for (i = 0; i < sendLen; i++) {
    Write_MFRC522(0x09, sendData[i]);
  }
  Write_MFRC522(0x01, command);
  if (command == 0x0C) {
    SetBitMask(0x0D, 0x80);
  }
  i = 2000;
  do {
    switch (Read_MFRC522(0x08) & 0x07) {
    case 0:
      printf("Modem is idle\n");
      break;
    case 1:
      printf("Waiting for StartSend\n");
      break;
    case 2:
      printf("TxWait: no RF field present\n");
      printf("Antenna state: %d \n", Read_MFRC522(0x14));
      break;
    case 3:
      printf("Transmitting...\n");
      break;
    case 4:
      printf("RxWait: no RF field present\n");
      break;
    case 5:
      printf("Waiting for data...\n");
      break;
    case 6:
      printf("Receiving...\n");
      break;
    }
    n = Read_MFRC522(0x04);
    i--;
  } while ((i != 0) && !(n & 0x01) && !(n & waitIRq));
  ClearBitMask(0x0D, 0x80);
  if (i != 0) {
    if (!(Read_MFRC522(0x06) & 0x1B)) {
      status = 0;
      if (n & irqEn & 0x01) {
        status = 1;
      }
      if (command == 0x0C) {
        n = Read_MFRC522(0x0A);
        lastBits = Read_MFRC522(0x0C) & 0x07;
        if (lastBits) {
          *backLen = (n - 1) * 8 + lastBits;
        } else {
          *backLen = n * 8;
        }
        if (n == 0)
          n = 1;
        if (n > 32)
          n = 32;
        for (i = 0; i < n; i++) {
          backData[i] = Read_MFRC522(0x09);
        }
      }
    } else {
      status = 2;
    }
  } else {
  }
  return status;
}


x86 assembly (clang, -O0):
<MFRC522_ToCard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %dl,%al
mov    %dil,%dl
mov    %dl,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movb   $0x2,-0x29(%rbp)
movb   $0x0,-0x2a(%rbp)
movb   $0x0,-0x2b(%rbp)
movzbl -0x1(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0xc,%eax
je     11ae <MFRC522_ToCard+0x5e>
jmp    1190 <MFRC522_ToCard+0x40>
mov    -0x38(%rbp),%eax
sub    $0xe,%eax
jne    11bb <MFRC522_ToCard+0x6b>
jmp    11a1 <MFRC522_ToCard+0x51>
movb   $0x12,-0x2a(%rbp)
movb   $0x10,-0x2b(%rbp)
jmp    11c0 <MFRC522_ToCard+0x70>
movb   $0x77,-0x2a(%rbp)
movb   $0x30,-0x2b(%rbp)
jmp    11c0 <MFRC522_ToCard+0x70>
jmp    11c0 <MFRC522_ToCard+0x70>
movzbl -0x2a(%rbp),%eax
or     $0x80,%eax
mov    $0x2,%edi
movzbl %al,%esi
call   1060 <Write_MFRC522@plt>
mov    $0x4,%edi
mov    $0x80,%esi
call   1070 <ClearBitMask@plt>
mov    $0xa,%edi
mov    $0x80,%esi
call   1050 <SetBitMask@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <Write_MFRC522@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
movzbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jae    1239 <MFRC522_ToCard+0xe9>
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    $0x9,%edi
movzbl (%rax,%rcx,1),%esi
call   1060 <Write_MFRC522@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1207 <MFRC522_ToCard+0xb7>
mov    $0x1,%edi
movzbl -0x1(%rbp),%esi
call   1060 <Write_MFRC522@plt>
movzbl -0x1(%rbp),%eax
cmp    $0xc,%eax
jne    1263 <MFRC522_ToCard+0x113>
mov    $0xd,%edi
mov    $0x80,%esi
call   1050 <SetBitMask@plt>
movl   $0x7d0,-0x34(%rbp)
mov    $0x8,%edi
call   1030 <Read_MFRC522@plt>
and    $0x7,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x6,%eax
ja     1334 <MFRC522_ToCard+0x1e4>
mov    -0x40(%rbp),%rax
lea    0xd6f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1334 <MFRC522_ToCard+0x1e4>
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1334 <MFRC522_ToCard+0x1e4>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x14,%edi
call   1030 <Read_MFRC522@plt>
mov    %eax,%esi
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1334 <MFRC522_ToCard+0x1e4>
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1334 <MFRC522_ToCard+0x1e4>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1334 <MFRC522_ToCard+0x1e4>
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1334 <MFRC522_ToCard+0x1e4>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x4,%edi
call   1030 <Read_MFRC522@plt>
mov    %al,-0x2d(%rbp)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x34(%rbp)
mov    %al,-0x41(%rbp)
je     1383 <MFRC522_ToCard+0x233>
movzbl -0x2d(%rbp),%ecx
and    $0x1,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x41(%rbp)
jne    1383 <MFRC522_ToCard+0x233>
movzbl -0x2d(%rbp),%eax
movzbl -0x2b(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    126a <MFRC522_ToCard+0x11a>
mov    $0xd,%edi
mov    $0x80,%esi
call   1070 <ClearBitMask@plt>
cmpl   $0x0,-0x34(%rbp)
je     14a6 <MFRC522_ToCard+0x356>
mov    $0x6,%edi
call   1030 <Read_MFRC522@plt>
and    $0x1b,%eax
cmp    $0x0,%eax
jne    149d <MFRC522_ToCard+0x34d>
movb   $0x0,-0x29(%rbp)
movzbl -0x2d(%rbp),%eax
movzbl -0x2a(%rbp),%ecx
and    %ecx,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     13db <MFRC522_ToCard+0x28b>
movb   $0x1,-0x29(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0xc,%eax
jne    1498 <MFRC522_ToCard+0x348>
mov    $0xa,%edi
call   1030 <Read_MFRC522@plt>
mov    %al,-0x2d(%rbp)
mov    $0xc,%edi
call   1030 <Read_MFRC522@plt>
and    $0x7,%eax
mov    %al,-0x2c(%rbp)
cmpb   $0x0,-0x2c(%rbp)
je     142a <MFRC522_ToCard+0x2da>
movzbl -0x2d(%rbp),%ecx
sub    $0x1,%ecx
shl    $0x3,%ecx
movzbl -0x2c(%rbp),%eax
add    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    1437 <MFRC522_ToCard+0x2e7>
movzbl -0x2d(%rbp),%ecx
shl    $0x3,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x2d(%rbp),%eax
cmp    $0x0,%eax
jne    1448 <MFRC522_ToCard+0x2f8>
movb   $0x1,-0x2d(%rbp)
movzbl -0x2d(%rbp),%eax
cmp    $0x20,%eax
jle    1459 <MFRC522_ToCard+0x309>
movb   $0x20,-0x2d(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
movzbl -0x2d(%rbp),%ecx
cmp    %ecx,%eax
jae    1493 <MFRC522_ToCard+0x343>
mov    $0x9,%edi
call   1030 <Read_MFRC522@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1460 <MFRC522_ToCard+0x310>
jmp    1498 <MFRC522_ToCard+0x348>
jmp    14a1 <MFRC522_ToCard+0x351>
movb   $0x2,-0x29(%rbp)
jmp    14ab <MFRC522_ToCard+0x35b>
jmp    14ab <MFRC522_ToCard+0x35b>
movzbl -0x29(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MFRC522_ToCard>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x10(%rsp)
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%r12d
cmp    $0xc,%r12b
mov    %r8,0x18(%rsp)
je     11a1 <MFRC522_ToCard+0x41>
xor    %eax,%eax
mov    $0x0,%r15d
cmp    $0xe,%r12b
jne    11ac <MFRC522_ToCard+0x4c>
mov    $0x10,%r15d
mov    $0x12,%eax
jmp    11ac <MFRC522_ToCard+0x4c>
mov    $0x30,%r15d
mov    $0x77,%eax
mov    %rax,0x20(%rsp)
add    $0xffffff80,%eax
movzbl %al,%esi
mov    $0x2,%edi
call   1070 <Write_MFRC522@plt>
mov    $0x4,%edi
mov    $0x80,%esi
call   1080 <ClearBitMask@plt>
mov    $0xa,%edi
mov    $0x80,%esi
call   1060 <SetBitMask@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1070 <Write_MFRC522@plt>
test   %bpl,%bpl
je     1218 <MFRC522_ToCard+0xb8>
movzbl %bpl,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%esi
mov    $0x9,%edi
call   1070 <Write_MFRC522@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1200 <MFRC522_ToCard+0xa0>
movzbl %r12b,%esi
mov    $0x1,%edi
call   1070 <Write_MFRC522@plt>
mov    %r12d,0xc(%rsp)
cmp    $0xc,%r12b
jne    1240 <MFRC522_ToCard+0xe0>
mov    $0xd,%edi
mov    $0x80,%esi
call   1060 <SetBitMask@plt>
mov    $0xfffff831,%eax
lea    0xdb4(%rip),%rbx
lea    0xdea(%rip),%r13
lea    0xdd6(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %eax,%r12d
mov    $0x8,%edi
call   1030 <Read_MFRC522@plt>
and    $0x7,%eax
cmp    $0x6,%eax
ja     12e5 <MFRC522_ToCard+0x185>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
lea    0xe2a(%rip),%rdi
jmp    12e0 <MFRC522_ToCard+0x180>
lea    0xe0b(%rip),%rdi
jmp    12e0 <MFRC522_ToCard+0x180>
lea    0xde6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x14,%edi
call   1030 <Read_MFRC522@plt>
lea    0xd6f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12e5 <MFRC522_ToCard+0x185>
lea    0xdae(%rip),%rdi
jmp    12e0 <MFRC522_ToCard+0x180>
lea    0xd89(%rip),%rdi
jmp    12e0 <MFRC522_ToCard+0x180>
mov    %r13,%rdi
jmp    12e0 <MFRC522_ToCard+0x180>
mov    %rbp,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1040 <puts@plt>
mov    $0x4,%edi
call   1030 <Read_MFRC522@plt>
mov    %eax,%r14d
test   %r12d,%r12d
je     1312 <MFRC522_ToCard+0x1b2>
mov    %r14d,%eax
and    $0x1,%eax
jne    1312 <MFRC522_ToCard+0x1b2>
mov    %r14d,%ecx
and    %r15d,%ecx
lea    0x1(%r12),%eax
test   %ecx,%ecx
je     1260 <MFRC522_ToCard+0x100>
mov    $0xd,%edi
mov    $0x80,%esi
call   1080 <ClearBitMask@plt>
mov    $0x2,%r15b
test   %r12d,%r12d
je     13c7 <MFRC522_ToCard+0x267>
mov    $0x6,%edi
call   1030 <Read_MFRC522@plt>
test   $0x1b,%al
jne    13c7 <MFRC522_ToCard+0x267>
and    0x20(%rsp),%r14d
mov    %r14d,%r15d
and    $0x1,%r15b
cmpb   $0xc,0xc(%rsp)
jne    13c7 <MFRC522_ToCard+0x267>
mov    $0xa,%edi
call   1030 <Read_MFRC522@plt>
mov    %eax,%ebp
mov    $0xc,%edi
call   1030 <Read_MFRC522@plt>
movzbl %bpl,%ecx
lea    0x0(,%rcx,8),%edx
mov    %eax,%esi
and    $0x7,%esi
test   $0x7,%al
lea    -0x8(%rdx,%rsi,1),%eax
cmove  %edx,%eax
mov    0x18(%rsp),%rdx
mov    %eax,(%rdx)
test   %cl,%cl
mov    $0x1,%ecx
cmovne %ebp,%ecx
cmp    $0x20,%cl
mov    $0x20,%eax
cmovb  %ecx,%eax
test   %al,%al
je     13c7 <MFRC522_ToCard+0x267>
movzbl %al,%r14d
xor    %ebx,%ebx
mov    0x10(%rsp),%rbp
nopl   0x0(%rax)
mov    $0x9,%edi
call   1030 <Read_MFRC522@plt>
mov    %al,0x0(%rbp,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    13b0 <MFRC522_ToCard+0x250>
mov    %r15d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Modem is idle\0A\00"
@.str.1 = [23 x i8] c"Waiting for StartSend\0A\00"
@.str.2 = [29 x i8] c"TxWait: no RF field present\0A\00"
@.str.3 = [20 x i8] c"Antenna state: %d \0A\00"
@.str.4 = [17 x i8] c"Transmitting...\0A\00"
@.str.5 = [29 x i8] c"RxWait: no RF field present\0A\00"
@.str.6 = [21 x i8] c"Waiting for data...\0A\00"
@.str.7 = [14 x i8] c"Receiving...\0A\00"
define zeroext i8 @MFRC522_ToCard(i8 zeroext %0, i8* %1, i8 zeroext %2, i8* %3, i32* %4) {
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8
%14 = alloca i8
%15 = alloca i8
%16 = alloca i32
store i8 %0, i8* %6
store i8* %1, i8** %7
store i8 %2, i8* %8
store i8* %3, i8** %9
store i32* %4, i32** %10
store i8 2, i8* %11
store i8 0, i8* %12
store i8 0, i8* %13
%17 = load i8, i8* %6
%18 = zext i8 %17 to i32
switch i32 %18, label %21 [
i32 14, label %19
i32 12, label %20
]
19: ; preds = %5
store i8 18, i8* %12
store i8 16, i8* %13
br label %22
20: ; preds = %5
store i8 119, i8* %12
store i8 48, i8* %13
br label %22
21: ; preds = %5
br label %22
22: ; preds = %21, %20, %19
%23 = load i8, i8* %12
%24 = zext i8 %23 to i32
%25 = or i32 %24, 128
%26 = trunc i32 %25 to i8
%27 = call i32 @Write_MFRC522(i32 2, i8 zeroext %26)
%28 = call i32 @ClearBitMask(i32 4, i32 128)
%29 = call i32 @SetBitMask(i32 10, i32 128)
%30 = call i32 @Write_MFRC522(i32 1, i8 zeroext 0)
store i32 0, i32* %16
br label %31
31: ; preds = %43, %22
%32 = load i32, i32* %16
%33 = load i8, i8* %8
%34 = zext i8 %33 to i32
%35 = icmp ult i32 %32, %34
br i1 %35, label %36, label %46
36: ; preds = %31
%37 = load i8*, i8** %7
%38 = load i32, i32* %16
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = call i32 @Write_MFRC522(i32 9, i8 zeroext %41)
br label %43
43: ; preds = %36
%44 = load i32, i32* %16
%45 = add i32 %44, 1
store i32 %45, i32* %16
br label %31
46: ; preds = %31
%47 = load i8, i8* %6
%48 = call i32 @Write_MFRC522(i32 1, i8 zeroext %47)
%49 = load i8, i8* %6
%50 = zext i8 %49 to i32
%51 = icmp eq i32 %50, 12
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = call i32 @SetBitMask(i32 13, i32 128)
br label %54
54: ; preds = %52, %46
store i32 2000, i32* %16
br label %55
55: ; preds = %95, %54
%56 = call i32 @Read_MFRC522(i32 8)
%57 = and i32 %56, 7
switch i32 %57, label %74 [
i32 0, label %58
i32 1, label %60
i32 2, label %62
i32 3, label %66
i32 4, label %68
i32 5, label %70
i32 6, label %72
]
58: ; preds = %55
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %74
60: ; preds = %55
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %74
62: ; preds = %55
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%64 = call i32 @Read_MFRC522(i32 20)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %64)
br label %74
66: ; preds = %55
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %74
68: ; preds = %55
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %74
70: ; preds = %55
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %74
72: ; preds = %55
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %74
74: ; preds = %55, %72, %70, %68, %66, %62, %60, %58
%75 = call i32 @Read_MFRC522(i32 4)
%76 = trunc i32 %75 to i8
store i8 %76, i8* %15
%77 = load i32, i32* %16
%78 = add i32 %77, -1
store i32 %78, i32* %16
br label %79
79: ; preds = %74
%80 = load i32, i32* %16
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %95
82: ; preds = %79
%83 = load i8, i8* %15
%84 = zext i8 %83 to i32
%85 = and i32 %84, 1
%86 = icmp ne i32 %85, 0
br i1 %86, label %95, label %87
87: ; preds = %82
%88 = load i8, i8* %15
%89 = zext i8 %88 to i32
%90 = load i8, i8* %13
%91 = zext i8 %90 to i32
%92 = and i32 %89, %91
%93 = icmp ne i32 %92, 0
%94 = xor i1 %93, true
br label %95
95: ; preds = %87, %82, %79
%96 = phi i1 [ false, %82 ], [ false, %79 ], [ %94, %87 ]
br i1 %96, label %55, label %97
97: ; preds = %95
%98 = call i32 @ClearBitMask(i32 13, i32 128)
%99 = load i32, i32* %16
%100 = icmp ne i32 %99, 0
br i1 %100, label %101, label %170
101: ; preds = %97
%102 = call i32 @Read_MFRC522(i32 6)
%103 = and i32 %102, 27
%104 = icmp ne i32 %103, 0
br i1 %104, label %168, label %105
105: ; preds = %101
store i8 0, i8* %11
%106 = load i8, i8* %15
%107 = zext i8 %106 to i32
%108 = load i8, i8* %12
%109 = zext i8 %108 to i32
%110 = and i32 %107, %109
%111 = and i32 %110, 1
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %114
113: ; preds = %105
store i8 1, i8* %11
br label %114
114: ; preds = %113, %105
%115 = load i8, i8* %6
%116 = zext i8 %115 to i32
%117 = icmp eq i32 %116, 12
br i1 %117, label %118, label %167
118: ; preds = %114
%119 = call i32 @Read_MFRC522(i32 10)
%120 = trunc i32 %119 to i8
store i8 %120, i8* %15
%121 = call i32 @Read_MFRC522(i32 12)
%122 = and i32 %121, 7
%123 = trunc i32 %122 to i8
store i8 %123, i8* %14
%124 = load i8, i8* %14
%125 = icmp ne i8 %124, 0
br i1 %125, label %126, label %135
126: ; preds = %118
%127 = load i8, i8* %15
%128 = zext i8 %127 to i32
%129 = sub nsw i32 %128, 1
%130 = mul nsw i32 %129, 8
%131 = load i8, i8* %14
%132 = zext i8 %131 to i32
%133 = add nsw i32 %130, %132
%134 = load i32*, i32** %10
store i32 %133, i32* %134
br label %140
135: ; preds = %118
%136 = load i8, i8* %15
%137 = zext i8 %136 to i32
%138 = mul nsw i32 %137, 8
%139 = load i32*, i32** %10
store i32 %138, i32* %139
br label %140
140: ; preds = %135, %126
%141 = load i8, i8* %15
%142 = zext i8 %141 to i32
%143 = icmp eq i32 %142, 0
br i1 %143, label %144, label %145
144: ; preds = %140
store i8 1, i8* %15
br label %145
145: ; preds = %144, %140
%146 = load i8, i8* %15
%147 = zext i8 %146 to i32
%148 = icmp sgt i32 %147, 32
br i1 %148, label %149, label %150
149: ; preds = %145
store i8 32, i8* %15
br label %150
150: ; preds = %149, %145
store i32 0, i32* %16
br label %151
151: ; preds = %163, %150
%152 = load i32, i32* %16
%153 = load i8, i8* %15
%154 = zext i8 %153 to i32
%155 = icmp ult i32 %152, %154
br i1 %155, label %156, label %166
156: ; preds = %151
%157 = call i32 @Read_MFRC522(i32 9)
%158 = trunc i32 %157 to i8
%159 = load i8*, i8** %9
%160 = load i32, i32* %16
%161 = zext i32 %160 to i64
%162 = getelementptr inbounds i8, i8* %159, i64 %161
store i8 %158, i8* %162
br label %163
163: ; preds = %156
%164 = load i32, i32* %16
%165 = add i32 %164, 1
store i32 %165, i32* %16
br label %151
166: ; preds = %151
br label %167
167: ; preds = %166, %114
br label %169
168: ; preds = %101
store i8 2, i8* %11
br label %169
169: ; preds = %168, %167
br label %171
170: ; preds = %97
br label %171
171: ; preds = %170, %169
%172 = load i8, i8* %11
ret i8 %172
}

LLVM IR (-O2):
@.str.3 = [20 x i8] c"Antenna state: %d \0A\00"
@str = [13 x i8] c"Receiving...\00"
@str.8 = [20 x i8] c"Waiting for data...\00"
@str.9 = [28 x i8] c"RxWait: no RF field present\00"
@str.10 = [16 x i8] c"Transmitting...\00"
@str.11 = [28 x i8] c"TxWait: no RF field present\00"
@str.12 = [22 x i8] c"Waiting for StartSend\00"
@str.13 = [14 x i8] c"Modem is idle\00"
define zeroext i8 @MFRC522_ToCard(i8 zeroext %0, i8* nocapture %1, i8 zeroext %2, i8* nocapture writeonly %3, i32* nocapture writeonly %4) {
switch i8 %0, label %8 [
i8 14, label %6
i8 12, label %7
]
6: ; preds = %5
br label %8
7: ; preds = %5
br label %8
8: ; preds = %5, %7, %6
%9 = phi i32 [ 0, %5 ], [ 119, %7 ], [ 18, %6 ]
%10 = phi i32 [ 0, %5 ], [ 48, %7 ], [ 16, %6 ]
%11 = trunc i32 %9 to i8
%12 = or i8 %11, -128
%13 = tail call i32 @Write_MFRC522(i32 2, i8 zeroext %12)
%14 = tail call i32 @ClearBitMask(i32 4, i32 128)
%15 = tail call i32 @SetBitMask(i32 10, i32 128)
%16 = tail call i32 @Write_MFRC522(i32 1, i8 zeroext 0)
%17 = icmp eq i8 %2, 0
br i1 %17, label %27, label %18
18: ; preds = %8
%19 = zext i8 %2 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %25, %20 ]
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @Write_MFRC522(i32 9, i8 zeroext %23)
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %19
br i1 %26, label %27, label %20
27: ; preds = %20, %8
%28 = tail call i32 @Write_MFRC522(i32 1, i8 zeroext %0)
%29 = icmp eq i8 %0, 12
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = tail call i32 @SetBitMask(i32 13, i32 128)
br label %32
32: ; preds = %30, %27
br label %33
33: ; preds = %32, %53
%34 = phi i32 [ %55, %53 ], [ 2000, %32 ]
%35 = tail call i32 @Read_MFRC522(i32 8)
%36 = and i32 %35, 7
switch i32 %36, label %53 [
i32 0, label %37
i32 1, label %39
i32 2, label %41
i32 3, label %45
i32 4, label %47
i32 5, label %49
i32 6, label %51
]
37: ; preds = %33
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.13, i64 0, i64 0))
br label %53
39: ; preds = %33
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.12, i64 0, i64 0))
br label %53
41: ; preds = %33
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.11, i64 0, i64 0))
%43 = tail call i32 @Read_MFRC522(i32 20)
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %43)
br label %53
45: ; preds = %33
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.10, i64 0, i64 0))
br label %53
47: ; preds = %33
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.9, i64 0, i64 0))
br label %53
49: ; preds = %33
%50 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0))
br label %53
51: ; preds = %33
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %53
53: ; preds = %33, %51, %49, %47, %45, %41, %39, %37
%54 = tail call i32 @Read_MFRC522(i32 4)
%55 = add i32 %34, -1
%56 = icmp eq i32 %55, 0
%57 = xor i1 %56, true
%58 = and i32 %54, 1
%59 = icmp eq i32 %58, 0
%60 = select i1 %57, i1 %59, i1 false
%61 = and i32 %54, %10
%62 = icmp eq i32 %61, 0
%63 = select i1 %60, i1 %62, i1 false
br i1 %63, label %33, label %64
64: ; preds = %53
%65 = tail call i32 @ClearBitMask(i32 13, i32 128)
br i1 %56, label %102, label %66
66: ; preds = %64
%67 = tail call i32 @Read_MFRC522(i32 6)
%68 = and i32 %67, 27
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %102
70: ; preds = %66
%71 = and i32 %54, %9
%72 = trunc i32 %71 to i8
%73 = and i8 %72, 1
br i1 %29, label %74, label %102
74: ; preds = %70
%75 = tail call i32 @Read_MFRC522(i32 10)
%76 = trunc i32 %75 to i8
%77 = tail call i32 @Read_MFRC522(i32 12)
%78 = trunc i32 %77 to i8
%79 = and i8 %78, 7
%80 = icmp eq i8 %79, 0
%81 = shl i32 %75, 3
%82 = and i32 %81, 2040
%83 = add nsw i32 %82, -8
%84 = zext i8 %79 to i32
%85 = or i32 %83, %84
%86 = select i1 %80, i32 %82, i32 %85
store i32 %86, i32* %4
%87 = and i32 %75, 255
%88 = icmp eq i32 %87, 0
%89 = select i1 %88, i8 1, i8 %76
%90 = icmp ult i8 %89, 32
%91 = select i1 %90, i8 %89, i8 32
%92 = icmp eq i8 %91, 0
br i1 %92, label %102, label %93
93: ; preds = %74
%94 = zext i8 %91 to i64
br label %95
95: ; preds = %93, %95
%96 = phi i64 [ 0, %93 ], [ %100, %95 ]
%97 = tail call i32 @Read_MFRC522(i32 9)
%98 = trunc i32 %97 to i8
%99 = getelementptr inbounds i8, i8* %3, i64 %96
store i8 %98, i8* %99
%100 = add nuw nsw i64 %96, 1
%101 = icmp eq i64 %100, %94
br i1 %101, label %102, label %95
102: ; preds = %95, %74, %66, %64, %70
%103 = phi i8 [ %73, %70 ], [ 2, %64 ], [ 2, %66 ], [ %73, %74 ], [ %73, %95 ]
ret i8 %103
}