#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 /*<<< orphan*/ O_DIRECTORY;
int apply_size_suffix(int, char, char *);
int /*<<< orphan*/ close(int);
char *get_file_content(int, char *);
int make_log2_friendly(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
int sscanf(char const *, char *, int *, char *);
scalar_t__ strncmp(char const *, char *, int);
unsigned detect_bucket_size(unsigned fallback_size) {
  const char *s;
  char size_suffix;
  static int bucket_size = 0;
  if (bucket_size) {
    return bucket_size > 0 ? (bucket_size / 1) : fallback_size;
  }
  int dir = open("/sys/devices/system/cpu/cpu0/cache/index0", O_DIRECTORY);
  if (dir < 0) {
    bucket_size = -1;
    return fallback_size;
  }
  if (!(s = get_file_content(dir, "level")) || strncmp(s, "1", 1) != 0) {
    printf("Cannot detect L1 cache size in %s:%d\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/EverythingMe/libbloom/refs/heads/master/"
           "linux.c",
           75);
    goto out_err;
  }
  if (!(s = get_file_content(dir, "type")) || strncmp(s, "Data", 4) != 0) {
    printf("Cannot detect L1 cache size in %s:%d\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/EverythingMe/libbloom/refs/heads/master/"
           "linux.c",
           81);
    goto out_err;
  }
  if (!(s = get_file_content(dir, "size")) ||
      sscanf(s, "%d%c", &bucket_size, &size_suffix) != 2) {
    printf("Cannot detect L1 cache size in %s:%d\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/EverythingMe/libbloom/refs/heads/master/"
           "linux.c",
           88);
    goto out_err;
  }
  bucket_size = apply_size_suffix(bucket_size, size_suffix,
                                  "Cannot detect L1 cache size");
  if (bucket_size < 0) {
    goto out_err;
  }
  bucket_size = make_log2_friendly(bucket_size);
  bucket_size /= 1;
  close(dir);
  return bucket_size;
out_err:
  bucket_size = -1;
  close(dir);
  return fallback_size;
}


x86 assembly (clang, -O0):
<detect_bucket_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,0x2ed2(%rip)
je     11cc <detect_bucket_size+0x4c>
cmpl   $0x0,0x2ec5(%rip)
jle    11bb <detect_bucket_size+0x3b>
mov    0x2eb9(%rip),%eax
mov    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
jmp    11c1 <detect_bucket_size+0x41>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1394 <detect_bucket_size+0x214>
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
lea    0xe24(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1203 <detect_bucket_size+0x83>
movl   $0xffffffff,0x2e6c(%rip)
ff ff ff
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1394 <detect_bucket_size+0x214>
mov    -0x18(%rbp),%edi
lea    0xe1d(%rip),%rsi
call   1040 <get_file_content@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     123f <detect_bucket_size+0xbf>
mov    -0x10(%rbp),%rdi
lea    0xe05(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     125c <detect_bucket_size+0xdc>
lea    0xdec(%rip),%rdi
lea    0xe0b(%rip),%rsi
mov    $0x4b,%edx
call   1050 <printf@plt>
jmp    137c <detect_bucket_size+0x1fc>
mov    -0x18(%rbp),%edi
lea    0xe7c(%rip),%rsi
call   1040 <get_file_content@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1298 <detect_bucket_size+0x118>
mov    -0x10(%rbp),%rdi
lea    0xe63(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     12b5 <detect_bucket_size+0x135>
lea    0xd93(%rip),%rdi
lea    0xdb2(%rip),%rsi
mov    $0x51,%edx
call   1050 <printf@plt>
jmp    137c <detect_bucket_size+0x1fc>
mov    -0x18(%rbp),%edi
lea    0xe49(%rip),%rsi
call   1040 <get_file_content@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     12f6 <detect_bucket_size+0x176>
mov    -0x10(%rbp),%rdi
lea    0xe0f(%rip),%rsi
lea    0x2d80(%rip),%rdx
lea    -0x11(%rbp),%rcx
call   1070 <sscanf@plt>
cmp    $0x2,%eax
je     1313 <detect_bucket_size+0x193>
lea    0xd35(%rip),%rdi
lea    0xd54(%rip),%rsi
mov    $0x58,%edx
call   1050 <printf@plt>
jmp    137c <detect_bucket_size+0x1fc>
mov    0x2d4b(%rip),%edi
lea    0xdd1(%rip),%rdx
movsbl -0x11(%rbp),%esi
call   10a0 <apply_size_suffix@plt>
mov    %eax,0x2d35(%rip)
cmpl   $0x0,0x2d2e(%rip)
jge    1341 <detect_bucket_size+0x1c1>
jmp    137c <detect_bucket_size+0x1fc>
mov    0x2d1d(%rip),%edi
call   1080 <make_log2_friendly@plt>
mov    %eax,0x2d12(%rip)
mov    0x2d0c(%rip),%eax
mov    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,0x2cfe(%rip)
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    0x2cf0(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    1394 <detect_bucket_size+0x214>
movl   $0xffffffff,0x2cde(%rip)
ff ff ff
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_bucket_size>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ed9(%rip),%eax
test   %eax,%eax
je     1194 <detect_bucket_size+0x14>
cmovg  %eax,%ebx
jmp    1210 <detect_bucket_size+0x90>
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0xe5c(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1206 <detect_bucket_size+0x86>
mov    %eax,%ebp
lea    0xe74(%rip),%rsi
mov    %eax,%edi
call   1040 <get_file_content@plt>
test   %rax,%rax
je     11db <detect_bucket_size+0x5b>
lea    0xe67(%rip),%rsi
mov    %rax,%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1219 <detect_bucket_size+0x99>
lea    0xe50(%rip),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x4b,%edx
call   1050 <printf@plt>
movl   $0xffffffff,0x2e67(%rip)
ff ff ff
mov    %ebp,%edi
call   1060 <close@plt>
jmp    1210 <detect_bucket_size+0x90>
movl   $0xffffffff,0x2e54(%rip)
ff ff ff
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xec2(%rip),%rsi
mov    %ebp,%edi
call   1040 <get_file_content@plt>
test   %rax,%rax
je     1245 <detect_bucket_size+0xc5>
lea    0xeb4(%rip),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     125a <detect_bucket_size+0xda>
lea    0xde6(%rip),%rdi
lea    0xe05(%rip),%rsi
mov    $0x51,%edx
jmp    11ee <detect_bucket_size+0x6e>
lea    0xea7(%rip),%rsi
mov    %ebp,%edi
call   1040 <get_file_content@plt>
test   %rax,%rax
je     12d1 <detect_bucket_size+0x151>
lea    0xe78(%rip),%rsi
lea    0x2de9(%rip),%rdx
lea    0x7(%rsp),%rcx
mov    %rax,%rdi
call   1070 <sscanf@plt>
cmp    $0x2,%eax
jne    12d1 <detect_bucket_size+0x151>
mov    0x2dd1(%rip),%edi
movsbl 0x7(%rsp),%esi
lea    0xe52(%rip),%rdx
call   10a0 <apply_size_suffix@plt>
mov    %eax,0x2dba(%rip)
test   %eax,%eax
js     11f3 <detect_bucket_size+0x73>
mov    %eax,%edi
call   1080 <make_log2_friendly@plt>
mov    %eax,0x2da5(%rip)
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2d98(%rip),%ebx
jmp    1210 <detect_bucket_size+0x90>
lea    0xd5a(%rip),%rdi
lea    0xd79(%rip),%rsi
mov    $0x58,%edx
jmp    11ee <detect_bucket_size+0x6e>

LLVM IR (-O0):
@detect_bucket_size.bucket_size = internal global i32 0
@.str = [42 x i8] c"/sys/devices/system/cpu/cpu0/cache/index0\00"
@O_DIRECTORY = global i32 0
@.str.1 = [6 x i8] c"level\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [38 x i8] c"Cannot detect L1 cache size in %s:%d\0A\00"
@.str.4 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/EverythingMe/libbloom/refs/heads/master/linux.c\00"
@.str.5 = [5 x i8] c"type\00"
@.str.6 = [5 x i8] c"Data\00"
@.str.7 = [5 x i8] c"size\00"
@.str.8 = [5 x i8] c"%d%c\00"
@.str.9 = [28 x i8] c"Cannot detect L1 cache size\00"
define i32 @detect_bucket_size(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* @detect_bucket_size.bucket_size
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %1
%10 = load i32, i32* @detect_bucket_size.bucket_size
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @detect_bucket_size.bucket_size
%14 = sdiv i32 %13, 1
br label %17
15: ; preds = %9
%16 = load i32, i32* %3
br label %17
17: ; preds = %15, %12
%18 = phi i32 [ %14, %12 ], [ %16, %15 ]
store i32 %18, i32* %2
br label %75
19: ; preds = %1
%20 = load i32, i32* @O_DIRECTORY
%21 = call i32 @open(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
store i32 -1, i32* @detect_bucket_size.bucket_size
%25 = load i32, i32* %3
store i32 %25, i32* %2
br label %75
26: ; preds = %19
%27 = load i32, i32* %6
%28 = call i8* @get_file_content(i32 %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i8* %28, i8** %4
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i8*, i8** %4
%32 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30, %26
%35 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.4, i64 0, i64 0), i32 75)
br label %71
36: ; preds = %30
%37 = load i32, i32* %6
%38 = call i8* @get_file_content(i32 %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i8* %38, i8** %4
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i8*, i8** %4
%42 = call i64 @strncmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40, %36
%45 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.4, i64 0, i64 0), i32 81)
br label %71
46: ; preds = %40
%47 = load i32, i32* %6
%48 = call i8* @get_file_content(i32 %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
store i8* %48, i8** %4
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = load i8*, i8** %4
%52 = call i32 @sscanf(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32* @detect_bucket_size.bucket_size, i8* %5)
%53 = icmp ne i32 %52, 2
br i1 %53, label %54, label %56
54: ; preds = %50, %46
%55 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.4, i64 0, i64 0), i32 88)
br label %71
56: ; preds = %50
%57 = load i32, i32* @detect_bucket_size.bucket_size
%58 = load i8, i8* %5
%59 = call i32 @apply_size_suffix(i32 %57, i8 signext %58, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
store i32 %59, i32* @detect_bucket_size.bucket_size
%60 = load i32, i32* @detect_bucket_size.bucket_size
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %56
br label %71
63: ; preds = %56
%64 = load i32, i32* @detect_bucket_size.bucket_size
%65 = call i32 @make_log2_friendly(i32 %64)
store i32 %65, i32* @detect_bucket_size.bucket_size
%66 = load i32, i32* @detect_bucket_size.bucket_size
%67 = sdiv i32 %66, 1
store i32 %67, i32* @detect_bucket_size.bucket_size
%68 = load i32, i32* %6
%69 = call i32 @close(i32 %68)
%70 = load i32, i32* @detect_bucket_size.bucket_size
store i32 %70, i32* %2
br label %75
71: ; preds = %62, %54, %44, %34
store i32 -1, i32* @detect_bucket_size.bucket_size
%72 = load i32, i32* %6
%73 = call i32 @close(i32 %72)
%74 = load i32, i32* %3
store i32 %74, i32* %2
br label %75
75: ; preds = %71, %63, %24, %17
%76 = load i32, i32* %2
ret i32 %76
}

LLVM IR (-O2):
@detect_bucket_size.bucket_size = internal global i32 0
@.str = [42 x i8] c"/sys/devices/system/cpu/cpu0/cache/index0\00"
@O_DIRECTORY = global i32 0
@.str.1 = [6 x i8] c"level\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [38 x i8] c"Cannot detect L1 cache size in %s:%d\0A\00"
@.str.4 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/EverythingMe/libbloom/refs/heads/master/linux.c\00"
@.str.5 = [5 x i8] c"type\00"
@.str.6 = [5 x i8] c"Data\00"
@.str.7 = [5 x i8] c"size\00"
@.str.8 = [5 x i8] c"%d%c\00"
@.str.9 = [28 x i8] c"Cannot detect L1 cache size\00"
define i32 @detect_bucket_size(i32 %0) {
%2 = alloca i8
%3 = load i32, i32* @detect_bucket_size.bucket_size
%4 = icmp eq i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = icmp sgt i32 %3, 0
%7 = select i1 %6, i32 %3, i32 %0
br label %48
8: ; preds = %1
%9 = load i32, i32* @O_DIRECTORY
%10 = tail call i32 @open(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 -1, i32* @detect_bucket_size.bucket_size
br label %48
13: ; preds = %8
%14 = tail call i8* @get_file_content(i32 %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = tail call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16, %13
%20 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.4, i64 0, i64 0), i32 75)
br label %46
21: ; preds = %16
%22 = tail call i8* @get_file_content(i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = tail call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24, %21
%28 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.4, i64 0, i64 0), i32 81)
br label %46
29: ; preds = %24
%30 = tail call i8* @get_file_content(i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%31 = icmp eq i8* %30, null
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32* @detect_bucket_size.bucket_size, i8* %2)
%34 = icmp eq i32 %33, 2
br i1 %34, label %37, label %35
35: ; preds = %32, %29
%36 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.4, i64 0, i64 0), i32 88)
br label %46
37: ; preds = %32
%38 = load i32, i32* @detect_bucket_size.bucket_size
%39 = load i8, i8* %2
%40 = call i32 @apply_size_suffix(i32 %38, i8 signext %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
store i32 %40, i32* @detect_bucket_size.bucket_size
%41 = icmp slt i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %37
%43 = call i32 @make_log2_friendly(i32 %40)
store i32 %43, i32* @detect_bucket_size.bucket_size
%44 = call i32 @close(i32 %10)
%45 = load i32, i32* @detect_bucket_size.bucket_size
br label %48
46: ; preds = %37, %35, %27, %19
store i32 -1, i32* @detect_bucket_size.bucket_size
%47 = call i32 @close(i32 %10)
br label %48
48: ; preds = %12, %42, %46, %5
%49 = phi i32 [ %7, %5 ], [ %0, %12 ], [ %0, %46 ], [ %45, %42 ]
ret i32 %49
}