#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 /*<<< orphan*/ snprintf(char *, int, char *, int);
unsigned long drp_value(int which) {
  char buffer[32];
  int fd = -1;
  unsigned long val = 0;
  snprintf(buffer, sizeof buffer, "/proc/dr/dr%d", which);
  fd = open(buffer, O_RDWR | O_SYNC);
  read(fd, &val, sizeof(unsigned long));
  close(fd);
  return val;
}


x86 assembly (clang, -O0):
<drp_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x20,%esi
lea    0xe93(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    0x2e5a(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x8,%edx
call   1050 <read@plt>
mov    -0x34(%rbp),%edi
call   1040 <close@plt>
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drp_value>:
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ecx
movq   $0x0,0x8(%rsp)
lea    0xea9(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <snprintf@plt>
mov    0x2e78(%rip),%rax
mov    0x2e69(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1050 <read@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x8(%rsp),%rax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/dr/dr%d\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
define i64 @drp_value(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = alloca i64
store i32 %0, i32* %2
store i32 -1, i32* %4
store i64 0, i64* %5
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* %2
%8 = call i32 @snprintf(i8* %6, i32 32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_SYNC
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %9, i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = call i32 @read(i32 %14, i64* %5, i32 8)
%16 = load i32, i32* %4
%17 = call i32 @close(i32 %16)
%18 = load i64, i64* %5
ret i64 %18
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/dr/dr%d\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
define i64 @drp_value(i32 %0) {
%2 = alloca [32 x i8]
%3 = alloca i64
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = call i32 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_SYNC
%9 = or i32 %8, %7
%10 = call i32 @open(i8* %4, i32 %9)
%11 = call i32 @read(i32 %10, i64* %3, i32 8)
%12 = call i32 @close(i32 %10)
%13 = load i64, i64* %3
ret i64 %13
}