#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 */
char EOF;
scalar_t__ MFRC522_Debug_CardDump(int *);
scalar_t__ MFRC522_Debug_DumpSector(int *, int);
scalar_t__ MFRC522_Debug_Write(int, char *, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int scan_loop(uint8_t *CardID) {
  while (1) {
    char input[32];
    int block_start;
    printf("RC522>");
    printf("%02X%02X%02X%02X>", CardID[0], CardID[1], CardID[2], CardID[3]);
    scanf("%s", input);
    puts((char *)input);
    if (strcmp(input, "halt") == 0) {
      return 1;
    } else if (strcmp(input, "dump") == 0) {
      if (MFRC522_Debug_CardDump(CardID) < 0)
        return -1;
    } else if (strcmp(input, "read") == 0) {
      scanf("%d", &block_start);
      if (MFRC522_Debug_DumpSector(CardID, block_start) < 0) {
        return -1;
      }
    } else if (strcmp(input, "writestr") == 0) {
      char write_buffer[256], c;
      size_t len = 0;
      scanf("%d", &block_start);
      while ((c = getchar()) != '\n' && c != EOF)
        ;
      printf(">");
      if (len >= 0) {
        if (MFRC522_Debug_Write(block_start, write_buffer,
                                strlen(write_buffer)) < 0) {
          return -1;
        }
      }
    } else {
      printf("Usage:\r\n"
             "\tread <blockstart>\r\n"
             "\tdump\r\n"
             "\twritestr <blockaddr>\r\n");
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<scan_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
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
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   10a0 <scanf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <puts@plt>
lea    -0x30(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1218 <scan_loop+0x88>
movl   $0x1,-0x4(%rbp)
jmp    13d6 <scan_loop+0x246>
lea    -0x30(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1256 <scan_loop+0xc6>
mov    -0x10(%rbp),%rdi
call   10b0 <MFRC522_Debug_CardDump@plt>
cmp    $0x0,%rax
jge    1251 <scan_loop+0xc1>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d6 <scan_loop+0x246>
jmp    13cc <scan_loop+0x23c>
lea    -0x30(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12a9 <scan_loop+0x119>
lea    0xdb4(%rip),%rdi
lea    -0x34(%rbp),%rsi
mov    $0x0,%al
call   10a0 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1090 <MFRC522_Debug_DumpSector@plt>
cmp    $0x0,%rax
jge    12a4 <scan_loop+0x114>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d6 <scan_loop+0x246>
jmp    13c7 <scan_loop+0x237>
lea    -0x30(%rbp),%rdi
lea    0xd7a(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    13a8 <scan_loop+0x218>
movq   $0x0,-0x150(%rbp)
lea    0xd56(%rip),%rdi
lea    -0x34(%rbp),%rsi
mov    $0x0,%al
call   10a0 <scanf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0x141(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x151(%rbp)
je     131d <scan_loop+0x18d>
movsbl -0x141(%rbp),%eax
mov    0x2cd9(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x151(%rbp)
mov    -0x151(%rbp),%al
test   $0x1,%al
jne    1330 <scan_loop+0x1a0>
jmp    1335 <scan_loop+0x1a5>
jmp    12e0 <scan_loop+0x150>
lea    0xcc9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x150(%rbp)
jb     13a3 <scan_loop+0x213>
mov    -0x34(%rbp),%eax
mov    %eax,-0x164(%rbp)
lea    -0x140(%rbp),%rax
mov    %rax,-0x160(%rbp)
lea    -0x140(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x164(%rbp),%edi
mov    -0x160(%rbp),%rsi
mov    %eax,%edx
call   1030 <MFRC522_Debug_Write@plt>
cmp    $0x0,%rax
jge    139e <scan_loop+0x20e>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d6 <scan_loop+0x246>
jmp    13a3 <scan_loop+0x213>
jmp    13c2 <scan_loop+0x232>
lea    0xc88(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13d6 <scan_loop+0x246>
jmp    13c7 <scan_loop+0x237>
jmp    13cc <scan_loop+0x23c>
jmp    13d1 <scan_loop+0x241>
jmp    119f <scan_loop+0xf>
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rdi,%rbx
lea    0xe45(%rip),%r14
lea    0xe45(%rip),%r12
lea    0xe50(%rip),%rbp
lea    0x10(%rsp),%r13
mov    0x2e13(%rip),%r15
jmp    11f1 <scan_loop+0x51>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10c0 <MFRC522_Debug_CardDump@plt>
test   %rax,%rax
js     1328 <scan_loop+0x188>
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%rbx),%esi
mov    0x4(%rbx),%edx
mov    0x8(%rbx),%ecx
mov    0xc(%rbx),%r8d
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   10b0 <scanf@plt>
mov    %r13,%rdi
call   1050 <puts@plt>
mov    %r13,%rdi
lea    0xdec(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     132f <scan_loop+0x18f>
mov    %r13,%rdi
lea    0xdd9(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11e0 <scan_loop+0x40>
mov    %r13,%rdi
lea    0xdca(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1300 <scan_loop+0x160>
mov    %r13,%rdi
lea    0xdba(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1336 <scan_loop+0x196>
mov    %r14,%r12
lea    0xd9f(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   10b0 <scanf@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    $0xa,%al
je     12b0 <scan_loop+0x110>
cmp    (%r15),%al
jne    12a0 <scan_loop+0x100>
mov    $0x3e,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%r14d
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <MFRC522_Debug_Write@plt>
test   %rax,%rax
mov    %r12,%r14
lea    0xd21(%rip),%r12
lea    0xd2c(%rip),%rbp
jns    11f1 <scan_loop+0x51>
jmp    1328 <scan_loop+0x188>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xd24(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   10b0 <scanf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   10a0 <MFRC522_Debug_DumpSector@plt>
test   %rax,%rax
jns    11f1 <scan_loop+0x51>
mov    $0xffffffff,%eax
jmp    1344 <scan_loop+0x1a4>
mov    $0x1,%eax
jmp    1344 <scan_loop+0x1a4>
lea    0xcfa(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"RC522>\00"
@.str.1 = [18 x i8] c"%02X%02X%02X%02X>\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [5 x i8] c"halt\00"
@.str.4 = [5 x i8] c"dump\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [9 x i8] c"writestr\00"
@EOF = global i8 0
@.str.8 = [2 x i8] c">\00"
@.str.9 = [59 x i8] c"Usage:\0D\0A\09read <blockstart>\0D\0A\09dump\0D\0A\09writestr <blockaddr>\0D\0A\00"
define i32 @scan_loop(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [32 x i8]
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i8
%8 = alloca i64
store i32* %0, i32** %3
br label %9
9: ; preds = %1, %92
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = load i32*, i32** %3
%12 = getelementptr inbounds i32, i32* %11, i64 0
%13 = load i32, i32* %12
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 1
%16 = load i32, i32* %15
%17 = load i32*, i32** %3
%18 = getelementptr inbounds i32, i32* %17, i64 2
%19 = load i32, i32* %18
%20 = load i32*, i32** %3
%21 = getelementptr inbounds i32, i32* %20, i64 3
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %16, i32 %19, i32 %22)
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%27 = call i32 @puts(i8* %26)
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %9
store i32 1, i32* %2
br label %93
32: ; preds = %9
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %32
%37 = load i32*, i32** %3
%38 = call i64 @MFRC522_Debug_CardDump(i32* %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36
store i32 -1, i32* %2
br label %93
41: ; preds = %36
br label %91
42: ; preds = %32
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %42
%47 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %5)
%48 = load i32*, i32** %3
%49 = load i32, i32* %5
%50 = call i64 @MFRC522_Debug_DumpSector(i32* %48, i32 %49)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %46
store i32 -1, i32* %2
br label %93
53: ; preds = %46
br label %90
54: ; preds = %42
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%56 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %87
58: ; preds = %54
store i64 0, i64* %8
%59 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %5)
br label %60
60: ; preds = %72, %58
%61 = call signext i8 (...) @getchar()
store i8 %61, i8* %7
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 10
br i1 %63, label %64, label %70
64: ; preds = %60
%65 = load i8, i8* %7
%66 = sext i8 %65 to i32
%67 = load i8, i8* @EOF
%68 = sext i8 %67 to i32
%69 = icmp ne i32 %66, %68
br label %70
70: ; preds = %64, %60
%71 = phi i1 [ false, %60 ], [ %69, %64 ]
br i1 %71, label %72, label %73
72: ; preds = %70
br label %60
73: ; preds = %70
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%75 = load i64, i64* %8
%76 = icmp uge i64 %75, 0
br i1 %76, label %77, label %86
77: ; preds = %73
%78 = load i32, i32* %5
%79 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%81 = call i32 @strlen(i8* %80)
%82 = call i64 @MFRC522_Debug_Write(i32 %78, i8* %79, i32 %81)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %77
store i32 -1, i32* %2
br label %93
85: ; preds = %77
br label %86
86: ; preds = %85, %73
br label %89
87: ; preds = %54
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %2
br label %93
89: ; preds = %86
br label %90
90: ; preds = %89, %53
br label %91
91: ; preds = %90, %41
br label %92
92: ; preds = %91
br label %9
93: ; preds = %87, %84, %52, %40, %31
%94 = load i32, i32* %2
ret i32 %94
}

LLVM IR (-O2):
@.str = [7 x i8] c"RC522>\00"
@.str.1 = [18 x i8] c"%02X%02X%02X%02X>\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [5 x i8] c"halt\00"
@.str.4 = [5 x i8] c"dump\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [9 x i8] c"writestr\00"
@EOF = global i8 0
@str = [58 x i8] c"Usage:\0D\0A\09read <blockstart>\0D\0A\09dump\0D\0A\09writestr <blockaddr>\0D\00"
define i32 @scan_loop(i32* %0) {
%2 = alloca [32 x i8]
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds i32, i32* %0, i64 1
%8 = getelementptr inbounds i32, i32* %0, i64 2
%9 = getelementptr inbounds i32, i32* %0, i64 3
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
br label %11
11: ; preds = %55, %1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %0
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = load i32, i32* %9
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14, i32 %15, i32 %16)
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%19 = call i32 @puts(i8* %5)
%20 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %56, label %22
22: ; preds = %11
%23 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = call i64 @MFRC522_Debug_CardDump(i32* %0)
%27 = icmp slt i64 %26, 0
br i1 %27, label %56, label %55
28: ; preds = %22
%29 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%33 = load i32, i32* %3
%34 = call i64 @MFRC522_Debug_DumpSector(i32* %0, i32 %33)
%35 = icmp slt i64 %34, 0
br i1 %35, label %56, label %55
36: ; preds = %28
%37 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %53
39: ; preds = %36
%40 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
br label %41
41: ; preds = %41, %39
%42 = call signext i8 (...) @getchar()
%43 = icmp ne i8 %42, 10
%44 = load i8, i8* @EOF
%45 = icmp ne i8 %42, %44
%46 = select i1 %43, i1 %45, i1 false
br i1 %46, label %41, label %47
47: ; preds = %41
%48 = call i32 @putchar(i32 62)
%49 = load i32, i32* %3
%50 = call i32 @strlen(i8* %10)
%51 = call i64 @MFRC522_Debug_Write(i32 %49, i8* %10, i32 %50)
%52 = icmp slt i64 %51, 0
br i1 %52, label %56, label %55
53: ; preds = %36
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
br label %56
55: ; preds = %31, %47, %25
br label %11
56: ; preds = %47, %11, %25, %31, %53
%57 = phi i32 [ 0, %53 ], [ -1, %31 ], [ -1, %25 ], [ 1, %11 ], [ -1, %47 ]
ret i32 %57
}