#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 */
typedef int /*<<< orphan*/ const uint8_t;

/* Variables and functions */
scalar_t__ dbg_readpage(int /*<<< orphan*/ const, int /*<<< orphan*/ const *);
scalar_t__ dbg_writepage(int /*<<< orphan*/ const, int /*<<< orphan*/ const *);
int /*<<< orphan*/ dump(int /*<<< orphan*/ const *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int program_verify_page(const uint8_t *data, uint8_t page) {
  uint8_t verbuf[1024];
  if (0 != dbg_writepage(page, data)) {
    fprintf(stderr, "program_page failed\n");
    return 1;
  }
  if (0 != dbg_readpage(page, verbuf)) {
    fprintf(stderr, "read_page failed\n");
    return 1;
  }
  fprintf(stderr, "verify failed\n");
  printf("verbuf = ");
  dump(verbuf, 1024);
  printf("expected = ");
  dump(data, 1024);
  return 0;
}


x86 assembly (clang, -O0):
<program_verify_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <dbg_writepage@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     119d <program_verify_page+0x4d>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122e <program_verify_page+0xde>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
call   1060 <dbg_readpage@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11db <program_verify_page+0x8b>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122e <program_verify_page+0xde>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
lea    -0x1020(%rbp),%rdi
mov    $0x400,%esi
call   1040 <dump@plt>
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x400,%esi
call   1040 <dump@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<program_verify_page>:
push   %rbp
push   %rbx
sub    $0x1008,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
mov    %rbx,%rsi
call   1070 <dbg_writepage@plt>
test   %rax,%rax
je     117f <program_verify_page+0x2f>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
jmp    119e <program_verify_page+0x4e>
mov    %rsp,%rsi
mov    %ebp,%edi
call   1060 <dbg_readpage@plt>
mov    0x2e50(%rip),%rcx
mov    (%rcx),%edi
test   %rax,%rax
je     11b2 <program_verify_page+0x62>
lea    0xe77(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe6e(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
call   1040 <dump@plt>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <dump@plt>
xor    %eax,%eax
jmp    11a8 <program_verify_page+0x58>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"program_page failed\0A\00"
@.str.1 = [18 x i8] c"read_page failed\0A\00"
@.str.2 = [15 x i8] c"verify failed\0A\00"
@.str.3 = [10 x i8] c"verbuf = \00"
@.str.4 = [12 x i8] c"expected = \00"
define i32 @program_verify_page(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [1024 x i32]
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = load i32*, i32** %4
%9 = call i64 @dbg_writepage(i32 %7, i32* %8)
%10 = icmp ne i64 0, %9
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %31
14: ; preds = %2
%15 = load i32, i32* %5
%16 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%17 = call i64 @dbg_readpage(i32 %15, i32* %16)
%18 = icmp ne i64 0, %17
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %31
22: ; preds = %14
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%26 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%27 = call i32 @dump(i32* %26, i32 1024)
%28 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%29 = load i32*, i32** %4
%30 = call i32 @dump(i32* %29, i32 1024)
store i32 0, i32* %3
br label %31
31: ; preds = %22, %19, %11
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"program_page failed\0A\00"
@.str.1 = [18 x i8] c"read_page failed\0A\00"
@.str.2 = [15 x i8] c"verify failed\0A\00"
@.str.3 = [10 x i8] c"verbuf = \00"
@.str.4 = [12 x i8] c"expected = \00"
define i32 @program_verify_page(i32* %0, i32 %1) {
%3 = alloca [1024 x i32]
%4 = bitcast [1024 x i32]* %3 to i8*
%5 = tail call i64 @dbg_writepage(i32 %1, i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %23
10: ; preds = %2
%11 = getelementptr inbounds [1024 x i32], [1024 x i32]* %3, i64 0, i64 0
%12 = call i64 @dbg_readpage(i32 %1, i32* %11)
%13 = icmp eq i64 %12, 0
%14 = load i32, i32* @stderr
br i1 %13, label %17, label %15
15: ; preds = %10
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %23
17: ; preds = %10
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @dump(i32* %11, i32 1024)
%21 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @dump(i32* %0, i32 1024)
br label %23
23: ; preds = %17, %15, %7
%24 = phi i32 [ 1, %7 ], [ 1, %15 ], [ 0, %17 ]
ret i32 %24
}