#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_Write(char blockAddr, char *writeData) {
  char _status;
  unsigned recvBits;
  char i;
  char buff[18];
  buff[0] = 0xA0;
  buff[1] = blockAddr;
  MFRC522_CRC(buff, 2, &buff[2]);
  _status = MFRC522_ToCard(0x0C, buff, 4, buff, &recvBits);
  if ((_status != 0) || (recvBits != 4) || ((buff[0] & 0x0F) != 0x0A)) {
    _status = 2;
  }
  if (_status == 0) {
    for (i = 0; i < 16; i++) {
      buff[i] = writeData[i];
    }
    MFRC522_CRC(buff, 16, &buff[16]);
    _status = MFRC522_ToCard(0x0C, buff, 18, buff, &recvBits);
    if ((_status != 0) || (recvBits != 4) || ((buff[0] & 0x0F) != 0x0A)) {
      _status = 2;
    }
  }
  return _status;
}


x86 assembly (clang, -O0):
<MFRC522_Write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0xa0,-0x30(%rbp)
mov    -0x1(%rbp),%al
mov    %al,-0x2f(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rdx
add    $0x2,%rdx
mov    $0x2,%esi
call   1030 <MFRC522_CRC@plt>
lea    -0x30(%rbp),%rsi
lea    -0x30(%rbp),%rcx
mov    $0xc,%edi
mov    $0x4,%edx
lea    -0x18(%rbp),%r8
call   1040 <MFRC522_ToCard@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    1197 <MFRC522_Write+0x77>
cmpl   $0x4,-0x18(%rbp)
jne    1197 <MFRC522_Write+0x77>
movsbl -0x30(%rbp),%eax
and    $0xf,%eax
cmp    $0xa,%eax
je     119b <MFRC522_Write+0x7b>
movb   $0x2,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    123f <MFRC522_Write+0x11f>
movb   $0x0,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x10,%eax
jge    11db <MFRC522_Write+0xbb>
mov    -0x10(%rbp),%rax
movsbq -0x19(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movsbq -0x19(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x19(%rbp),%al
add    $0x1,%al
mov    %al,-0x19(%rbp)
jmp    11ac <MFRC522_Write+0x8c>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rdx
add    $0x10,%rdx
mov    $0x10,%esi
call   1030 <MFRC522_CRC@plt>
lea    -0x30(%rbp),%rsi
lea    -0x30(%rbp),%rcx
mov    $0xc,%edi
mov    $0x12,%edx
lea    -0x18(%rbp),%r8
call   1040 <MFRC522_ToCard@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    1236 <MFRC522_Write+0x116>
cmpl   $0x4,-0x18(%rbp)
jne    1236 <MFRC522_Write+0x116>
movsbl -0x30(%rbp),%eax
and    $0xf,%eax
cmp    $0xa,%eax
je     123a <MFRC522_Write+0x11a>
movb   $0x2,-0x11(%rbp)
jmp    123f <MFRC522_Write+0x11f>
movsbl -0x11(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MFRC522_Write>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
movb   $0xa0,0x10(%rsp)
mov    %dil,0x11(%rsp)
lea    0x12(%rsp),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <MFRC522_CRC@plt>
lea    0xc(%rsp),%r8
mov    $0xc,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1040 <MFRC522_ToCard@plt>
mov    $0x2,%bl
test   %al,%al
jne    11cd <MFRC522_Write+0xad>
cmpl   $0x4,0xc(%rsp)
jne    11cd <MFRC522_Write+0xad>
mov    0x10(%rsp),%al
and    $0xf,%al
cmp    $0xa,%al
jne    11cd <MFRC522_Write+0xad>
movups (%r14),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x20(%rsp),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x10,%esi
call   1030 <MFRC522_CRC@plt>
lea    0xc(%rsp),%r8
mov    $0xc,%edi
mov    %r14,%rsi
mov    $0x12,%edx
mov    %r14,%rcx
call   1040 <MFRC522_ToCard@plt>
test   %al,%al
jne    11cd <MFRC522_Write+0xad>
cmpl   $0x4,0xc(%rsp)
jne    11cd <MFRC522_Write+0xad>
mov    0x10(%rsp),%al
and    $0xf,%al
cmp    $0xa,%al
jne    11cd <MFRC522_Write+0xad>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define signext i8 @MFRC522_Write(i8 signext %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i8
%8 = alloca [18 x i8]
store i8 %0, i8* %3
store i8* %1, i8** %4
%9 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 0
store i8 -96, i8* %9
%10 = load i8, i8* %3
%11 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 1
store i8 %10, i8* %11
%12 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 0
%13 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 2
%14 = call i32 @MFRC522_CRC(i8* %12, i32 2, i8* %13)
%15 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 0
%16 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 0
%17 = call signext i8 @MFRC522_ToCard(i32 12, i8* %15, i32 4, i8* %16, i32* %6)
store i8 %17, i8* %5
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %2
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 4
br i1 %23, label %30, label %24
24: ; preds = %21
%25 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = and i32 %27, 15
%29 = icmp ne i32 %28, 10
br i1 %29, label %30, label %31
30: ; preds = %24, %21, %2
store i8 2, i8* %5
br label %31
31: ; preds = %30, %24
%32 = load i8, i8* %5
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %73
35: ; preds = %31
store i8 0, i8* %7
br label %36
36: ; preds = %49, %35
%37 = load i8, i8* %7
%38 = sext i8 %37 to i32
%39 = icmp slt i32 %38, 16
br i1 %39, label %40, label %52
40: ; preds = %36
%41 = load i8*, i8** %4
%42 = load i8, i8* %7
%43 = sext i8 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = load i8, i8* %7
%47 = sext i8 %46 to i64
%48 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 %47
store i8 %45, i8* %48
br label %49
49: ; preds = %40
%50 = load i8, i8* %7
%51 = add i8 %50, 1
store i8 %51, i8* %7
br label %36
52: ; preds = %36
%53 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 0
%54 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 16
%55 = call i32 @MFRC522_CRC(i8* %53, i32 16, i8* %54)
%56 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 0
%57 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 0
%58 = call signext i8 @MFRC522_ToCard(i32 12, i8* %56, i32 18, i8* %57, i32* %6)
store i8 %58, i8* %5
%59 = load i8, i8* %5
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 0
br i1 %61, label %71, label %62
62: ; preds = %52
%63 = load i32, i32* %6
%64 = icmp ne i32 %63, 4
br i1 %64, label %71, label %65
65: ; preds = %62
%66 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 0
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = and i32 %68, 15
%70 = icmp ne i32 %69, 10
br i1 %70, label %71, label %72
71: ; preds = %65, %62, %52
store i8 2, i8* %5
br label %72
72: ; preds = %71, %65
br label %73
73: ; preds = %72, %31
%74 = load i8, i8* %5
ret i8 %74
}

LLVM IR (-O2):
define signext i8 @MFRC522_Write(i8 signext %0, i8* nocapture %1) {
%3 = alloca i32
%4 = alloca [18 x i8]
%5 = getelementptr inbounds [18 x i8], [18 x i8]* %4, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [18 x i8], [18 x i8]* %4, i64 0, i64 0
store i8 -96, i8* %7
%8 = getelementptr inbounds [18 x i8], [18 x i8]* %4, i64 0, i64 1
store i8 %0, i8* %8
%9 = getelementptr inbounds [18 x i8], [18 x i8]* %4, i64 0, i64 2
%10 = call i32 @MFRC522_CRC(i8* %7, i32 2, i8* %9)
%11 = call signext i8 @MFRC522_ToCard(i32 12, i8* %7, i32 4, i8* %7, i32* %3)
%12 = icmp ne i8 %11, 0
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 4
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %33, label %16
16: ; preds = %2
%17 = load i8, i8* %7
%18 = and i8 %17, 15
%19 = icmp eq i8 %18, 10
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = getelementptr inbounds [18 x i8], [18 x i8]* %4, i64 0, i64 16
%22 = call i32 @MFRC522_CRC(i8* %7, i32 16, i8* %21)
%23 = call signext i8 @MFRC522_ToCard(i32 12, i8* %7, i32 18, i8* %7, i32* %3)
%24 = icmp ne i8 %23, 0
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, 4
%27 = select i1 %24, i1 true, i1 %26
br i1 %27, label %32, label %28
28: ; preds = %20
%29 = load i8, i8* %7
%30 = and i8 %29, 15
%31 = icmp eq i8 %30, 10
br i1 %31, label %33, label %32
32: ; preds = %28, %20
br label %33
33: ; preds = %16, %2, %28, %32
%34 = phi i8 [ 2, %32 ], [ 0, %28 ], [ 2, %2 ], [ 2, %16 ]
ret i8 %34
}