int inspect_pid(int pid) {
  static int dig_nr;
  long offset_inside_bounds_dir;
  char bounds_dir_buf[sizeof(unsigned long) * (1UL << 15)];
  char *dig_bounds_dir_ptr;
  int total_entries = 0;
  int nr_populated_bdes = 0;
  int inspect_self;
  if (getpid() == pid) {
    do {
      if (4 <= 0)
        printf("inspecting self\n");
    } while (0);
    inspect_self = 1;
  } else {
    do {
      if (4 <= 0)
        printf("inspecting pid %d\n", pid);
    } while (0);
    __mpx_dig_abort("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/786228836/linux/refs/"
                    "heads/4.8.6/ECE695-Spring17/t3-scheduler/linux-4.10.6/"
                    "tools/testing/selftests/x86/mpx-dig.c",
                    __func__, 427);
  }
  for (offset_inside_bounds_dir = 0; offset_inside_bounds_dir < (1ULL << 22);
       offset_inside_bounds_dir += sizeof(bounds_dir_buf)) {
    static int bufs_skipped;
    int this_entries;
    if (inspect_self) {
      dig_bounds_dir_ptr = fill_bounds_dir_buf_self(
          offset_inside_bounds_dir, sizeof(bounds_dir_buf), &bounds_dir_buf[0]);
    } else {
      dig_bounds_dir_ptr = fill_bounds_dir_buf_other(
          offset_inside_bounds_dir, sizeof(bounds_dir_buf), &bounds_dir_buf[0]);
    }
    if (!dig_bounds_dir_ptr) {
      bufs_skipped++;
      continue;
    }
    this_entries = search_bd_buf(dig_bounds_dir_ptr, sizeof(bounds_dir_buf),
                                 offset_inside_bounds_dir, &nr_populated_bdes);
    total_entries += this_entries;
  }
  printf("mpx dig (%3d) complete, SUCCESS (%8d / %4d)\n", ++dig_nr,
         total_entries, nr_populated_bdes);
  return total_entries + nr_populated_bdes;
}


