int nand_isbadblock_p2048(unsigned int block) {
  unsigned int page;
  int bad = 0;
  page = block << 6;
  do {
    (*(volatile unsigned long *)(0x4E000000 + 0x04)) &= (~(1 << 1));
  } while (0);
  do {
    (*(volatile unsigned long *)(0x4E000000 + 0x20)) |= (1 << 2);
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x08)) = 0x00;
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x0C)) = 2048 & 0xFF;
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x0C)) = (2048 >> 8) & 0xFF;
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x0C)) = page & 0xFF;
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x0C)) = (page >> 8) & 0xFF;
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x0C)) = (page >> 16) & 0xFF;
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x08)) = 0x30;
  } while (0);
  while (!((*(volatile unsigned long *)(0x4E000000 + 0x20)) & (1 << 2)))
    ;
  bad = ((*(volatile unsigned char *)(0x4E000000 + 0x10)));
  do {
    (*(volatile unsigned long *)(0x4E000000 + 0x04)) |= (1 << 1);
  } while (0);
  return (bad != 0xFF);
}


x86 assembly (clang, -O0):
<nand_isbadblock_p2048>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x6,%eax
mov    %eax,-0x8(%rbp)
mov    $0x4e000004,%eax
mov    (%rax),%rcx
and    $0xfffffffffffffffd,%rcx
mov    $0x4e000004,%eax
mov    %rcx,(%rax)
jmp    1130 <nand_isbadblock_p2048+0x30>
mov    $0x4e000020,%eax
mov    (%rax),%rcx
or     $0x4,%rcx
mov    $0x4e000020,%eax
mov    %rcx,(%rax)
jmp    1149 <nand_isbadblock_p2048+0x49>
mov    $0x4e000008,%eax
movb   $0x0,(%rax)
jmp    1156 <nand_isbadblock_p2048+0x56>
mov    $0x4e00000c,%eax
movb   $0x0,(%rax)
jmp    1163 <nand_isbadblock_p2048+0x63>
mov    $0x4e00000c,%eax
movb   $0x8,(%rax)
jmp    1170 <nand_isbadblock_p2048+0x70>
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    $0x4e00000c,%eax
mov    %cl,(%rax)
jmp    1186 <nand_isbadblock_p2048+0x86>
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    $0x4e00000c,%eax
mov    %cl,(%rax)
jmp    119f <nand_isbadblock_p2048+0x9f>
mov    -0x8(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    $0x4e00000c,%eax
mov    %cl,(%rax)
jmp    11b8 <nand_isbadblock_p2048+0xb8>
mov    $0x4e000008,%eax
movb   $0x30,(%rax)
jmp    11c5 <nand_isbadblock_p2048+0xc5>
mov    $0x4e000020,%eax
mov    (%rax),%rax
and    $0x4,%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e7 <nand_isbadblock_p2048+0xe7>
jmp    11ec <nand_isbadblock_p2048+0xec>
jmp    11c5 <nand_isbadblock_p2048+0xc5>
mov    $0x4e000010,%eax
mov    (%rax),%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
mov    $0x4e000004,%eax
mov    (%rax),%rcx
or     $0x2,%rcx
mov    $0x4e000004,%eax
mov    %rcx,(%rax)
cmpl   $0xff,-0xc(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<nand_isbadblock_p2048>:
mov    %edi,%eax
shl    $0x6,%eax
andq   $0xfffffffffffffffd,0x4e000004
4e fd
orq    $0x4,0x4e000020
4e 04
movb   $0x0,0x4e000008
movb   $0x0,0x4e00000c
movb   $0x8,0x4e00000c
08
mov    %al,0x4e00000c
mov    %edi,%eax
shr    $0x2,%eax
mov    %al,0x4e00000c
shr    $0xa,%edi
mov    %dil,0x4e00000c
4e
movb   $0x30,0x4e000008
30
cs nopw 0x0(%rax,%rax,1)
nop
testq  $0x4,0x4e000020
je     1160 <nand_isbadblock_p2048+0x60>
mov    0x4e000010,%cl
orq    $0x2,0x4e000004
4e 02
xor    %eax,%eax
cmp    $0xff,%cl
setne  %al
ret

LLVM IR (-O0):
define i32 @nand_isbadblock_p2048(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
%5 = load i32, i32* %2
%6 = shl i32 %5, 6
store i32 %6, i32* %3
br label %7
7: ; preds = %1
%8 = load volatile i64, i64* inttoptr (i64 1308622852 to i64*)
%9 = and i64 %8, -3
store volatile i64 %9, i64* inttoptr (i64 1308622852 to i64*)
br label %10
10: ; preds = %7
br label %11
11: ; preds = %10
%12 = load volatile i64, i64* inttoptr (i64 1308622880 to i64*)
%13 = or i64 %12, 4
store volatile i64 %13, i64* inttoptr (i64 1308622880 to i64*)
br label %14
14: ; preds = %11
br label %15
15: ; preds = %14
store volatile i8 0, i8* inttoptr (i64 1308622856 to i8*)
br label %16
16: ; preds = %15
br label %17
17: ; preds = %16
store volatile i8 0, i8* inttoptr (i64 1308622860 to i8*)
br label %18
18: ; preds = %17
br label %19
19: ; preds = %18
store volatile i8 8, i8* inttoptr (i64 1308622860 to i8*)
br label %20
20: ; preds = %19
br label %21
21: ; preds = %20
%22 = load i32, i32* %3
%23 = and i32 %22, 255
%24 = trunc i32 %23 to i8
store volatile i8 %24, i8* inttoptr (i64 1308622860 to i8*)
br label %25
25: ; preds = %21
br label %26
26: ; preds = %25
%27 = load i32, i32* %3
%28 = lshr i32 %27, 8
%29 = and i32 %28, 255
%30 = trunc i32 %29 to i8
store volatile i8 %30, i8* inttoptr (i64 1308622860 to i8*)
br label %31
31: ; preds = %26
br label %32
32: ; preds = %31
%33 = load i32, i32* %3
%34 = lshr i32 %33, 16
%35 = and i32 %34, 255
%36 = trunc i32 %35 to i8
store volatile i8 %36, i8* inttoptr (i64 1308622860 to i8*)
br label %37
37: ; preds = %32
br label %38
38: ; preds = %37
store volatile i8 48, i8* inttoptr (i64 1308622856 to i8*)
br label %39
39: ; preds = %38
br label %40
40: ; preds = %45, %39
%41 = load volatile i64, i64* inttoptr (i64 1308622880 to i64*)
%42 = and i64 %41, 4
%43 = icmp ne i64 %42, 0
%44 = xor i1 %43, true
br i1 %44, label %45, label %46
45: ; preds = %40
br label %40
46: ; preds = %40
%47 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%48 = zext i8 %47 to i32
store i32 %48, i32* %4
br label %49
49: ; preds = %46
%50 = load volatile i64, i64* inttoptr (i64 1308622852 to i64*)
%51 = or i64 %50, 2
store volatile i64 %51, i64* inttoptr (i64 1308622852 to i64*)
br label %52
52: ; preds = %49
%53 = load i32, i32* %4
%54 = icmp ne i32 %53, 255
%55 = zext i1 %54 to i32
ret i32 %55
}

LLVM IR (-O2):
define i32 @nand_isbadblock_p2048(i32 %0) {
%2 = shl i32 %0, 6
%3 = load volatile i64, i64* inttoptr (i64 1308622852 to i64*)
%4 = and i64 %3, -3
store volatile i64 %4, i64* inttoptr (i64 1308622852 to i64*)
%5 = load volatile i64, i64* inttoptr (i64 1308622880 to i64*)
%6 = or i64 %5, 4
store volatile i64 %6, i64* inttoptr (i64 1308622880 to i64*)
store volatile i8 0, i8* inttoptr (i64 1308622856 to i8*)
store volatile i8 0, i8* inttoptr (i64 1308622860 to i8*)
store volatile i8 8, i8* inttoptr (i64 1308622860 to i8*)
%7 = trunc i32 %2 to i8
store volatile i8 %7, i8* inttoptr (i64 1308622860 to i8*)
%8 = lshr i32 %2, 8
%9 = trunc i32 %8 to i8
store volatile i8 %9, i8* inttoptr (i64 1308622860 to i8*)
%10 = lshr i32 %2, 16
%11 = trunc i32 %10 to i8
store volatile i8 %11, i8* inttoptr (i64 1308622860 to i8*)
store volatile i8 48, i8* inttoptr (i64 1308622856 to i8*)
br label %12
12: ; preds = %12, %1
%13 = load volatile i64, i64* inttoptr (i64 1308622880 to i64*)
%14 = and i64 %13, 4
%15 = icmp eq i64 %14, 0
br i1 %15, label %12, label %16
16: ; preds = %12
%17 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%18 = load volatile i64, i64* inttoptr (i64 1308622852 to i64*)
%19 = or i64 %18, 2
store volatile i64 %19, i64* inttoptr (i64 1308622852 to i64*)
%20 = icmp ne i8 %17, -1
%21 = zext i1 %20 to i32
ret i32 %21
}