// File: /workspace/github_c_makefile_star2_O0/dlbeer[P]dhara/tests/sim.c
// Function: dhara_nand_prog
int dhara_nand_prog(const struct dhara_nand *n, dhara_page_t p,
		    const uint8_t *data, dhara_error_t *err)
{
	const int bno = p >> LOG2_PAGES_PER_BLOCK;
	const int pno = p & ((1 << LOG2_PAGES_PER_BLOCK) - 1);
	uint8_t *page = pages + (p << LOG2_PAGE_SIZE);

	if ((bno < 0) || (bno >= NUM_BLOCKS)) {
		fprintf(stderr, "sim: NAND_prog called on "
			"invalid block: %d\n", bno);
		abort();
	}

	if (blocks[bno].flags & BLOCK_BAD_MARK) {
		fprintf(stderr, "sim: NAND_prog called on "
			"block which is marked bad: %d\n", bno);
		abort();
	}

	if (pno < blocks[bno].next_page) {
		fprintf(stderr, "sim: NAND_prog: out-of-order "
			"page programming. Block %d, page %d "
			"(expected %d)\n",
			bno, pno, blocks[bno].next_page);
		abort();
	}

	if (!stats.frozen)
		stats.prog++;
	blocks[bno].next_page = pno + 1;

	timebomb_tick(bno);

	if (blocks[bno].flags & BLOCK_FAILED) {
		if (!stats.frozen)
			stats.prog_fail++;
		seq_gen(p * 57 + 29, page, PAGE_SIZE);
		dhara_set_error(err, DHARA_E_BAD_BLOCK);
		return -1;
	}

	memcpy(page, data, PAGE_SIZE);
	return 0;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movl %esi, 0x24(%rsp)
movq %rdx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movl 0x24(%rsp), %eax
shrl $0x3, %eax
movl %eax, 0xc(%rsp)
movl 0x24(%rsp), %eax
andl $0x7, %eax
movl %eax, 0x8(%rsp)
movl 0x24(%rsp), %eax
shll $0x9, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x4891(%rip), %rax      # 0x9920
addq %rcx, %rax
movq %rax, (%rsp)
cmpl $0x0, 0xc(%rsp)
jl 0x50a4
cmpl $0x71, 0xc(%rsp)
jl 0x50c5
movq 0x3f4d(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movl 0xc(%rsp), %edx
leaq 0x1327(%rip), %rsi      # 0x63e0
movb $0x0, %al
callq 0x1090
callq 0x1030
movslq 0xc(%rsp), %rcx
leaq 0x42ff(%rip), %rax      # 0x93d0
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5103
movq 0x3f0f(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movl 0xc(%rsp), %edx
leaq 0x1315(%rip), %rsi      # 0x640c
movb $0x0, %al
callq 0x1090
callq 0x1030
movl 0x8(%rsp), %eax
movslq 0xc(%rsp), %rdx
leaq 0x42bd(%rip), %rcx      # 0x93d0
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jge 0x515b
movq 0x3ed2(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
movslq 0xc(%rsp), %rsi
leaq 0x4293(%rip), %rax      # 0x93d0
imulq $0xc, %rsi, %rsi
addq %rsi, %rax
movl 0x4(%rax), %r8d
leaq 0x12f5(%rip), %rsi      # 0x6444
movb $0x0, %al
callq 0x1090
callq 0x1030
cmpl $0x0, 0x423e(%rip)      # 0x93a0
jne 0x5173
movl 0x424e(%rip), %eax      # 0x93b8
addl $0x1, %eax
movl %eax, 0x4245(%rip)      # 0x93b8
movl 0x8(%rsp), %ecx
addl $0x1, %ecx
movslq 0xc(%rsp), %rdx
leaq 0x424a(%rip), %rax      # 0x93d0
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl 0xc(%rsp), %edi
callq 0x4fe0
movslq 0xc(%rsp), %rcx
leaq 0x422b(%rip), %rax      # 0x93d0
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x51fd
cmpl $0x0, 0x41e3(%rip)      # 0x93a0
jne 0x51ce
movl 0x41f7(%rip), %eax      # 0x93bc
addl $0x1, %eax
movl %eax, 0x41ee(%rip)      # 0x93bc
imull $0x39, 0x24(%rsp), %edi
addl $0x1d, %edi
movq (%rsp), %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x5820
movq 0x10(%rsp), %rdi
movl $0x1, %esi
callq 0x5030
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
jmp 0x5218
movq (%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x10a0
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)