#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*/ nand_cmd(int);
int /*<<< orphan*/ nand_deselect();
unsigned char nand_read_status();
int /*<<< orphan*/ nand_ready();
int /*<<< orphan*/ nand_select();
unsigned char nand_erase_one_block(unsigned int addr) {
  int block = addr / (2048 * 64);
  unsigned char errorcode = 0;
  nand_select();
  nand_cmd(0x60);
  *((volatile unsigned long *)0x7020000C) = block & 0xff;
  *((volatile unsigned long *)0x7020000C) = (block >> 8) & 0xff;
  *((volatile unsigned long *)0x7020000C) = (block >> 16) & 0xff;
  nand_cmd(0xd0);
  nand_ready();
  errorcode = nand_read_status();
  nand_deselect();
  return errorcode;
}


x86 assembly (clang, -O0):
<nand_erase_one_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x11,%eax
mov    %eax,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
mov    $0x0,%al
call   1060 <nand_select@plt>
mov    $0x60,%edi
call   1050 <nand_cmd@plt>
mov    -0x8(%rbp),%eax
and    $0xff,%eax
movslq %eax,%rcx
mov    $0x7020000c,%eax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
movslq %eax,%rcx
mov    $0x7020000c,%eax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
movslq %eax,%rcx
mov    $0x7020000c,%eax
mov    %rcx,(%rax)
mov    $0xd0,%edi
call   1050 <nand_cmd@plt>
mov    $0x0,%al
call   1040 <nand_ready@plt>
mov    $0x0,%al
call   1070 <nand_read_status@plt>
mov    %al,-0x9(%rbp)
mov    $0x0,%al
call   1030 <nand_deselect@plt>
movzbl -0x9(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nand_erase_one_block>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %edi,%ebp
shr    $0x11,%ebp
xor    %eax,%eax
call   1060 <nand_select@plt>
mov    $0x60,%edi
call   1050 <nand_cmd@plt>
movzbl %bpl,%eax
mov    %rax,0x7020000c
70
shr    $0x19,%ebx
mov    %rbx,0x7020000c
70
movq   $0x0,0x7020000c
mov    $0xd0,%edi
call   1050 <nand_cmd@plt>
xor    %eax,%eax
call   1040 <nand_ready@plt>
xor    %eax,%eax
call   1070 <nand_read_status@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <nand_deselect@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @nand_erase_one_block(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = udiv i32 %5, 131072
store i32 %6, i32* %3
store i8 0, i8* %4
%7 = call i32 (...) @nand_select()
%8 = call i32 @nand_cmd(i32 96)
%9 = load i32, i32* %3
%10 = and i32 %9, 255
%11 = sext i32 %10 to i64
store volatile i64 %11, i64* inttoptr (i64 1881145356 to i64*)
%12 = load i32, i32* %3
%13 = ashr i32 %12, 8
%14 = and i32 %13, 255
%15 = sext i32 %14 to i64
store volatile i64 %15, i64* inttoptr (i64 1881145356 to i64*)
%16 = load i32, i32* %3
%17 = ashr i32 %16, 16
%18 = and i32 %17, 255
%19 = sext i32 %18 to i64
store volatile i64 %19, i64* inttoptr (i64 1881145356 to i64*)
%20 = call i32 @nand_cmd(i32 208)
%21 = call i32 (...) @nand_ready()
%22 = call zeroext i8 (...) @nand_read_status()
store i8 %22, i8* %4
%23 = call i32 (...) @nand_deselect()
%24 = load i8, i8* %4
ret i8 %24
}

LLVM IR (-O2):
define zeroext i8 @nand_erase_one_block(i32 %0) {
%2 = lshr i32 %0, 17
%3 = tail call i32 (...) @nand_select()
%4 = tail call i32 @nand_cmd(i32 96)
%5 = and i32 %2, 255
%6 = zext i32 %5 to i64
store volatile i64 %6, i64* inttoptr (i64 1881145356 to i64*)
%7 = lshr i32 %0, 25
%8 = zext i32 %7 to i64
store volatile i64 %8, i64* inttoptr (i64 1881145356 to i64*)
store volatile i64 0, i64* inttoptr (i64 1881145356 to i64*)
%9 = tail call i32 @nand_cmd(i32 208)
%10 = tail call i32 (...) @nand_ready()
%11 = tail call zeroext i8 (...) @nand_read_status()
%12 = tail call i32 (...) @nand_deselect()
ret i8 %11
}