#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_wr(size_t);
int cmp_data_log_rd_phys2_wr(size_t);
int /*<<< orphan*/ flush_disk_buffers();
int /*<<< orphan*/ init_test();
int /*<<< orphan*/ log_read_start(size_t);
int /*<<< orphan*/ phys1_corrupt_and_write_start(size_t, int);
int /*<<< orphan*/ phys2_write_start(size_t);
int /*<<< orphan*/ phys_fill_buffer(size_t);
void corrupt_read_correct_one_sector_disk1(void) {
  int rc_data, rc_crc;
  size_t len = 512;
  init_test();
  phys_fill_buffer(len);
  phys1_corrupt_and_write_start(len, 1);
  phys2_write_start(len);
  flush_disk_buffers();
  log_read_start(len);
  rc_data = cmp_data_log_rd_phys2_wr(len);
  rc_crc = cmp_crc_log_rd_phys2_wr(len);
  basic_test(rc_data == 0 && rc_crc == 0);
  cleanup_test();
}


x86 assembly (clang, -O0):
<corrupt_read_correct_one_sector_disk1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x200,-0x10(%rbp)
mov    $0x0,%al
call   10b0 <init_test@plt>
mov    -0x10(%rbp),%rdi
call   1080 <phys_fill_buffer@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1050 <phys1_corrupt_and_write_start@plt>
mov    -0x10(%rbp),%rdi
call   1070 <phys2_write_start@plt>
mov    $0x0,%al
call   10c0 <flush_disk_buffers@plt>
mov    -0x10(%rbp),%rdi
call   1090 <log_read_start@plt>
mov    -0x10(%rbp),%rdi
call   1030 <cmp_data_log_rd_phys2_wr@plt>
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <cmp_crc_log_rd_phys2_wr@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x11(%rbp)
jne    1218 <corrupt_read_correct_one_sector_disk1+0x78>
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):
<corrupt_read_correct_one_sector_disk1>:
push   %rbx
xor    %eax,%eax
call   10b0 <init_test@plt>
mov    $0x200,%edi
call   1080 <phys_fill_buffer@plt>
mov    $0x200,%edi
mov    $0x1,%esi
call   1050 <phys1_corrupt_and_write_start@plt>
mov    $0x200,%edi
call   1070 <phys2_write_start@plt>
xor    %eax,%eax
call   10c0 <flush_disk_buffers@plt>
mov    $0x200,%edi
call   1090 <log_read_start@plt>
mov    $0x200,%edi
call   1030 <cmp_data_log_rd_phys2_wr@plt>
mov    %eax,%ebx
mov    $0x200,%edi
call   1060 <cmp_crc_log_rd_phys2_wr@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 @corrupt_read_correct_one_sector_disk1() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
store i64 512, 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_corrupt_and_write_start(i64 %7, i32 1)
%9 = load i64, i64* %3
%10 = call i32 @phys2_write_start(i64 %9)
%11 = call i32 (...) @flush_disk_buffers()
%12 = load i64, i64* %3
%13 = call i32 @log_read_start(i64 %12)
%14 = load i64, i64* %3
%15 = call i32 @cmp_data_log_rd_phys2_wr(i64 %14)
store i32 %15, i32* %1
%16 = load i64, i64* %3
%17 = call i32 @cmp_crc_log_rd_phys2_wr(i64 %16)
store i32 %17, i32* %2
%18 = load i32, i32* %1
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %0
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 0
br label %23
23: ; preds = %20, %0
%24 = phi i1 [ false, %0 ], [ %22, %20 ]
%25 = zext i1 %24 to i32
%26 = call i32 @basic_test(i32 %25)
%27 = call i32 (...) @cleanup_test()
ret void
}

LLVM IR (-O2):
define void @corrupt_read_correct_one_sector_disk1() {
%1 = tail call i32 (...) @init_test()
%2 = tail call i32 @phys_fill_buffer(i64 512)
%3 = tail call i32 @phys1_corrupt_and_write_start(i64 512, i32 1)
%4 = tail call i32 @phys2_write_start(i64 512)
%5 = tail call i32 (...) @flush_disk_buffers()
%6 = tail call i32 @log_read_start(i64 512)
%7 = tail call i32 @cmp_data_log_rd_phys2_wr(i64 512)
%8 = tail call i32 @cmp_crc_log_rd_phys2_wr(i64 512)
%9 = icmp eq i32 %7, 0
%10 = icmp eq i32 %8, 0
%11 = select i1 %9, i1 %10, i1 false
%12 = zext i1 %11 to i32
%13 = tail call i32 @basic_test(i32 %12)
%14 = tail call i32 (...) @cleanup_test()
ret void
}