#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*/ basic_test(int);
int /*<<< orphan*/ cleanup_test();
int cmp_crc_log_rd_phys2_rd(size_t);
int cmp_data_log_rd_phys2_rd(size_t);
int /*<<< orphan*/ flush_disk_buffers();
int /*<<< orphan*/ init_test();
int /*<<< orphan*/ log_read_start(size_t);
int /*<<< orphan*/ phys1_write_start(size_t);
int /*<<< orphan*/ phys2_corrupt_and_write_start(size_t, int);
int /*<<< orphan*/ phys2_read_start(size_t);
int /*<<< orphan*/ phys_fill_buffer(size_t);
void recover_one_page_disk2(void) {
  int rc_data, rc_crc;
  size_t len = 4096;
  init_test();
  phys_fill_buffer(len);
  phys1_write_start(len);
  phys2_corrupt_and_write_start(len, 4096 / 512);
  flush_disk_buffers();
  log_read_start(len);
  flush_disk_buffers();
  phys2_read_start(len);
  rc_data = cmp_data_log_rd_phys2_rd(len);
  rc_crc = cmp_crc_log_rd_phys2_rd(len);
  basic_test(rc_data == 0 && rc_crc == 0);
  cleanup_test();
}


x86 assembly (clang, -O0):
<recover_one_page_disk2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x1000,-0x10(%rbp)
mov    $0x0,%al
call   10c0 <init_test@plt>
mov    -0x10(%rbp),%rdi
call   1080 <phys_fill_buffer@plt>
mov    -0x10(%rbp),%rdi
call   1030 <phys1_write_start@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <phys2_corrupt_and_write_start@plt>
mov    $0x0,%al
call   10d0 <flush_disk_buffers@plt>
mov    -0x10(%rbp),%rdi
call   1090 <log_read_start@plt>
mov    $0x0,%al
call   10d0 <flush_disk_buffers@plt>
mov    -0x10(%rbp),%rdi
call   1050 <phys2_read_start@plt>
mov    -0x10(%rbp),%rdi
call   1070 <cmp_data_log_rd_phys2_rd@plt>
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <cmp_crc_log_rd_phys2_rd@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x11(%rbp)
jne    1238 <recover_one_page_disk2+0x88>
cmpl   $0x0,-0x8(%rbp)
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <basic_test@plt>
mov    $0x0,%al
call   10a0 <cleanup_test@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recover_one_page_disk2>:
push   %rbx
xor    %eax,%eax
call   10c0 <init_test@plt>
mov    $0x1000,%edi
call   1080 <phys_fill_buffer@plt>
mov    $0x1000,%edi
call   1030 <phys1_write_start@plt>
mov    $0x1000,%edi
mov    $0x8,%esi
call   10b0 <phys2_corrupt_and_write_start@plt>
xor    %eax,%eax
call   10d0 <flush_disk_buffers@plt>
mov    $0x1000,%edi
call   1090 <log_read_start@plt>
xor    %eax,%eax
call   10d0 <flush_disk_buffers@plt>
mov    $0x1000,%edi
call   1050 <phys2_read_start@plt>
mov    $0x1000,%edi
call   1070 <cmp_data_log_rd_phys2_rd@plt>
mov    %eax,%ebx
mov    $0x1000,%edi
call   1060 <cmp_crc_log_rd_phys2_rd@plt>
xor    %edi,%edi
or     %ebx,%eax
sete   %dil
call   1040 <basic_test@plt>
xor    %eax,%eax
pop    %rbx
jmp    10a0 <cleanup_test@plt>

LLVM IR (-O0):
define void @recover_one_page_disk2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
store i64 4096, i64* %3
%4 = call i32 (...) @init_test()
%5 = load i64, i64* %3
%6 = call i32 @phys_fill_buffer(i64 %5)
%7 = load i64, i64* %3
%8 = call i32 @phys1_write_start(i64 %7)
%9 = load i64, i64* %3
%10 = call i32 @phys2_corrupt_and_write_start(i64 %9, i32 8)
%11 = call i32 (...) @flush_disk_buffers()
%12 = load i64, i64* %3
%13 = call i32 @log_read_start(i64 %12)
%14 = call i32 (...) @flush_disk_buffers()
%15 = load i64, i64* %3
%16 = call i32 @phys2_read_start(i64 %15)
%17 = load i64, i64* %3
%18 = call i32 @cmp_data_log_rd_phys2_rd(i64 %17)
store i32 %18, i32* %1
%19 = load i64, i64* %3
%20 = call i32 @cmp_crc_log_rd_phys2_rd(i64 %19)
store i32 %20, i32* %2
%21 = load i32, i32* %1
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %0
%24 = load i32, i32* %2
%25 = icmp eq i32 %24, 0
br label %26
26: ; preds = %23, %0
%27 = phi i1 [ false, %0 ], [ %25, %23 ]
%28 = zext i1 %27 to i32
%29 = call i32 @basic_test(i32 %28)
%30 = call i32 (...) @cleanup_test()
ret void
}

LLVM IR (-O2):
define void @recover_one_page_disk2() {
%1 = tail call i32 (...) @init_test()
%2 = tail call i32 @phys_fill_buffer(i64 4096)
%3 = tail call i32 @phys1_write_start(i64 4096)
%4 = tail call i32 @phys2_corrupt_and_write_start(i64 4096, i32 8)
%5 = tail call i32 (...) @flush_disk_buffers()
%6 = tail call i32 @log_read_start(i64 4096)
%7 = tail call i32 (...) @flush_disk_buffers()
%8 = tail call i32 @phys2_read_start(i64 4096)
%9 = tail call i32 @cmp_data_log_rd_phys2_rd(i64 4096)
%10 = tail call i32 @cmp_crc_log_rd_phys2_rd(i64 4096)
%11 = icmp eq i32 %9, 0
%12 = icmp eq i32 %10, 0
%13 = select i1 %11, i1 %12, i1 false
%14 = zext i1 %13 to i32
%15 = tail call i32 @basic_test(i32 %14)
%16 = tail call i32 (...) @cleanup_test()
ret void
}