#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_addr(int);
int /*<<< orphan*/ nand_cmd(int);
int /*<<< orphan*/ nand_deselect();
int /*<<< orphan*/ nand_select();
int /*<<< orphan*/ wait_ready();
int nand_erase_block(unsigned long addr) {
  int page = addr / 2048;
  nand_select();
  nand_cmd(0x60);
  nand_addr(page & 0xff);
  nand_addr((page >> 8) & 0xff);
  nand_addr((page >> 16) & 0xff);
  nand_cmd(0xd0);
  wait_ready();
  nand_deselect();
}


x86 assembly (clang, -O0):
<nand_erase_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shr    $0xb,%rax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1070 <nand_select@plt>
mov    $0x60,%edi
call   1050 <nand_cmd@plt>
mov    -0x14(%rbp),%edi
and    $0xff,%edi
call   1040 <nand_addr@plt>
mov    -0x14(%rbp),%edi
sar    $0x8,%edi
and    $0xff,%edi
call   1040 <nand_addr@plt>
mov    -0x14(%rbp),%edi
sar    $0x10,%edi
and    $0xff,%edi
call   1040 <nand_addr@plt>
mov    $0xd0,%edi
call   1050 <nand_cmd@plt>
mov    $0x0,%al
call   1060 <wait_ready@plt>
mov    $0x0,%al
call   1030 <nand_deselect@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nand_erase_block>:
push   %rbx
mov    %rdi,%rbx
shr    $0xb,%rbx
xor    %eax,%eax
call   1070 <nand_select@plt>
mov    $0x60,%edi
call   1050 <nand_cmd@plt>
movzbl %bl,%edi
call   1040 <nand_addr@plt>
movzbl %bh,%edi
call   1040 <nand_addr@plt>
shr    $0x10,%ebx
movzbl %bl,%edi
call   1040 <nand_addr@plt>
mov    $0xd0,%edi
call   1050 <nand_cmd@plt>
xor    %eax,%eax
call   1060 <wait_ready@plt>
xor    %eax,%eax
pop    %rbx
jmp    1030 <nand_deselect@plt>

LLVM IR (-O0):
define i32 @nand_erase_block(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = udiv i64 %5, 2048
%7 = trunc i64 %6 to i32
store i32 %7, i32* %4
%8 = call i32 (...) @nand_select()
%9 = call i32 @nand_cmd(i32 96)
%10 = load i32, i32* %4
%11 = and i32 %10, 255
%12 = call i32 @nand_addr(i32 %11)
%13 = load i32, i32* %4
%14 = ashr i32 %13, 8
%15 = and i32 %14, 255
%16 = call i32 @nand_addr(i32 %15)
%17 = load i32, i32* %4
%18 = ashr i32 %17, 16
%19 = and i32 %18, 255
%20 = call i32 @nand_addr(i32 %19)
%21 = call i32 @nand_cmd(i32 208)
%22 = call i32 (...) @wait_ready()
%23 = call i32 (...) @nand_deselect()
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
define i32 @nand_erase_block(i64 %0) {
%2 = lshr i64 %0, 11
%3 = trunc i64 %2 to i32
%4 = tail call i32 (...) @nand_select()
%5 = tail call i32 @nand_cmd(i32 96)
%6 = and i32 %3, 255
%7 = tail call i32 @nand_addr(i32 %6)
%8 = lshr i32 %3, 8
%9 = and i32 %8, 255
%10 = tail call i32 @nand_addr(i32 %9)
%11 = lshr i32 %3, 16
%12 = and i32 %11, 255
%13 = tail call i32 @nand_addr(i32 %12)
%14 = tail call i32 @nand_cmd(i32 208)
%15 = tail call i32 (...) @wait_ready()
%16 = tail call i32 (...) @nand_deselect()
ret i32 undef
}