#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 riva128_mmio_read_l(int, void *);
int /*<<< orphan*/ riva128_mmio_write_l(int, int, void *);
int /*<<< orphan*/ riva128_out(int, int, void *);
void riva128_mmio_write(uint32_t addr, uint8_t val, void *p) {
  addr &= 0xffffff;
  if (addr != 0x6013d4 && addr != 0x6013d5 && addr != 0x6013b4 &&
      addr != 0x6013b5 && addr != 0x6013da &&
      !((addr >= 0x6813c6) && (addr <= 0x6813cc))) {
    uint32_t tmp = riva128_mmio_read_l(addr, p);
    tmp &= ~(0xff << ((addr & 3) << 3));
    tmp |= val << ((addr & 3) << 3);
    riva128_mmio_write_l(addr, tmp, p);
  } else {
    riva128_out(addr & 0xfff, val & 0xff, p);
  }
}


x86 assembly (clang, -O0):
<riva128_mmio_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0xffffff,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x6013d4,-0x4(%rbp)
je     11f8 <riva128_mmio_write+0xc8>
cmpl   $0x6013d5,-0x4(%rbp)
je     11f8 <riva128_mmio_write+0xc8>
cmpl   $0x6013b4,-0x4(%rbp)
je     11f8 <riva128_mmio_write+0xc8>
cmpl   $0x6013b5,-0x4(%rbp)
je     11f8 <riva128_mmio_write+0xc8>
cmpl   $0x6013da,-0x4(%rbp)
je     11f8 <riva128_mmio_write+0xc8>
cmpl   $0x6813c6,-0x4(%rbp)
jl     11a8 <riva128_mmio_write+0x78>
cmpl   $0x6813cc,-0x4(%rbp)
jle    11f8 <riva128_mmio_write+0xc8>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <riva128_mmio_read_l@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%ecx
and    $0x3,%ecx
shl    $0x3,%ecx
mov    $0xff,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
and    $0x3,%ecx
shl    $0x3,%ecx
shl    %cl,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1050 <riva128_mmio_write_l@plt>
jmp    1213 <riva128_mmio_write+0xe3>
mov    -0x4(%rbp),%edi
and    $0xfff,%edi
mov    -0x8(%rbp),%esi
and    $0xff,%esi
mov    -0x10(%rbp),%rdx
call   1030 <riva128_out@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<riva128_mmio_write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebx
mov    %edi,%ebp
and    $0xffffff,%ebp
cmp    $0x6013da,%ebp
je     11a6 <riva128_mmio_write+0x76>
mov    %ebx,%eax
and    $0xfffffe,%eax
cmp    $0x6013b4,%eax
je     11a6 <riva128_mmio_write+0x76>
cmp    $0x6013d4,%eax
je     11a6 <riva128_mmio_write+0x76>
lea    -0x6813c6(%rbp),%eax
cmp    $0x7,%eax
jb     11a6 <riva128_mmio_write+0x76>
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <riva128_mmio_read_l@plt>
shl    $0x3,%ebx
mov    $0xff,%edx
mov    %ebx,%ecx
shl    %cl,%edx
not    %edx
and    %eax,%edx
shl    %cl,%r15d
or     %edx,%r15d
mov    %ebp,%edi
mov    %r15d,%esi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <riva128_mmio_write_l@plt>
and    $0xfff,%ebx
movzbl %r15b,%esi
mov    %ebx,%edi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <riva128_out@plt>

LLVM IR (-O0):
define void @riva128_mmio_write(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i32, i32* %4
%9 = and i32 %8, 16777215
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 6296532
br i1 %11, label %12, label %52
12: ; preds = %3
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 6296533
br i1 %14, label %15, label %52
15: ; preds = %12
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 6296500
br i1 %17, label %18, label %52
18: ; preds = %15
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 6296501
br i1 %20, label %21, label %52
21: ; preds = %18
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 6296538
br i1 %23, label %24, label %52
24: ; preds = %21
%25 = load i32, i32* %4
%26 = icmp sge i32 %25, 6820806
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %4
%29 = icmp sle i32 %28, 6820812
br i1 %29, label %52, label %30
30: ; preds = %27, %24
%31 = load i32, i32* %4
%32 = load i8*, i8** %6
%33 = call i32 @riva128_mmio_read_l(i32 %31, i8* %32)
store i32 %33, i32* %7
%34 = load i32, i32* %4
%35 = and i32 %34, 3
%36 = shl i32 %35, 3
%37 = shl i32 255, %36
%38 = xor i32 %37, -1
%39 = load i32, i32* %7
%40 = and i32 %39, %38
store i32 %40, i32* %7
%41 = load i32, i32* %5
%42 = load i32, i32* %4
%43 = and i32 %42, 3
%44 = shl i32 %43, 3
%45 = shl i32 %41, %44
%46 = load i32, i32* %7
%47 = or i32 %46, %45
store i32 %47, i32* %7
%48 = load i32, i32* %4
%49 = load i32, i32* %7
%50 = load i8*, i8** %6
%51 = call i32 @riva128_mmio_write_l(i32 %48, i32 %49, i8* %50)
br label %59
52: ; preds = %27, %21, %18, %15, %12, %3
%53 = load i32, i32* %4
%54 = and i32 %53, 4095
%55 = load i32, i32* %5
%56 = and i32 %55, 255
%57 = load i8*, i8** %6
%58 = call i32 @riva128_out(i32 %54, i32 %56, i8* %57)
br label %59
59: ; preds = %52, %30
ret void
}

LLVM IR (-O2):
define void @riva128_mmio_write(i32 %0, i32 %1, i8* %2) {
%4 = and i32 %0, 16777215
%5 = and i32 %0, 16777214
%6 = icmp ne i32 %5, 6296532
%7 = icmp ne i32 %5, 6296500
%8 = and i1 %7, %6
%9 = icmp ne i32 %4, 6296538
%10 = and i1 %9, %8
%11 = xor i1 %10, true
%12 = add nsw i32 %4, -6820806
%13 = icmp ult i32 %12, 7
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %25, label %15
15: ; preds = %3
%16 = tail call i32 @riva128_mmio_read_l(i32 %4, i8* %2)
%17 = shl i32 %0, 3
%18 = and i32 %17, 24
%19 = shl nuw i32 255, %18
%20 = xor i32 %19, -1
%21 = and i32 %16, %20
%22 = shl i32 %1, %18
%23 = or i32 %21, %22
%24 = tail call i32 @riva128_mmio_write_l(i32 %4, i32 %23, i8* %2)
br label %29
25: ; preds = %3
%26 = and i32 %0, 4095
%27 = and i32 %1, 255
%28 = tail call i32 @riva128_out(i32 %26, i32 %27, i8* %2)
br label %29
29: ; preds = %25, %15
ret void
}