#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 get_rw_offset(int);
void proctal_x86_64_dr_rw_set(unsigned long long *dr7, int r,
                              unsigned int state) {
  int offset = get_rw_offset(r);
  if (offset == -1) {
    return;
  }
  unsigned int mask = 0x3u << offset;
  state <<= offset;
  state &= mask;
  *dr7 &= ~(mask);
  *dr7 |= state;
}


x86 assembly (clang, -O0):
<proctal_x86_64_dr_rw_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <get_rw_offset@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    113c <proctal_x86_64_dr_rw_set+0x2c>
jmp    1180 <proctal_x86_64_dr_rw_set+0x70>
mov    -0x14(%rbp),%ecx
mov    $0x3,%eax
shl    %cl,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
shl    %cl,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,%eax
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
and    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
or     (%rax),%rcx
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proctal_x86_64_dr_rw_set>:
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rdi,%r14
mov    %esi,%edi
call   1030 <get_rw_offset@plt>
cmp    $0xffffffff,%eax
je     113c <proctal_x86_64_dr_rw_set+0x2c>
mov    %eax,%ecx
mov    $0x3,%eax
shl    %cl,%eax
shl    %cl,%ebx
mov    (%r14),%ecx
xor    %ecx,%ebx
and    %eax,%ebx
xor    %ecx,%ebx
mov    %rbx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @proctal_x86_64_dr_rw_set(i64* %0, i32 %1, i32 %2) {
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i64* %0, i64** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = call i32 @get_rw_offset(i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %3
br label %34
14: ; preds = %3
%15 = load i32, i32* %7
%16 = shl i32 3, %15
store i32 %16, i32* %8
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = shl i32 %18, %17
store i32 %19, i32* %6
%20 = load i32, i32* %8
%21 = load i32, i32* %6
%22 = and i32 %21, %20
store i32 %22, i32* %6
%23 = load i32, i32* %8
%24 = xor i32 %23, -1
%25 = zext i32 %24 to i64
%26 = load i64*, i64** %4
%27 = load i64, i64* %26
%28 = and i64 %27, %25
store i64 %28, i64* %26
%29 = load i32, i32* %6
%30 = zext i32 %29 to i64
%31 = load i64*, i64** %4
%32 = load i64, i64* %31
%33 = or i64 %32, %30
store i64 %33, i64* %31
br label %34
34: ; preds = %14, %13
ret void
}

LLVM IR (-O2):
define void @proctal_x86_64_dr_rw_set(i64* nocapture %0, i32 %1, i32 %2) {
%4 = tail call i32 @get_rw_offset(i32 %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = shl i32 3, %4
%8 = shl i32 %2, %4
%9 = and i32 %8, %7
%10 = xor i32 %7, -1
%11 = zext i32 %10 to i64
%12 = load i64, i64* %0
%13 = and i64 %12, %11
%14 = zext i32 %9 to i64
%15 = or i64 %13, %14
store i64 %15, i64* %0
br label %16
16: ; preds = %3, %6
ret void
}