x86 assembly (clang, -O0):
<inspect_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40030,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x4001c(%rbp)
movl   $0x0,-0x40020(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
cmp    -0x4(%rbp),%eax
jne    11ab <inspect_pid+0x4b>
jmp    1197 <inspect_pid+0x37>
jmp    119c <inspect_pid+0x3c>
movl   $0x1,-0x40024(%rbp)
jmp    11cf <inspect_pid+0x6f>
jmp    11b0 <inspect_pid+0x50>
jmp    11b5 <inspect_pid+0x55>
lea    0xe44(%rip),%rdi
lea    0xf08(%rip),%rsi
mov    $0x1ab,%edx
mov    $0x0,%al
call   1030 <__mpx_dig_abort@plt>
movq   $0x0,-0x10(%rbp)
cmpq   $0x400000,-0x10(%rbp)
jae    12a2 <inspect_pid+0x142>
cmpl   $0x0,-0x40024(%rbp)
je     1217 <inspect_pid+0xb7>
mov    -0x10(%rbp),%rdi
lea    -0x40010(%rbp),%rdx
mov    $0x40000,%esi
mov    $0x0,%al
call   1060 <fill_bounds_dir_buf_self@plt>
cltq
mov    %rax,-0x40018(%rbp)
jmp    1237 <inspect_pid+0xd7>
mov    -0x10(%rbp),%rdi
lea    -0x40010(%rbp),%rdx
mov    $0x40000,%esi
mov    $0x0,%al
call   1070 <fill_bounds_dir_buf_other@plt>
cltq
mov    %rax,-0x40018(%rbp)
cmpq   $0x0,-0x40018(%rbp)
jne    1259 <inspect_pid+0xf9>
mov    0x2e0d(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e04(%rip)
jmp    128f <inspect_pid+0x12f>
mov    -0x40018(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x40000,%esi
lea    -0x40020(%rbp),%rcx
mov    $0x0,%al
call   1080 <search_bd_buf@plt>
mov    %eax,-0x40028(%rbp)
mov    -0x40028(%rbp),%eax
add    -0x4001c(%rbp),%eax
mov    %eax,-0x4001c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x40000,%rax
mov    %rax,-0x10(%rbp)
jmp    11d7 <inspect_pid+0x77>
mov    0x2dac(%rip),%esi
add    $0x1,%esi
mov    %esi,0x2da3(%rip)
mov    -0x4001c(%rbp),%edx
mov    -0x40020(%rbp),%ecx
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4001c(%rbp),%eax
add    -0x40020(%rbp),%eax
add    $0x40030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inspect_pid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x40018,%rsp
mov    %edi,%ebx
movl   $0x0,0xc(%rsp)
xor    %eax,%eax
call   1040 <getpid@plt>
cmp    %ebx,%eax
je     118c <inspect_pid+0x3c>
lea    0xe87(%rip),%rdi
lea    0xf4b(%rip),%rsi
mov    $0x1ab,%edx
xor    %eax,%eax
call   1030 <__mpx_dig_abort@plt>
mov    $0xfffffffffffc0000,%rbx
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
xor    %ebp,%ebp
jmp    11d0 <inspect_pid+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq %eax,%rdi
mov    $0x40000,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <search_bd_buf@plt>
add    %eax,%ebp
cmp    $0x3c0000,%rbx
jae    11fd <inspect_pid+0xad>
add    $0x40000,%rbx
mov    $0x40000,%esi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fill_bounds_dir_buf_self@plt>
test   %eax,%eax
jne    11b0 <inspect_pid+0x60>
addl   $0x1,0x2e5c(%rip)
cmp    $0x3c0000,%rbx
jb     11d0 <inspect_pid+0x80>
mov    0x2e49(%rip),%esi
add    $0x1,%esi
mov    %esi,0x2e40(%rip)
mov    0xc(%rsp),%ecx
lea    0xec0(%rip),%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    0xc(%rsp),%ebp
mov    %ebp,%eax
add    $0x40018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@inspect_pid.dig_nr = internal global i32 0
@.str = [203 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/786228836/linux/refs/heads/4.8.6/ECE695-Spring17/t3-scheduler/linux-4.10.6/tools/testing/selftests/x86/mpx-dig.c\00"
@__func__.inspect_pid = [12 x i8] c"inspect_pid\00"
@inspect_pid.bufs_skipped = internal global i32 0
@.str.1 = [45 x i8] c"mpx dig (%3d) complete, SUCCESS (%8d / %4d)\0A\00"
define i32 @inspect_pid(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca [262144 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %6
store i32 0, i32* %7
%10 = call i32 (...) @getpid()
%11 = load i32, i32* %2
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %1
br label %14
14: ; preds = %13
br label %15
15: ; preds = %14
store i32 1, i32* %8
br label %20
16: ; preds = %1
br label %17
17: ; preds = %16
br label %18
18: ; preds = %17
%19 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @__mpx_dig_abort to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([203 x i8], [203 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.inspect_pid, i64 0, i64 0), i32 427)
br label %20
20: ; preds = %18, %15
store i64 0, i64* %3
br label %21
21: ; preds = %52, %20
%22 = load i64, i64* %3
%23 = icmp ult i64 %22, 4194304
br i1 %23, label %24, label %55
24: ; preds = %21
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = load i64, i64* %3
%29 = getelementptr inbounds [262144 x i8], [262144 x i8]* %4, i64 0, i64 0
%30 = call i32 (i64, i64, i8*, ...) bitcast (i32 (...)* @fill_bounds_dir_buf_self to i32 (i64, i64, i8*, ...)*)(i64 %28, i64 262144, i8* %29)
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %5
br label %39
33: ; preds = %24
%34 = load i64, i64* %3
%35 = getelementptr inbounds [262144 x i8], [262144 x i8]* %4, i64 0, i64 0
%36 = call i32 (i64, i64, i8*, ...) bitcast (i32 (...)* @fill_bounds_dir_buf_other to i32 (i64, i64, i8*, ...)*)(i64 %34, i64 262144, i8* %35)
%37 = sext i32 %36 to i64
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %5
br label %39
39: ; preds = %33, %27
%40 = load i8*, i8** %5
%41 = icmp ne i8* %40, null
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i32, i32* @inspect_pid.bufs_skipped
%44 = add nsw i32 %43, 1
store i32 %44, i32* @inspect_pid.bufs_skipped
br label %52
45: ; preds = %39
%46 = load i8*, i8** %5
%47 = load i64, i64* %3
%48 = call i32 (i8*, i64, i64, i32*, ...) bitcast (i32 (...)* @search_bd_buf to i32 (i8*, i64, i64, i32*, ...)*)(i8* %46, i64 262144, i64 %47, i32* %7)
store i32 %48, i32* %9
%49 = load i32, i32* %9
%50 = load i32, i32* %6
%51 = add nsw i32 %50, %49
store i32 %51, i32* %6
br label %52
52: ; preds = %45, %42
%53 = load i64, i64* %3
%54 = add i64 %53, 262144
store i64 %54, i64* %3
br label %21
55: ; preds = %21
%56 = load i32, i32* @inspect_pid.dig_nr
%57 = add nsw i32 %56, 1
store i32 %57, i32* @inspect_pid.dig_nr
%58 = load i32, i32* %6
%59 = load i32, i32* %7
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %57, i32 %58, i32 %59)
%61 = load i32, i32* %6
%62 = load i32, i32* %7
%63 = add nsw i32 %61, %62
ret i32 %63
}

LLVM IR (-O2):
@inspect_pid.dig_nr = internal unnamed_addr global i32 0
@.str = [203 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/786228836/linux/refs/heads/4.8.6/ECE695-Spring17/t3-scheduler/linux-4.10.6/tools/testing/selftests/x86/mpx-dig.c\00"
@__func__.inspect_pid = [12 x i8] c"inspect_pid\00"
@inspect_pid.bufs_skipped = internal unnamed_addr global i32 0
@.str.1 = [45 x i8] c"mpx dig (%3d) complete, SUCCESS (%8d / %4d)\0A\00"
define i32 @inspect_pid(i32 %0) {
%2 = alloca [262144 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [262144 x i8], [262144 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = tail call i32 (...) @getpid()
%7 = icmp eq i32 %6, %0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @__mpx_dig_abort to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([203 x i8], [203 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.inspect_pid, i64 0, i64 0), i32 427)
br label %10
10: ; preds = %1, %8
br label %11
11: ; preds = %10, %24
%12 = phi i64 [ %26, %24 ], [ 0, %10 ]
%13 = phi i32 [ %25, %24 ], [ 0, %10 ]
%14 = call i32 (i64, i64, i8*, ...) bitcast (i32 (...)* @fill_bounds_dir_buf_self to i32 (i64, i64, i8*, ...)*)(i64 %12, i64 262144, i8* %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* @inspect_pid.bufs_skipped
%18 = add nsw i32 %17, 1
store i32 %18, i32* @inspect_pid.bufs_skipped
br label %24
19: ; preds = %11
%20 = sext i32 %14 to i64
%21 = inttoptr i64 %20 to i8*
%22 = call i32 (i8*, i64, i64, i32*, ...) bitcast (i32 (...)* @search_bd_buf to i32 (i8*, i64, i64, i32*, ...)*)(i8* %21, i64 262144, i64 %12, i32* %3)
%23 = add nsw i32 %22, %13
br label %24
24: ; preds = %19, %16
%25 = phi i32 [ %23, %19 ], [ %13, %16 ]
%26 = add nuw nsw i64 %12, 262144
%27 = icmp ult i64 %12, 3932160
br i1 %27, label %11, label %28
28: ; preds = %24
%29 = load i32, i32* @inspect_pid.dig_nr
%30 = add nsw i32 %29, 1
store i32 %30, i32* @inspect_pid.dig_nr
%31 = load i32, i32* %3
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %25, i32 %31)
%33 = load i32, i32* %3
%34 = add nsw i32 %33, %25
ret i32 %34
}