#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 /*<<< orphan*/ siginfo_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, long *, int);
void sigtrap_sa(int nr, siginfo_t *si, void *__ctx) {
  int i;
  long val;
  int fd = open("/proc/dr/dr6", O_RDONLY);
  read(fd, &val, sizeof val);
  close(fd);
  if (val & 0x1)
    printf("Breakpoint 0\n");
  if (val & 0x2)
    printf("Breakpoint 1\n");
  if (val & 0x4)
    printf("Breakpoint 2\n");
  if (val & 0x8)
    printf("Breakpoint 3\n");
}


x86 assembly (clang, -O0):
<sigtrap_sa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0xe9d(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1050 <read@plt>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
mov    -0x28(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11a2 <sigtrap_sa+0x62>
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
and    $0x2,%rax
cmp    $0x0,%rax
je     11c0 <sigtrap_sa+0x80>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
and    $0x4,%rax
cmp    $0x0,%rax
je     11de <sigtrap_sa+0x9e>
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
and    $0x8,%rax
cmp    $0x0,%rax
je     11fc <sigtrap_sa+0xbc>
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigtrap_sa>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%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),%rbx
test   $0x1,%bl
jne    1193 <sigtrap_sa+0x53>
test   $0x2,%bl
jne    11a4 <sigtrap_sa+0x64>
test   $0x4,%bl
jne    11b5 <sigtrap_sa+0x75>
test   $0x8,%bl
jne    11c6 <sigtrap_sa+0x86>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
test   $0x2,%bl
je     1183 <sigtrap_sa+0x43>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
test   $0x4,%bl
je     1188 <sigtrap_sa+0x48>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
test   $0x8,%bl
je     118d <sigtrap_sa+0x4d>
lea    0xe40(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/dr/dr6\00"
@O_RDONLY = global i32 0
@.str.1 = [14 x i8] c"Breakpoint 0\0A\00"
@.str.2 = [14 x i8] c"Breakpoint 1\0A\00"
@.str.3 = [14 x i8] c"Breakpoint 2\0A\00"
@.str.4 = [14 x i8] c"Breakpoint 3\0A\00"
define void @sigtrap_sa(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = call i32 @read(i32 %12, i64* %8, i32 8)
%14 = load i32, i32* %9
%15 = call i32 @close(i32 %14)
%16 = load i64, i64* %8
%17 = and i64 %16, 1
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %3
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %3
%22 = load i64, i64* %8
%23 = and i64 %22, 2
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = load i64, i64* %8
%29 = and i64 %28, 4
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = load i64, i64* %8
%35 = and i64 %34, 8
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/dr/dr6\00"
@O_RDONLY = global i32 0
@str = [13 x i8] c"Breakpoint 3\00"
@str.5 = [13 x i8] c"Breakpoint 2\00"
@str.6 = [13 x i8] c"Breakpoint 1\00"
@str.7 = [13 x i8] c"Breakpoint 0\00"
define void @sigtrap_sa(i32 %0, i32* nocapture readnone %1, i8* nocapture readnone %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = load i32, i32* @O_RDONLY
%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* %4, i32 8)
%9 = tail call i32 @close(i32 %7)
%10 = load i64, i64* %4
%11 = and i64 %10, 1
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
br label %15
15: ; preds = %13, %3
%16 = and i64 %10, 2
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
%21 = and i64 %10, 4
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.5, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = and i64 %10, 8
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
ret void
}