#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 NF_IsBadBlock(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
void K9Fxx08_badcheck(unsigned short type) {
  int i, badcount = 0, bad, numBlocks;
  if (type == 0xec73)
    numBlocks = 1024;
  if (type == 0xec75)
    numBlocks = 2048;
  printf("Checking NAND Blocks");
  for (i = 0; i < numBlocks; i++) {
    if (i % 64 == 0)
      printf("\n %08X: ", i * 0x4000);
    bad = NF_IsBadBlock(i);
    if (bad != 0xFF) {
      printf("b");
      badcount++;
    } else {
      printf(".");
    }
    fflush(stdout);
  }
  printf("\nTotal Bad Blocks: %d\n", badcount);
}


x86 assembly (clang, -O0):
<K9Fxx08_badcheck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movl   $0x0,-0xc(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0xec73,%eax
jne    115c <K9Fxx08_badcheck+0x2c>
movl   $0x400,-0x14(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0xec75,%eax
jne    1172 <K9Fxx08_badcheck+0x42>
movl   $0x800,-0x14(%rbp)
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1219 <K9Fxx08_badcheck+0xe9>
mov    -0x8(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11bb <K9Fxx08_badcheck+0x8b>
mov    -0x8(%rbp),%esi
shl    $0xe,%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <NF_IsBadBlock@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xff,-0x10(%rbp)
je     11ef <K9Fxx08_badcheck+0xbf>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11fd <K9Fxx08_badcheck+0xcd>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1187 <K9Fxx08_badcheck+0x57>
mov    -0xc(%rbp),%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<K9Fxx08_badcheck>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r12d,%r12d
cmp    $0xec75,%edi
sete   %r12b
shl    $0xa,%r12d
add    $0x400,%r12d
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9d(%rip),%r14
mov    0x2e61(%rip),%r13
xor    %ebx,%ebx
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    11b1 <K9Fxx08_badcheck+0x71>
nopl   0x0(%rax,%rax,1)
mov    $0x2e,%edi
call   1030 <putchar@plt>
mov    0x0(%r13),%edi
call   1050 <fflush@plt>
add    $0x1,%ebp
add    $0x4000,%ebx
cmp    %ebp,%r12d
je     11e1 <K9Fxx08_badcheck+0xa1>
test   $0x3f,%bpl
jne    11c3 <K9Fxx08_badcheck+0x83>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <NF_IsBadBlock@plt>
cmp    $0xff,%eax
je     1190 <K9Fxx08_badcheck+0x50>
mov    $0x62,%edi
call   1030 <putchar@plt>
add    $0x1,%r15d
jmp    119a <K9Fxx08_badcheck+0x5a>
lea    0xe36(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Checking NAND Blocks\00"
@.str.1 = [9 x i8] c"\0A %08X: \00"
@.str.2 = [2 x i8] c"b\00"
@.str.3 = [2 x i8] c".\00"
@stdout = global i32 0
@.str.4 = [23 x i8] c"\0ATotal Bad Blocks: %d\0A\00"
define void @K9Fxx08_badcheck(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i16 %0, i16* %2
store i32 0, i32* %4
%7 = load i16, i16* %2
%8 = zext i16 %7 to i32
%9 = icmp eq i32 %8, 60531
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 1024, i32* %6
br label %11
11: ; preds = %10, %1
%12 = load i16, i16* %2
%13 = zext i16 %12 to i32
%14 = icmp eq i32 %13, 60533
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 2048, i32* %6
br label %16
16: ; preds = %15, %11
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %18
18: ; preds = %44, %16
%19 = load i32, i32* %3
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %47
22: ; preds = %18
%23 = load i32, i32* %3
%24 = srem i32 %23, 64
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* %3
%28 = mul nsw i32 %27, 16384
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %26, %22
%31 = load i32, i32* %3
%32 = call i32 @NF_IsBadBlock(i32 %31)
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = icmp ne i32 %33, 255
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %41
39: ; preds = %30
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %35
%42 = load i32, i32* @stdout
%43 = call i32 @fflush(i32 %42)
br label %44
44: ; preds = %41
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %18
47: ; preds = %18
%48 = load i32, i32* %4
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %48)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"Checking NAND Blocks\00"
@.str.1 = [9 x i8] c"\0A %08X: \00"
@stdout = global i32 0
@.str.4 = [23 x i8] c"\0ATotal Bad Blocks: %d\0A\00"
define void @K9Fxx08_badcheck(i16 zeroext %0) {
%2 = icmp eq i16 %0, -5003
%3 = select i1 %2, i32 2048, i32 1024
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %1, %21
%6 = phi i32 [ 0, %1 ], [ %25, %21 ]
%7 = phi i32 [ 0, %1 ], [ %22, %21 ]
%8 = and i32 %6, 63
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = shl nsw i32 %6, 14
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %10, %5
%14 = tail call i32 @NF_IsBadBlock(i32 %6)
%15 = icmp eq i32 %14, 255
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = tail call i32 @putchar(i32 98)
%18 = add nsw i32 %7, 1
br label %21
19: ; preds = %13
%20 = tail call i32 @putchar(i32 46)
br label %21
21: ; preds = %19, %16
%22 = phi i32 [ %18, %16 ], [ %7, %19 ]
%23 = load i32, i32* @stdout
%24 = tail call i32 @fflush(i32 %23)
%25 = add nuw nsw i32 %6, 1
%26 = icmp eq i32 %25, %3
br i1 %26, label %27, label %5
27: ; preds = %21
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %22)
ret void
}