#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*/ grib_fail(char *, char *, int);
int grib_power(long, int);
long grib_get_bits_per_value(double max, double min, long binary_scale_factor) {
  double range = max - min;
  double zs = 1;
  long scale = 0;
  const long last = 127;
  unsigned long maxint = grib_power(binary_scale_factor, 2) - 1;
  double dmaxint = (double)maxint;
  if (maxint == 0)
    maxint = 1;
  if (range == 0)
    return 0;
  while ((range * zs) <= dmaxint) {
    scale--;
    zs *= 2;
  }
  while ((range * zs) > dmaxint) {
    scale++;
    zs /= 2;
  }
  while ((unsigned long)(range * zs + 0.5) <= maxint) {
    scale--;
    zs *= 2;
  }
  while ((unsigned long)(range * zs + 0.5) > maxint) {
    scale++;
    zs /= 2;
  }
  {
    if (!(scale >= -last && scale <= last))
      grib_fail("scale >= -last && scale <= last",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/MengbinZhu/pfldp/refs/heads/"
                "master/ropp-7.0/grib_api-1.9.9/src/grib_scaling.c",
                121);
  };
  return scale;
}


x86 assembly (clang, -O0):
<grib_get_bits_per_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movabs $0x3ff0000000000000,%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x7f,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2,%esi
call   1040 <grib_power@plt>
add    $0xffffffff,%eax
cltq
mov    %rax,-0x48(%rbp)
movaps 0xe7b(%rip),%xmm1
movq   -0x48(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe7a(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11bd <grib_get_bits_per_value+0x9d>
movq   $0x1,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11e2 <grib_get_bits_per_value+0xc2>
jp     11e2 <grib_get_bits_per_value+0xc2>
movq   $0x0,-0x8(%rbp)
jmp    1382 <grib_get_bits_per_value+0x262>
jmp    11e7 <grib_get_bits_per_value+0xc7>
movsd  -0x28(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1223 <grib_get_bits_per_value+0x103>
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
movsd  0xe1c(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11e7 <grib_get_bits_per_value+0xc7>
jmp    1228 <grib_get_bits_per_value+0x108>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    1264 <grib_get_bits_per_value+0x144>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xdda(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1228 <grib_get_bits_per_value+0x108>
jmp    1269 <grib_get_bits_per_value+0x149>
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xda1(%rip),%xmm1
addsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xd8e(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
cmp    -0x48(%rbp),%rax
ja     12d6 <grib_get_bits_per_value+0x1b6>
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
movsd  0xd69(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1269 <grib_get_bits_per_value+0x149>
jmp    12db <grib_get_bits_per_value+0x1bb>
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd2f(%rip),%xmm1
addsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xd1c(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
cmp    -0x48(%rbp),%rax
jbe    134c <grib_get_bits_per_value+0x22c>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xcf2(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    12db <grib_get_bits_per_value+0x1bb>
cmpq   $0xffffffffffffff81,-0x38(%rbp)
jl     1362 <grib_get_bits_per_value+0x242>
cmpq   $0x7f,-0x38(%rbp)
jle    137a <grib_get_bits_per_value+0x25a>
lea    0xccf(%rip),%rdi
lea    0xce8(%rip),%rsi
mov    $0x79,%edx
call   1030 <grib_fail@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grib_get_bits_per_value>:
push   %rbx
sub    $0x10,%rsp
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%esi
call   1040 <grib_power@plt>
movsd  0x8(%rsp),%xmm4
add    $0xffffffff,%eax
movslq %eax,%rcx
test   %ecx,%ecx
mov    $0x1,%eax
cmovne %rcx,%rax
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm4
jne    1163 <grib_get_bits_per_value+0x43>
jp     1163 <grib_get_bits_per_value+0x43>
xor    %ebx,%ebx
jmp    12d8 <grib_get_bits_per_value+0x1b8>
movq   %rcx,%xmm0
punpckldq 0xe90(%rip),%xmm0
subpd  0xe98(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe94(%rip),%xmm0
xor    %ebx,%ebx
ucomisd %xmm4,%xmm1
jb     11b6 <grib_get_bits_per_value+0x96>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffffffffffff,%rbx
addsd  %xmm0,%xmm0
movapd %xmm4,%xmm2
mulsd  %xmm0,%xmm2
ucomisd %xmm2,%xmm1
jae    11a0 <grib_get_bits_per_value+0x80>
movapd %xmm4,%xmm2
mulsd  %xmm0,%xmm2
ucomisd %xmm1,%xmm2
jbe    11e6 <grib_get_bits_per_value+0xc6>
movsd  0xe5c(%rip),%xmm2
nopl   0x0(%rax)
add    $0x1,%rbx
mulsd  %xmm2,%xmm0
movapd %xmm4,%xmm3
mulsd  %xmm0,%xmm3
ucomisd %xmm1,%xmm3
ja     11d0 <grib_get_bits_per_value+0xb0>
movapd %xmm4,%xmm1
mulsd  %xmm0,%xmm1
addsd  0xe32(%rip),%xmm1
cvttsd2si %xmm1,%rdx
mov    %rdx,%rsi
subsd  0xe2a(%rip),%xmm1
cvttsd2si %xmm1,%rcx
sar    $0x3f,%rsi
and    %rsi,%rcx
or     %rdx,%rcx
cmp    %rcx,%rax
jb     1264 <grib_get_bits_per_value+0x144>
movsd  0xe06(%rip),%xmm1
movsd  0xe06(%rip),%xmm2
nopw   0x0(%rax,%rax,1)
addsd  %xmm0,%xmm0
movapd %xmm4,%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm1,%xmm3
cvttsd2si %xmm3,%rdx
add    $0xffffffffffffffff,%rbx
mov    %rdx,%rsi
subsd  %xmm2,%xmm3
cvttsd2si %xmm3,%rcx
sar    $0x3f,%rsi
and    %rsi,%rcx
or     %rdx,%rcx
cmp    %rcx,%rax
jae    1230 <grib_get_bits_per_value+0x110>
cmp    %rcx,%rax
jae    12b4 <grib_get_bits_per_value+0x194>
movsd  0xdb7(%rip),%xmm1
movsd  0xdb7(%rip),%xmm2
nopl   0x0(%rax)
mulsd  %xmm1,%xmm0
movapd %xmm4,%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm1,%xmm3
cvttsd2si %xmm3,%rcx
add    $0x1,%rbx
mov    %rcx,%rdx
subsd  %xmm2,%xmm3
cvttsd2si %xmm3,%rsi
sar    $0x3f,%rdx
and    %rdx,%rsi
or     %rcx,%rsi
cmp    %rsi,%rax
jb     1280 <grib_get_bits_per_value+0x160>
lea    0x7f(%rbx),%rax
cmp    $0xff,%rax
jb     12d8 <grib_get_bits_per_value+0x1b8>
lea    0xd71(%rip),%rdi
lea    0xd8a(%rip),%rsi
mov    $0x79,%edx
call   1030 <grib_fail@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"scale >= -last && scale <= last\00"
@.str.1 = [168 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/MengbinZhu/pfldp/refs/heads/master/ropp-7.0/grib_api-1.9.9/src/grib_scaling.c\00"
define i64 @grib_get_bits_per_value(double %0, double %1, i64 %2) {
%4 = alloca i64
%5 = alloca double
%6 = alloca double
%7 = alloca i64
%8 = alloca double
%9 = alloca double
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca double
store double %0, double* %5
store double %1, double* %6
store i64 %2, i64* %7
%14 = load double, double* %5
%15 = load double, double* %6
%16 = fsub double %14, %15
store double %16, double* %8
store double 1.000000e+00, double* %9
store i64 0, i64* %10
store i64 127, i64* %11
%17 = load i64, i64* %7
%18 = call i32 @grib_power(i64 %17, i32 2)
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
store i64 %20, i64* %12
%21 = load i64, i64* %12
%22 = uitofp i64 %21 to double
store double %22, double* %13
%23 = load i64, i64* %12
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %3
store i64 1, i64* %12
br label %26
26: ; preds = %25, %3
%27 = load double, double* %8
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %29, label %30
29: ; preds = %26
store i64 0, i64* %4
br label %90
30: ; preds = %26
br label %31
31: ; preds = %37, %30
%32 = load double, double* %8
%33 = load double, double* %9
%34 = fmul double %32, %33
%35 = load double, double* %13
%36 = fcmp ole double %34, %35
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i64, i64* %10
%39 = add nsw i64 %38, -1
store i64 %39, i64* %10
%40 = load double, double* %9
%41 = fmul double %40, 2.000000e+00
store double %41, double* %9
br label %31
42: ; preds = %31
br label %43
43: ; preds = %49, %42
%44 = load double, double* %8
%45 = load double, double* %9
%46 = fmul double %44, %45
%47 = load double, double* %13
%48 = fcmp ogt double %46, %47
br i1 %48, label %49, label %54
49: ; preds = %43
%50 = load i64, i64* %10
%51 = add nsw i64 %50, 1
store i64 %51, i64* %10
%52 = load double, double* %9
%53 = fdiv double %52, 2.000000e+00
store double %53, double* %9
br label %43
54: ; preds = %43
br label %55
55: ; preds = %62, %54
%56 = load double, double* %8
%57 = load double, double* %9
%58 = call double @llvm.fmuladd.f64(double %56, double %57, double 5.000000e-01)
%59 = fptoui double %58 to i64
%60 = load i64, i64* %12
%61 = icmp ule i64 %59, %60
br i1 %61, label %62, label %67
62: ; preds = %55
%63 = load i64, i64* %10
%64 = add nsw i64 %63, -1
store i64 %64, i64* %10
%65 = load double, double* %9
%66 = fmul double %65, 2.000000e+00
store double %66, double* %9
br label %55
67: ; preds = %55
br label %68
68: ; preds = %75, %67
%69 = load double, double* %8
%70 = load double, double* %9
%71 = call double @llvm.fmuladd.f64(double %69, double %70, double 5.000000e-01)
%72 = fptoui double %71 to i64
%73 = load i64, i64* %12
%74 = icmp ugt i64 %72, %73
br i1 %74, label %75, label %80
75: ; preds = %68
%76 = load i64, i64* %10
%77 = add nsw i64 %76, 1
store i64 %77, i64* %10
%78 = load double, double* %9
%79 = fdiv double %78, 2.000000e+00
store double %79, double* %9
br label %68
80: ; preds = %68
%81 = load i64, i64* %10
%82 = icmp sge i64 %81, -127
br i1 %82, label %83, label %86
83: ; preds = %80
%84 = load i64, i64* %10
%85 = icmp sle i64 %84, 127
br i1 %85, label %88, label %86
86: ; preds = %83, %80
%87 = call i32 @grib_fail(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str.1, i64 0, i64 0), i32 121)
br label %88
88: ; preds = %86, %83
%89 = load i64, i64* %10
store i64 %89, i64* %4
br label %90
90: ; preds = %88, %29
%91 = load i64, i64* %4
ret i64 %91
}

LLVM IR (-O2):
@.str = [32 x i8] c"scale >= -last && scale <= last\00"
@.str.1 = [168 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/MengbinZhu/pfldp/refs/heads/master/ropp-7.0/grib_api-1.9.9/src/grib_scaling.c\00"
define i64 @grib_get_bits_per_value(double %0, double %1, i64 %2) {
%4 = fsub double %0, %1
%5 = tail call i32 @grib_power(i64 %2, i32 2)
%6 = add nsw i32 %5, -1
%7 = sext i32 %6 to i64
%8 = uitofp i64 %7 to double
%9 = icmp eq i32 %6, 0
%10 = select i1 %9, i64 1, i64 %7
%11 = fcmp oeq double %4, 0.000000e+00
br i1 %11, label %66, label %12
12: ; preds = %3
%13 = fcmp ugt double %4, %8
br i1 %13, label %14, label %19
14: ; preds = %19, %12
%15 = phi i64 [ 0, %12 ], [ %22, %19 ]
%16 = phi double [ 1.000000e+00, %12 ], [ %23, %19 ]
%17 = fmul double %4, %16
%18 = fcmp ogt double %17, %8
br i1 %18, label %32, label %26
19: ; preds = %12, %19
%20 = phi double [ %23, %19 ], [ 1.000000e+00, %12 ]
%21 = phi i64 [ %22, %19 ], [ 0, %12 ]
%22 = add nsw i64 %21, -1
%23 = fmul double %20, 2.000000e+00
%24 = fmul double %4, %23
%25 = fcmp ugt double %24, %8
br i1 %25, label %14, label %19
26: ; preds = %32, %14
%27 = phi i64 [ %15, %14 ], [ %35, %32 ]
%28 = phi double [ %16, %14 ], [ %36, %32 ]
%29 = tail call double @llvm.fmuladd.f64(double %4, double %28, double 5.000000e-01)
%30 = fptoui double %29 to i64
%31 = icmp ult i64 %10, %30
br i1 %31, label %39, label %44
32: ; preds = %14, %32
%33 = phi double [ %36, %32 ], [ %16, %14 ]
%34 = phi i64 [ %35, %32 ], [ %15, %14 ]
%35 = add nsw i64 %34, 1
%36 = fmul double %33, 5.000000e-01
%37 = fmul double %4, %36
%38 = fcmp ogt double %37, %8
br i1 %38, label %32, label %26
39: ; preds = %44, %26
%40 = phi i64 [ %30, %26 ], [ %50, %44 ]
%41 = phi i64 [ %27, %26 ], [ %47, %44 ]
%42 = phi double [ %28, %26 ], [ %48, %44 ]
%43 = icmp ult i64 %10, %40
br i1 %43, label %52, label %60
44: ; preds = %26, %44
%45 = phi double [ %48, %44 ], [ %28, %26 ]
%46 = phi i64 [ %47, %44 ], [ %27, %26 ]
%47 = add nsw i64 %46, -1
%48 = fmul double %45, 2.000000e+00
%49 = tail call double @llvm.fmuladd.f64(double %4, double %48, double 5.000000e-01)
%50 = fptoui double %49 to i64
%51 = icmp ult i64 %10, %50
br i1 %51, label %39, label %44
52: ; preds = %39, %52
%53 = phi double [ %56, %52 ], [ %42, %39 ]
%54 = phi i64 [ %55, %52 ], [ %41, %39 ]
%55 = add nsw i64 %54, 1
%56 = fmul double %53, 5.000000e-01
%57 = tail call double @llvm.fmuladd.f64(double %4, double %56, double 5.000000e-01)
%58 = fptoui double %57 to i64
%59 = icmp ult i64 %10, %58
br i1 %59, label %52, label %60
60: ; preds = %52, %39
%61 = phi i64 [ %41, %39 ], [ %55, %52 ]
%62 = add i64 %61, 127
%63 = icmp ult i64 %62, 255
br i1 %63, label %66, label %64
64: ; preds = %60
%65 = tail call i32 @grib_fail(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str.1, i64 0, i64 0), i32 121)
br label %66
66: ; preds = %64, %60, %3
%67 = phi i64 [ 0, %3 ], [ %61, %60 ], [ %61, %64 ]
ret i64 %67
}