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

/* Variables and functions */
int _get_result(int);
int /*<<< orphan*/ _write_crc(int, int /*<<< orphan*/ *, int, int *);
int /*<<< orphan*/ _write_crc_byte(int, int, int *);
int /*<<< orphan*/ read(int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ write(int, int *, int);
uint32_t _get_page(int fd, uint32_t addr) {
  do {
    uint8_t crc = 0xFF;
    _write_crc_byte(fd, 'P', &crc);
    _write_crc_byte(fd, sizeof(addr), &crc);
    _write_crc(fd, &addr, sizeof(addr), &crc);
    write(fd, &crc, 1);
  } while (_get_result(fd) > 1);
  uint32_t page = 0;
  read(fd, &page, sizeof(page));
  return page;
}


x86 assembly (clang, -O0):
<_get_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0xff,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x50,%esi
lea    -0xc(%rbp),%rdx
call   1040 <_write_crc_byte@plt>
mov    -0x4(%rbp),%edi
mov    $0x4,%esi
lea    -0xc(%rbp),%rdx
call   1040 <_write_crc_byte@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
lea    -0xc(%rbp),%rcx
call   1050 <_write_crc@plt>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1070 <_get_result@plt>
cmp    $0x1,%eax
jg     115e <_get_page+0xe>
movl   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_page>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %esi,0xc(%rsp)
lea    0x8(%rsp),%r14
lea    0xc(%rsp),%r15
nopl   0x0(%rax)
movl   $0xff,0x8(%rsp)
mov    %ebx,%edi
mov    $0x50,%esi
mov    %r14,%rdx
call   1040 <_write_crc_byte@plt>
mov    %ebx,%edi
mov    $0x4,%esi
mov    %r14,%rdx
call   1040 <_write_crc_byte@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x4,%edx
mov    %r14,%rcx
call   1050 <_write_crc@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1070 <_get_result@plt>
cmp    $0x1,%eax
jg     1170 <_get_page+0x20>
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1060 <read@plt>
mov    0x4(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @_get_page(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %7
7: ; preds = %16, %2
store i32 255, i32* %5
%8 = load i32, i32* %3
%9 = call i32 @_write_crc_byte(i32 %8, i32 80, i32* %5)
%10 = load i32, i32* %3
%11 = call i32 @_write_crc_byte(i32 %10, i32 4, i32* %5)
%12 = load i32, i32* %3
%13 = call i32 @_write_crc(i32 %12, i32* %4, i32 4, i32* %5)
%14 = load i32, i32* %3
%15 = call i32 @write(i32 %14, i32* %5, i32 1)
br label %16
16: ; preds = %7
%17 = load i32, i32* %3
%18 = call i32 @_get_result(i32 %17)
%19 = icmp sgt i32 %18, 1
br i1 %19, label %7, label %20
20: ; preds = %16
store i32 0, i32* %6
%21 = load i32, i32* %3
%22 = call i32 @read(i32 %21, i32* %6, i32 4)
%23 = load i32, i32* %6
ret i32 %23
}

LLVM IR (-O2):
define i32 @_get_page(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %1, i32* %3
%6 = bitcast i32* %4 to i8*
br label %7
7: ; preds = %7, %2
store i32 255, i32* %4
%8 = call i32 @_write_crc_byte(i32 %0, i32 80, i32* %4)
%9 = call i32 @_write_crc_byte(i32 %0, i32 4, i32* %4)
%10 = call i32 @_write_crc(i32 %0, i32* %3, i32 4, i32* %4)
%11 = call i32 @write(i32 %0, i32* %4, i32 1)
%12 = call i32 @_get_result(i32 %0)
%13 = icmp sgt i32 %12, 1
br i1 %13, label %7, label %14
14: ; preds = %7
%15 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%16 = call i32 @read(i32 %0, i32* %5, i32 4)
%17 = load i32, i32* %5
ret i32 %17
}