#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 */
unsigned long get_unaligned(unsigned long *);
int /*<<< orphan*/ put_unaligned(unsigned long, unsigned long *);
unsigned long flat_put_addr_at_rp(unsigned long *rp, unsigned long addr,
                                  unsigned long relval) {
  if (relval & 0xC0000000) {
    unsigned long old_val = get_unaligned(rp);
    if (relval & 0x80000000)
      addr = (old_val & 0xffc00000) | (addr >> 10);
    else
      addr = (old_val & 0xfffffc00) | (addr & 0x3ff);
  }
  put_unaligned(addr, rp);
}


x86 assembly (clang, -O0):
<flat_put_addr_at_rp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movabs $0xc0000000,%rax
and    -0x20(%rbp),%rax
cmp    $0x0,%rax
je     11b8 <flat_put_addr_at_rp+0x98>
mov    -0x10(%rbp),%rdi
call   1030 <get_unaligned@plt>
mov    %rax,-0x28(%rbp)
movabs $0x80000000,%rax
and    -0x20(%rbp),%rax
cmp    $0x0,%rax
je     1193 <flat_put_addr_at_rp+0x73>
movabs $0xffc00000,%rax
and    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
shr    $0xa,%rcx
or     %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    11b3 <flat_put_addr_at_rp+0x93>
movabs $0xfffffc00,%rax
and    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
and    $0x3ff,%rcx
or     %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    11b8 <flat_put_addr_at_rp+0x98>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <put_unaligned@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flat_put_addr_at_rp>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
test   $0xc0000000,%ebx
je     1160 <flat_put_addr_at_rp+0x40>
mov    %r14,%rdi
call   1030 <get_unaligned@plt>
test   $0x80000000,%ebx
jne    1154 <flat_put_addr_at_rp+0x34>
and    $0xfffffc00,%eax
and    $0x3ff,%r15d
jmp    115d <flat_put_addr_at_rp+0x3d>
and    $0xffc00000,%eax
shr    $0xa,%r15
or     %rax,%r15
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <put_unaligned@plt>

LLVM IR (-O0):
define i64 @flat_put_addr_at_rp(i64* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i64* %0, i64** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%9 = load i64, i64* %7
%10 = and i64 %9, 3221225472
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %3
%13 = load i64*, i64** %5
%14 = call i64 @get_unaligned(i64* %13)
store i64 %14, i64* %8
%15 = load i64, i64* %7
%16 = and i64 %15, 2147483648
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = load i64, i64* %8
%20 = and i64 %19, 4290772992
%21 = load i64, i64* %6
%22 = lshr i64 %21, 10
%23 = or i64 %20, %22
store i64 %23, i64* %6
br label %30
24: ; preds = %12
%25 = load i64, i64* %8
%26 = and i64 %25, 4294966272
%27 = load i64, i64* %6
%28 = and i64 %27, 1023
%29 = or i64 %26, %28
store i64 %29, i64* %6
br label %30
30: ; preds = %24, %18
br label %31
31: ; preds = %30, %3
%32 = load i64, i64* %6
%33 = load i64*, i64** %5
%34 = call i32 @put_unaligned(i64 %32, i64* %33)
%35 = load i64, i64* %4
ret i64 %35
}

LLVM IR (-O2):
define i64 @flat_put_addr_at_rp(i64* %0, i64 %1, i64 %2) {
%4 = and i64 %2, 3221225472
%5 = icmp eq i64 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = tail call i64 @get_unaligned(i64* %0)
%8 = and i64 %2, 2147483648
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = and i64 %7, 4290772992
%12 = lshr i64 %1, 10
%13 = or i64 %11, %12
br label %18
14: ; preds = %6
%15 = and i64 %7, 4294966272
%16 = and i64 %1, 1023
%17 = or i64 %15, %16
br label %18
18: ; preds = %10, %14, %3
%19 = phi i64 [ %1, %3 ], [ %13, %10 ], [ %17, %14 ]
%20 = tail call i32 @put_unaligned(i64 %19, i64* %0)
ret i64 undef
}