#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_binary_scale_fact(double max, double min, long bpval, int *ret) {
  double range = max - min;
  double zs = 1;
  long scale = 0;
  const long last = 127;
  unsigned long maxint = grib_power(bpval, 2) - 1;
  double dmaxint = (double)maxint;
  *ret = 0;
  {
    if (!(bpval >= 1))
      grib_fail("bpval >= 1",
                "/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",
                48);
  };
  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) {
    *ret = -49;
    scale = -last;
  }
  {
    if (!(scale <= last))
      grib_fail("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",
                81);
  };
  return scale;
}


x86 assembly (clang, -O0):
<grib_get_binary_scale_fact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movabs $0x3ff0000000000000,%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x7f,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2,%esi
call   1040 <grib_power@plt>
add    $0xffffffff,%eax
cltq
mov    %rax,-0x50(%rbp)
movaps 0xe77(%rip),%xmm1
movq   -0x50(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe76(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
cmpq   $0x1,-0x20(%rbp)
jge    11db <grib_get_binary_scale_fact+0xbb>
lea    0xe6e(%rip),%rdi
lea    0xe72(%rip),%rsi
mov    $0x30,%edx
call   1030 <grib_fail@plt>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1200 <grib_get_binary_scale_fact+0xe0>
jp     1200 <grib_get_binary_scale_fact+0xe0>
movq   $0x0,-0x8(%rbp)
jmp    13b2 <grib_get_binary_scale_fact+0x292>
jmp    1205 <grib_get_binary_scale_fact+0xe5>
movsd  -0x30(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1241 <grib_get_binary_scale_fact+0x121>
mov    -0x40(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x40(%rbp)
movsd  0xdfe(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1205 <grib_get_binary_scale_fact+0xe5>
jmp    1246 <grib_get_binary_scale_fact+0x126>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
ucomisd -0x58(%rbp),%xmm0
jbe    1282 <grib_get_binary_scale_fact+0x162>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xdbc(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1246 <grib_get_binary_scale_fact+0x126>
jmp    1287 <grib_get_binary_scale_fact+0x167>
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd83(%rip),%xmm1
addsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xd70(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
cmp    -0x50(%rbp),%rax
ja     12f4 <grib_get_binary_scale_fact+0x1d4>
mov    -0x40(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x40(%rbp)
movsd  0xd4b(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1287 <grib_get_binary_scale_fact+0x167>
jmp    12f9 <grib_get_binary_scale_fact+0x1d9>
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd11(%rip),%xmm1
addsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xcfe(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
cmp    -0x50(%rbp),%rax
jbe    136a <grib_get_binary_scale_fact+0x24a>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xcd4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    12f9 <grib_get_binary_scale_fact+0x1d9>
cmpq   $0xffffffffffffff81,-0x40(%rbp)
jge    1387 <grib_get_binary_scale_fact+0x267>
mov    -0x28(%rbp),%rax
movl   $0xffffffcf,(%rax)
movq   $0xffffffffffffff81,-0x40(%rbp)
ff
cmpq   $0x7f,-0x40(%rbp)
jle    13aa <grib_get_binary_scale_fact+0x28a>
lea    0xd52(%rip),%rdi
lea    0xca3(%rip),%rsi
mov    $0x51,%edx
call   1030 <grib_fail@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grib_get_binary_scale_fact>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%esi
call   1040 <grib_power@plt>
mov    %eax,%ebp
movl   $0x0,(%r14)
test   %rbx,%rbx
jg     1168 <grib_get_binary_scale_fact+0x48>
lea    0xee1(%rip),%rdi
lea    0xee5(%rip),%rsi
mov    $0x30,%edx
call   1030 <grib_fail@plt>
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm4
ucomisd %xmm0,%xmm4
jne    1181 <grib_get_binary_scale_fact+0x61>
jp     1181 <grib_get_binary_scale_fact+0x61>
xor    %ebx,%ebx
jmp    130b <grib_get_binary_scale_fact+0x1eb>
add    $0xffffffff,%ebp
movslq %ebp,%rax
movq   %rax,%xmm0
punpckldq 0xe6c(%rip),%xmm0
subpd  0xe74(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe70(%rip),%xmm0
xor    %ebx,%ebx
ucomisd %xmm4,%xmm1
jb     11d6 <grib_get_binary_scale_fact+0xb6>
nopl   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rbx
addsd  %xmm0,%xmm0
movapd %xmm4,%xmm2
mulsd  %xmm0,%xmm2
ucomisd %xmm2,%xmm1
jae    11c0 <grib_get_binary_scale_fact+0xa0>
movapd %xmm4,%xmm2
mulsd  %xmm0,%xmm2
ucomisd %xmm1,%xmm2
jbe    1206 <grib_get_binary_scale_fact+0xe6>
movsd  0xe3c(%rip),%xmm2
nopl   0x0(%rax)
add    $0x1,%rbx
mulsd  %xmm2,%xmm0
movapd %xmm4,%xmm3
mulsd  %xmm0,%xmm3
ucomisd %xmm1,%xmm3
ja     11f0 <grib_get_binary_scale_fact+0xd0>
movapd %xmm4,%xmm1
mulsd  %xmm0,%xmm1
addsd  0xe12(%rip),%xmm1
cvttsd2si %xmm1,%rdx
mov    %rdx,%rsi
subsd  0xe0a(%rip),%xmm1
cvttsd2si %xmm1,%rcx
sar    $0x3f,%rsi
and    %rsi,%rcx
or     %rdx,%rcx
cmp    %rax,%rcx
ja     1284 <grib_get_binary_scale_fact+0x164>
movsd  0xde6(%rip),%xmm1
movsd  0xde6(%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    %rax,%rcx
jbe    1250 <grib_get_binary_scale_fact+0x130>
cmp    %rax,%rcx
jbe    12d4 <grib_get_binary_scale_fact+0x1b4>
movsd  0xd97(%rip),%xmm1
movsd  0xd97(%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    %rax,%rsi
ja     12a0 <grib_get_binary_scale_fact+0x180>
cmp    $0xffffffffffffff80,%rbx
jg     12ea <grib_get_binary_scale_fact+0x1ca>
movl   $0xffffffcf,(%r14)
mov    $0xffffffffffffff81,%rbx
jmp    130b <grib_get_binary_scale_fact+0x1eb>
cmp    $0x80,%rbx
jl     130b <grib_get_binary_scale_fact+0x1eb>
lea    0xdf1(%rip),%rdi
lea    0xd42(%rip),%rsi
mov    $0x51,%edx
call   1030 <grib_fail@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"bpval >= 1\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"
@.str.2 = [14 x i8] c"scale <= last\00"
define i64 @grib_get_binary_scale_fact(double %0, double %1, i64 %2, i32* nocapture writeonly %3) {
%5 = fsub double %0, %1
%6 = tail call i32 @grib_power(i64 %2, i32 2)
%7 = add nsw i32 %6, -1
%8 = sext i32 %7 to i64
%9 = uitofp i64 %8 to double
store i32 0, i32* %3
%10 = icmp sgt i64 %2, 0
br i1 %10, label %13, label %11
11: ; preds = %4
%12 = tail call i32 @grib_fail(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str.1, i64 0, i64 0), i32 48)
br label %13
13: ; preds = %11, %4
%14 = fcmp oeq double %5, 0.000000e+00
br i1 %14, label %71, label %15
15: ; preds = %13
%16 = fcmp ugt double %5, %9
br i1 %16, label %17, label %22
17: ; preds = %22, %15
%18 = phi i64 [ 0, %15 ], [ %25, %22 ]
%19 = phi double [ 1.000000e+00, %15 ], [ %26, %22 ]
%20 = fmul double %5, %19
%21 = fcmp ogt double %20, %9
br i1 %21, label %35, label %29
22: ; preds = %15, %22
%23 = phi double [ %26, %22 ], [ 1.000000e+00, %15 ]
%24 = phi i64 [ %25, %22 ], [ 0, %15 ]
%25 = add nsw i64 %24, -1
%26 = fmul double %23, 2.000000e+00
%27 = fmul double %5, %26
%28 = fcmp ugt double %27, %9
br i1 %28, label %17, label %22
29: ; preds = %35, %17
%30 = phi i64 [ %18, %17 ], [ %38, %35 ]
%31 = phi double [ %19, %17 ], [ %39, %35 ]
%32 = tail call double @llvm.fmuladd.f64(double %5, double %31, double 5.000000e-01)
%33 = fptoui double %32 to i64
%34 = icmp ugt i64 %33, %8
br i1 %34, label %42, label %47
35: ; preds = %17, %35
%36 = phi double [ %39, %35 ], [ %19, %17 ]
%37 = phi i64 [ %38, %35 ], [ %18, %17 ]
%38 = add nsw i64 %37, 1
%39 = fmul double %36, 5.000000e-01
%40 = fmul double %5, %39
%41 = fcmp ogt double %40, %9
br i1 %41, label %35, label %29
42: ; preds = %47, %29
%43 = phi i64 [ %33, %29 ], [ %53, %47 ]
%44 = phi i64 [ %30, %29 ], [ %50, %47 ]
%45 = phi double [ %31, %29 ], [ %51, %47 ]
%46 = icmp ugt i64 %43, %8
br i1 %46, label %55, label %63
47: ; preds = %29, %47
%48 = phi double [ %51, %47 ], [ %31, %29 ]
%49 = phi i64 [ %50, %47 ], [ %30, %29 ]
%50 = add nsw i64 %49, -1
%51 = fmul double %48, 2.000000e+00
%52 = tail call double @llvm.fmuladd.f64(double %5, double %51, double 5.000000e-01)
%53 = fptoui double %52 to i64
%54 = icmp ugt i64 %53, %8
br i1 %54, label %42, label %47
55: ; preds = %42, %55
%56 = phi double [ %59, %55 ], [ %45, %42 ]
%57 = phi i64 [ %58, %55 ], [ %44, %42 ]
%58 = add nsw i64 %57, 1
%59 = fmul double %56, 5.000000e-01
%60 = tail call double @llvm.fmuladd.f64(double %5, double %59, double 5.000000e-01)
%61 = fptoui double %60 to i64
%62 = icmp ugt i64 %61, %8
br i1 %62, label %55, label %63
63: ; preds = %55, %42
%64 = phi i64 [ %44, %42 ], [ %58, %55 ]
%65 = icmp slt i64 %64, -127
br i1 %65, label %66, label %67
66: ; preds = %63
store i32 -49, i32* %3
br label %71
67: ; preds = %63
%68 = icmp slt i64 %64, 128
br i1 %68, label %71, label %69
69: ; preds = %67
%70 = tail call i32 @grib_fail(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str.1, i64 0, i64 0), i32 81)
br label %71
71: ; preds = %66, %67, %69, %13
%72 = phi i64 [ 0, %13 ], [ %64, %69 ], [ %64, %67 ], [ -127, %66 ]
ret i64 %72
}