#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 O_RDWR;
int O_SYNC;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ read(int, unsigned long *, int);
int drp_status(int which) {
  int fd = -1;
  unsigned long dr7 = 0;
  fd = open("/proc/dr/dr7", O_RDWR | O_SYNC);
  read(fd, &dr7, sizeof dr7);
  close(fd);
  if (which == 0)
    return (dr7 & 0x00000001);
  else if (which == 1)
    return (dr7 & 0x00000004);
  else if (which == 2)
    return (dr7 & 0x00000010);
  else if (which == 3)
    return (dr7 & 0x00000040);
}


x86 assembly (clang, -O0):
<drp_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
mov    0x2e86(%rip),%rax
or     (%rax),%esi
lea    0xe9d(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x8(%rbp)
jne    119e <drp_status+0x6e>
mov    -0x18(%rbp),%rax
and    $0x1,%rax
mov    %eax,-0x4(%rbp)
jmp    11fb <drp_status+0xcb>
cmpl   $0x1,-0x8(%rbp)
jne    11b8 <drp_status+0x88>
mov    -0x18(%rbp),%rax
and    $0x4,%rax
mov    %eax,-0x4(%rbp)
jmp    11fb <drp_status+0xcb>
cmpl   $0x2,-0x8(%rbp)
jne    11d2 <drp_status+0xa2>
mov    -0x18(%rbp),%rax
and    $0x10,%rax
mov    %eax,-0x4(%rbp)
jmp    11fb <drp_status+0xcb>
cmpl   $0x3,-0x8(%rbp)
jne    11ec <drp_status+0xbc>
mov    -0x18(%rbp),%rax
and    $0x40,%rax
mov    %eax,-0x4(%rbp)
jmp    11fb <drp_status+0xcb>
jmp    11f1 <drp_status+0xc1>
jmp    11f6 <drp_status+0xc6>
jmp    11fb <drp_status+0xcb>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drp_status>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
movq   $0x0,(%rsp)
mov    0x2ea4(%rip),%rax
mov    0x2e95(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeba(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %ebp,%edi
call   1030 <close@plt>
cmp    $0x3,%ebx
ja     1192 <drp_status+0x62>
mov    %ebx,%eax
lea    0xe7f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    (%rsp),%eax
and    $0x1,%eax
jmp    11aa <drp_status+0x7a>
jmp    11aa <drp_status+0x7a>
mov    (%rsp),%eax
and    $0x4,%eax
jmp    11aa <drp_status+0x7a>
mov    (%rsp),%eax
and    $0x10,%eax
jmp    11aa <drp_status+0x7a>
mov    (%rsp),%eax
and    $0x40,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/dr/dr7\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
define i32 @drp_status(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32 %0, i32* %3
store i32 -1, i32* %4
store i64 0, i64* %5
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_SYNC
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = call i32 @read(i32 %10, i64* %5, i32 8)
%12 = load i32, i32* %4
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = load i64, i64* %5
%18 = and i64 %17, 1
%19 = trunc i64 %18 to i32
store i32 %19, i32* %2
br label %44
20: ; preds = %1
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i64, i64* %5
%25 = and i64 %24, 4
%26 = trunc i64 %25 to i32
store i32 %26, i32* %2
br label %44
27: ; preds = %20
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 2
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i64, i64* %5
%32 = and i64 %31, 16
%33 = trunc i64 %32 to i32
store i32 %33, i32* %2
br label %44
34: ; preds = %27
%35 = load i32, i32* %3
%36 = icmp eq i32 %35, 3
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i64, i64* %5
%39 = and i64 %38, 64
%40 = trunc i64 %39 to i32
store i32 %40, i32* %2
br label %44
41: ; preds = %34
br label %42
42: ; preds = %41
br label %43
43: ; preds = %42
br label %44
44: ; preds = %16, %23, %30, %37, %43
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/dr/dr7\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
define i32 @drp_status(i32 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_SYNC
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 @read(i32 %7, i64* %2, i32 8)
%9 = tail call i32 @close(i32 %7)
switch i32 %0, label %26 [
i32 0, label %10
i32 1, label %14
i32 2, label %18
i32 3, label %22
]
10: ; preds = %1
%11 = load i64, i64* %2
%12 = trunc i64 %11 to i32
%13 = and i32 %12, 1
br label %26
14: ; preds = %1
%15 = load i64, i64* %2
%16 = trunc i64 %15 to i32
%17 = and i32 %16, 4
br label %26
18: ; preds = %1
%19 = load i64, i64* %2
%20 = trunc i64 %19 to i32
%21 = and i32 %20, 16
br label %26
22: ; preds = %1
%23 = load i64, i64* %2
%24 = trunc i64 %23 to i32
%25 = and i32 %24, 64
br label %26
26: ; preds = %1, %22, %18, %14, %10
%27 = phi i32 [ %13, %10 ], [ %17, %14 ], [ %21, %18 ], [ %25, %22 ], [ undef, %1 ]
ret i32 %27
}