#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();
void nand_erase_block(unsigned long addr) {
  int page = addr / 4096;
  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    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0xc,%rax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1070 <nand_select@plt>
mov    $0x60,%edi
call   1050 <nand_cmd@plt>
mov    -0xc(%rbp),%edi
and    $0xff,%edi
call   1040 <nand_addr@plt>
mov    -0xc(%rbp),%edi
sar    $0x8,%edi
and    $0xff,%edi
call   1040 <nand_addr@plt>
mov    -0xc(%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>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nand_erase_block>:
push   %rbx
mov    %rdi,%rbx
shr    $0xc,%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 void @nand_erase_block(i64 %0) {
%2 = alloca i64
%3 = alloca i32
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = udiv i64 %4, 4096
%6 = trunc i64 %5 to i32
store i32 %6, i32* %3
%7 = call i32 (...) @nand_select()
%8 = call i32 @nand_cmd(i32 96)
%9 = load i32, i32* %3
%10 = and i32 %9, 255
%11 = call i32 @nand_addr(i32 %10)
%12 = load i32, i32* %3
%13 = ashr i32 %12, 8
%14 = and i32 %13, 255
%15 = call i32 @nand_addr(i32 %14)
%16 = load i32, i32* %3
%17 = ashr i32 %16, 16
%18 = and i32 %17, 255
%19 = call i32 @nand_addr(i32 %18)
%20 = call i32 @nand_cmd(i32 208)
%21 = call i32 (...) @wait_ready()
%22 = call i32 (...) @nand_deselect()
ret void
}

LLVM IR (-O2):
define void @nand_erase_block(i64 %0) {
%2 = lshr i64 %0, 12
%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 void
}