#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 uint32_t;

/* Variables and functions */
int realtek_mst_i2c_spi_write_register(int, int, int);
int realtek_mst_i2c_spi_map_page(int fd, uint32_t addr) {
  int ret = 0;
  uint8_t block_idx = (addr >> 16) & 0xff;
  uint8_t page_idx = (addr >> 8) & 0xff;
  uint8_t byte_idx = addr & 0xff;
  ret |= realtek_mst_i2c_spi_write_register(fd, 0x64, block_idx);
  ret |= realtek_mst_i2c_spi_write_register(fd, 0x65, page_idx);
  ret |= realtek_mst_i2c_spi_write_register(fd, 0x66, byte_idx);
  return ret ? -1 : 0;
}


x86 assembly (clang, -O0):
<realtek_mst_i2c_spi_map_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%edx
mov    $0x64,%esi
call   1030 <realtek_mst_i2c_spi_write_register@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%edx
mov    $0x65,%esi
call   1030 <realtek_mst_i2c_spi_write_register@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    $0x66,%esi
call   1030 <realtek_mst_i2c_spi_write_register@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realtek_mst_i2c_spi_map_page>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%eax
mov    %edi,%ebp
movzbl %ah,%ebx
movzbl %al,%r14d
shr    $0x10,%eax
movzbl %al,%edx
mov    $0x64,%esi
call   1030 <realtek_mst_i2c_spi_write_register@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    $0x65,%esi
mov    %ebx,%edx
call   1030 <realtek_mst_i2c_spi_write_register@plt>
mov    %eax,%ebx
or     %r15d,%ebx
mov    %ebp,%edi
mov    $0x66,%esi
mov    %r14d,%edx
call   1030 <realtek_mst_i2c_spi_write_register@plt>
xor    %ecx,%ecx
or     %ebx,%eax
setne  %cl
neg    %ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @realtek_mst_i2c_spi_map_page(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%9 = load i32, i32* %4
%10 = ashr i32 %9, 16
%11 = and i32 %10, 255
store i32 %11, i32* %6
%12 = load i32, i32* %4
%13 = ashr i32 %12, 8
%14 = and i32 %13, 255
store i32 %14, i32* %7
%15 = load i32, i32* %4
%16 = and i32 %15, 255
store i32 %16, i32* %8
%17 = load i32, i32* %3
%18 = load i32, i32* %6
%19 = call i32 @realtek_mst_i2c_spi_write_register(i32 %17, i32 100, i32 %18)
%20 = load i32, i32* %5
%21 = or i32 %20, %19
store i32 %21, i32* %5
%22 = load i32, i32* %3
%23 = load i32, i32* %7
%24 = call i32 @realtek_mst_i2c_spi_write_register(i32 %22, i32 101, i32 %23)
%25 = load i32, i32* %5
%26 = or i32 %25, %24
store i32 %26, i32* %5
%27 = load i32, i32* %3
%28 = load i32, i32* %8
%29 = call i32 @realtek_mst_i2c_spi_write_register(i32 %27, i32 102, i32 %28)
%30 = load i32, i32* %5
%31 = or i32 %30, %29
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i32 -1, i32 0
ret i32 %35
}

LLVM IR (-O2):
define i32 @realtek_mst_i2c_spi_map_page(i32 %0, i32 %1) {
%3 = lshr i32 %1, 16
%4 = and i32 %3, 255
%5 = lshr i32 %1, 8
%6 = and i32 %5, 255
%7 = and i32 %1, 255
%8 = tail call i32 @realtek_mst_i2c_spi_write_register(i32 %0, i32 100, i32 %4)
%9 = tail call i32 @realtek_mst_i2c_spi_write_register(i32 %0, i32 101, i32 %6)
%10 = or i32 %9, %8
%11 = tail call i32 @realtek_mst_i2c_spi_write_register(i32 %0, i32 102, i32 %7)
%12 = or i32 %10, %11
%13 = icmp ne i32 %12, 0
%14 = sext i1 %13 to i32
ret i32 %14
}