#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 ceil(int);
double fabs(double);
scalar_t__ fmod(int, int);
int log10(int);
double pow(int, double);
unsigned long grib_local_ibm(double local_float) {
  long a, b;
  unsigned long ibm_float;
  if (local_float == 0.) {
    ibm_float = 0;
  } else {
    a = ceil(log10(fabs(local_float)) / log10(16.)) + 64;
    if (fmod((log10(fabs(local_float)) / log10(16.)), 1.) == 0) {
      a++;
    }
    if ((local_float == 1.) || (local_float == -1.))
      a = 65;
    b = (long)(fabs(local_float) * pow(16., (double)(70 - a)) + .5) &
        0x00ffffff;
    ibm_float = (((local_float > 0.) ? 0 : 1) << 31) | (a << 24) | b;
  }
  return ibm_float;
}


x86 assembly (clang, -O0):
<grib_local_ibm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1172 <grib_local_ibm+0x32>
jp     1172 <grib_local_ibm+0x32>
movq   $0x0,-0x20(%rbp)
jmp    12c9 <grib_local_ibm+0x189>
movsd  -0x8(%rbp),%xmm0
movaps 0xe82(%rip),%xmm1
pand   %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <log10@plt>
mov    %eax,-0x28(%rbp)
mov    $0x10,%edi
call   1060 <log10@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <ceil@plt>
add    $0x40,%eax
cltq
mov    %rax,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movaps 0xe44(%rip),%xmm1
pand   %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <log10@plt>
mov    %eax,-0x24(%rbp)
mov    $0x10,%edi
call   1060 <log10@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <fmod@plt>
cmp    $0x0,%rax
jne    1200 <grib_local_ibm+0xc0>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe03(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1222 <grib_local_ibm+0xe2>
jp     1222 <grib_local_ibm+0xe2>
jmp    123f <grib_local_ibm+0xff>
movsd  -0x8(%rbp),%xmm0
movsd  0xde9(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1247 <grib_local_ibm+0x107>
jp     1247 <grib_local_ibm+0x107>
movq   $0x41,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movaps 0xdad(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x46,%eax
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    $0x10,%edi
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd98(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
and    $0xffffff,%rax
mov    %rax,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
mov    $0x1,%eax
xor    %ecx,%ecx
ucomisd %xmm1,%xmm0
cmova  %ecx,%eax
shl    $0x1f,%eax
cltq
mov    -0x10(%rbp),%rcx
shl    $0x18,%rcx
or     %rcx,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grib_local_ibm>:
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    114f <grib_local_ibm+0xf>
jp     114f <grib_local_ibm+0xf>
xor    %eax,%eax
ret
push   %rbp
push   %rbx
sub    $0x28,%rsp
movapd 0xea3(%rip),%xmm1
andpd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
cvttsd2si %xmm1,%ebx
mov    %ebx,%edi
movapd %xmm0,(%rsp)
call   1060 <log10@plt>
mov    %eax,%ebp
mov    $0x10,%edi
call   1060 <log10@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1060 <log10@plt>
mov    %eax,%ebx
mov    $0x10,%edi
call   1060 <log10@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <fmod@plt>
cmp    $0x1,%rax
movslq %ebp,%rax
adc    $0x0,%rax
add    $0x40,%rax
movapd (%rsp),%xmm0
ucomisd 0xe3b(%rip),%xmm0
mov    $0x41,%ecx
cmovne %rax,%rcx
cmovp  %rax,%rcx
mov    $0x41,%ebx
ucomisd 0xe29(%rip),%xmm0
cmovne %rcx,%rbx
cmovp  %rcx,%rbx
mov    $0x46,%eax
sub    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    $0x10,%edi
call   1050 <pow@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0xe01(%rip),%xmm0
cvttsd2si %xmm0,%rax
and    $0xffffff,%eax
xor    %ecx,%ecx
movapd (%rsp),%xmm0
ucomisd 0xdf0(%rip),%xmm0
seta   %cl
shl    $0x1f,%rcx
shl    $0x18,%rbx
add    %rcx,%rax
add    $0xffffffff80000000,%rax
or     %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i64 @grib_local_ibm(double %0) {
%2 = alloca double
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store double %0, double* %2
%6 = load double, double* %2
%7 = fcmp oeq double %6, 0.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %1
store i64 0, i64* %5
br label %58
9: ; preds = %1
%10 = load double, double* %2
%11 = call double @llvm.fabs.f64(double %10)
%12 = fptosi double %11 to i32
%13 = call i32 @log10(i32 %12)
%14 = call i32 @log10(i32 16)
%15 = sdiv i32 %13, %14
%16 = call i32 @ceil(i32 %15)
%17 = add nsw i32 %16, 64
%18 = sext i32 %17 to i64
store i64 %18, i64* %3
%19 = load double, double* %2
%20 = call double @llvm.fabs.f64(double %19)
%21 = fptosi double %20 to i32
%22 = call i32 @log10(i32 %21)
%23 = call i32 @log10(i32 16)
%24 = sdiv i32 %22, %23
%25 = call i64 @fmod(i32 %24, i32 1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %9
%28 = load i64, i64* %3
%29 = add nsw i64 %28, 1
store i64 %29, i64* %3
br label %30
30: ; preds = %27, %9
%31 = load double, double* %2
%32 = fcmp oeq double %31, 1.000000e+00
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load double, double* %2
%35 = fcmp oeq double %34, -1.000000e+00
br i1 %35, label %36, label %37
36: ; preds = %33, %30
store i64 65, i64* %3
br label %37
37: ; preds = %36, %33
%38 = load double, double* %2
%39 = call double @llvm.fabs.f64(double %38)
%40 = load i64, i64* %3
%41 = sub nsw i64 70, %40
%42 = sitofp i64 %41 to double
%43 = call double @pow(i32 16, double %42)
%44 = call double @llvm.fmuladd.f64(double %39, double %43, double 5.000000e-01)
%45 = fptosi double %44 to i64
%46 = and i64 %45, 16777215
store i64 %46, i64* %4
%47 = load double, double* %2
%48 = fcmp ogt double %47, 0.000000e+00
%49 = zext i1 %48 to i64
%50 = select i1 %48, i32 0, i32 1
%51 = shl i32 %50, 31
%52 = sext i32 %51 to i64
%53 = load i64, i64* %3
%54 = shl i64 %53, 24
%55 = or i64 %52, %54
%56 = load i64, i64* %4
%57 = or i64 %55, %56
store i64 %57, i64* %5
br label %58
58: ; preds = %37, %8
%59 = load i64, i64* %5
ret i64 %59
}

LLVM IR (-O2):
define i64 @grib_local_ibm(double %0) {
%2 = fcmp oeq double %0, 0.000000e+00
br i1 %2, label %34, label %3
3: ; preds = %1
%4 = tail call double @llvm.fabs.f64(double %0)
%5 = fptosi double %4 to i32
%6 = tail call i32 @log10(i32 %5)
%7 = tail call i32 @log10(i32 16)
%8 = sdiv i32 %6, %7
%9 = tail call i32 @ceil(i32 %8)
%10 = add nsw i32 %9, 64
%11 = sext i32 %10 to i64
%12 = tail call i32 @log10(i32 %5)
%13 = tail call i32 @log10(i32 16)
%14 = sdiv i32 %12, %13
%15 = tail call i64 @fmod(i32 %14, i32 1)
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i64
%18 = add nsw i64 %17, %11
%19 = fcmp oeq double %0, 1.000000e+00
%20 = fcmp oeq double %0, -1.000000e+00
%21 = or i1 %19, %20
%22 = select i1 %21, i64 65, i64 %18
%23 = sub nsw i64 70, %22
%24 = sitofp i64 %23 to double
%25 = tail call double @pow(i32 16, double %24)
%26 = tail call double @llvm.fmuladd.f64(double %4, double %25, double 5.000000e-01)
%27 = fptosi double %26 to i64
%28 = and i64 %27, 16777215
%29 = fcmp ule double %0, 0.000000e+00
%30 = select i1 %29, i64 -2147483648, i64 0
%31 = shl nsw i64 %22, 24
%32 = or i64 %28, %30
%33 = or i64 %32, %31
br label %34
34: ; preds = %1, %3
%35 = phi i64 [ %33, %3 ], [ 0, %1 ]
ret i64 %35
}