#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 floor(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
double frexp(double, int *);
int /*<<< orphan*/ stderr;
int flt2ibm(float x, unsigned char *ibm) {
  int sign, exp;
  double mant;
  int imant;
  if (x == 0.0) {
    ibm[0] = ibm[1] = ibm[2] = ibm[3] = 0;
    return 0;
  }
  if (x < 0.0) {
    sign = 128;
    x = -x;
  } else
    sign = 0;
  mant = frexp((double)x, &exp);
  if (mant >= 1.0) {
    mant = 0.5;
    exp++;
  }
  while (exp & 3) {
    mant *= 0.5;
    exp++;
  }
  imant = floor(mant * 256.0 * 256.0 * 256.0 + 0.5);
  if (imant >= 256 * 256 * 256) {
    imant = floor(mant * 16.0 * 256.0 * 256.0 + 0.5);
    exp -= 4;
  }
  exp = exp / 4 + 64;
  if (exp < 0) {
    fprintf(stderr, "underflow in flt2ibm\n");
    ibm[0] = ibm[1] = ibm[2] = ibm[3] = 0;
    return 0;
  }
  if (exp > 127) {
    fprintf(stderr, "overflow in flt2ibm\n");
    ibm[0] = sign | 127;
    ibm[1] = ibm[2] = ibm[3] = 255;
    return -1;
  }
  ibm[0] = sign | exp;
  ibm[3] = imant & 255;
  ibm[2] = (imant >> 8) & 255;
  ibm[1] = (imant >> 16) & 255;
  return 0;
}


x86 assembly (clang, -O0):
<flt2ibm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1188 <flt2ibm+0x58>
jp     1188 <flt2ibm+0x58>
mov    -0x10(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    13c2 <flt2ibm+0x292>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11c1 <flt2ibm+0x91>
movl   $0x80,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11c8 <flt2ibm+0x98>
movl   $0x0,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    -0x18(%rbp),%rdi
call   1030 <frexp@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe14(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     120c <flt2ibm+0xdc>
movsd  0xe0a(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1211 <flt2ibm+0xe1>
mov    -0x18(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
je     1240 <flt2ibm+0x110>
movsd  0xde0(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1211 <flt2ibm+0xe1>
movsd  0xdc8(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  0xdbb(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdaf(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd9b(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <floor@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1000000,-0x24(%rbp)
jl     12c8 <flt2ibm+0x198>
movsd  0xd8a(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  0xd75(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd69(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd55(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <floor@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
add    $0x40,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1323 <flt2ibm+0x1f3>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0xd2d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    13c2 <flt2ibm+0x292>
cmpl   $0x7f,-0x18(%rbp)
jle    1374 <flt2ibm+0x244>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
lea    0xcf9(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
or     $0x7f,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movb   $0xff,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0xff,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0xff,0x1(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    13c2 <flt2ibm+0x292>
mov    -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x24(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x24(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flt2ibm>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1152 <flt2ibm+0x22>
jp     1152 <flt2ibm+0x22>
movl   $0x0,(%rbx)
jmp    12c9 <flt2ibm+0x199>
xor    %r15d,%r15d
ucomiss %xmm0,%xmm1
seta   %r14b
jbe    1165 <flt2ibm+0x35>
xorps  0xe9b(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xc(%rsp),%rdi
call   1030 <frexp@plt>
movsd  0xe95(%rip),%xmm2
ucomisd %xmm2,%xmm0
mov    0xc(%rsp),%ebp
sbb    $0xffffffff,%ebp
cmpnlesd %xmm0,%xmm2
andpd  %xmm2,%xmm0
movsd  0xe81(%rip),%xmm1
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
test   $0x3,%bpl
je     11e1 <flt2ibm+0xb1>
mulsd  0xe6b(%rip),%xmm2
lea    0x1(%rbp),%eax
test   $0x3,%al
je     11df <flt2ibm+0xaf>
mulsd  0xe5c(%rip),%xmm2
lea    0x2(%rbp),%eax
test   $0x3,%al
je     11df <flt2ibm+0xaf>
mulsd  0xe4d(%rip),%xmm2
lea    0x3(%rbp),%eax
test   $0x3,%al
je     11df <flt2ibm+0xaf>
mulsd  0xe3e(%rip),%xmm2
add    $0x4,%ebp
jmp    11e1 <flt2ibm+0xb1>
mov    %eax,%ebp
movapd %xmm2,0x10(%rsp)
movsd  0xe31(%rip),%xmm1
movapd %xmm2,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe11(%rip),%xmm0
call   1050 <floor@plt>
cmp    $0x1000000,%eax
jl     1249 <flt2ibm+0x119>
movapd 0x10(%rsp),%xmm1
mulsd  0xe07(%rip),%xmm1
movsd  0xdf7(%rip),%xmm0
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
addsd  0xddf(%rip),%xmm1
movapd %xmm1,%xmm0
call   1050 <floor@plt>
add    $0xfffffffc,%ebp
mov    %ebp,0xc(%rsp)
lea    0x3(%rbp),%ecx
test   %ebp,%ebp
cmovns %ebp,%ecx
cmp    $0xfffffefc,%ebp
jg     1276 <flt2ibm+0x146>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,(%rbx)
jmp    12c9 <flt2ibm+0x199>
mov    %r14b,%r15b
shl    $0x7,%r15d
cmp    $0x100,%ebp
jl     12b2 <flt2ibm+0x182>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
call   1040 <fprintf@plt>
or     $0x7f,%r15b
mov    %r15b,(%rbx)
movb   $0xff,0x3(%rbx)
movw   $0xffff,0x1(%rbx)
mov    $0xffffffff,%eax
jmp    12cb <flt2ibm+0x19b>
sar    $0x2,%ecx
add    $0x40,%ecx
or     %r15d,%ecx
mov    %cl,(%rbx)
mov    %al,0x3(%rbx)
mov    %ah,0x2(%rbx)
shr    $0x10,%eax
mov    %al,0x1(%rbx)
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"underflow in flt2ibm\0A\00"
@.str.1 = [21 x i8] c"overflow in flt2ibm\0A\00"
define i32 @flt2ibm(float %0, i8* %1) {
%3 = alloca i32
%4 = alloca float
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
store float %0, float* %4
store i8* %1, i8** %5
%10 = load float, float* %4
%11 = fpext float %10 to double
%12 = fcmp oeq double %11, 0.000000e+00
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 3
store i8 0, i8* %15
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 2
store i8 0, i8* %17
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8 0, i8* %19
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 0, i8* %21
store i32 0, i32* %3
br label %123
22: ; preds = %2
%23 = load float, float* %4
%24 = fpext float %23 to double
%25 = fcmp olt double %24, 0.000000e+00
br i1 %25, label %26, label %29
26: ; preds = %22
store i32 128, i32* %6
%27 = load float, float* %4
%28 = fneg float %27
store float %28, float* %4
br label %30
29: ; preds = %22
store i32 0, i32* %6
br label %30
30: ; preds = %29, %26
%31 = load float, float* %4
%32 = fpext float %31 to double
%33 = call double @frexp(double %32, i32* %7)
store double %33, double* %8
%34 = load double, double* %8
%35 = fcmp oge double %34, 1.000000e+00
br i1 %35, label %36, label %39
36: ; preds = %30
store double 5.000000e-01, double* %8
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %39
39: ; preds = %36, %30
br label %40
40: ; preds = %44, %39
%41 = load i32, i32* %7
%42 = and i32 %41, 3
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %40
%45 = load double, double* %8
%46 = fmul double %45, 5.000000e-01
store double %46, double* %8
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %40
49: ; preds = %40
%50 = load double, double* %8
%51 = fmul double %50, 2.560000e+02
%52 = fmul double %51, 2.560000e+02
%53 = call double @llvm.fmuladd.f64(double %52, double 2.560000e+02, double 5.000000e-01)
%54 = call i32 @floor(double %53)
store i32 %54, i32* %9
%55 = load i32, i32* %9
%56 = icmp sge i32 %55, 16777216
br i1 %56, label %57, label %65
57: ; preds = %49
%58 = load double, double* %8
%59 = fmul double %58, 1.600000e+01
%60 = fmul double %59, 2.560000e+02
%61 = call double @llvm.fmuladd.f64(double %60, double 2.560000e+02, double 5.000000e-01)
%62 = call i32 @floor(double %61)
store i32 %62, i32* %9
%63 = load i32, i32* %7
%64 = sub nsw i32 %63, 4
store i32 %64, i32* %7
br label %65
65: ; preds = %57, %49
%66 = load i32, i32* %7
%67 = sdiv i32 %66, 4
%68 = add nsw i32 %67, 64
store i32 %68, i32* %7
%69 = load i32, i32* %7
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %82
71: ; preds = %65
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%74 = load i8*, i8** %5
%75 = getelementptr inbounds i8, i8* %74, i64 3
store i8 0, i8* %75
%76 = load i8*, i8** %5
%77 = getelementptr inbounds i8, i8* %76, i64 2
store i8 0, i8* %77
%78 = load i8*, i8** %5
%79 = getelementptr inbounds i8, i8* %78, i64 1
store i8 0, i8* %79
%80 = load i8*, i8** %5
%81 = getelementptr inbounds i8, i8* %80, i64 0
store i8 0, i8* %81
store i32 0, i32* %3
br label %123
82: ; preds = %65
%83 = load i32, i32* %7
%84 = icmp sgt i32 %83, 127
br i1 %84, label %85, label %99
85: ; preds = %82
%86 = load i32, i32* @stderr
%87 = call i32 @fprintf(i32 %86, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%88 = load i32, i32* %6
%89 = or i32 %88, 127
%90 = trunc i32 %89 to i8
%91 = load i8*, i8** %5
%92 = getelementptr inbounds i8, i8* %91, i64 0
store i8 %90, i8* %92
%93 = load i8*, i8** %5
%94 = getelementptr inbounds i8, i8* %93, i64 3
store i8 -1, i8* %94
%95 = load i8*, i8** %5
%96 = getelementptr inbounds i8, i8* %95, i64 2
store i8 -1, i8* %96
%97 = load i8*, i8** %5
%98 = getelementptr inbounds i8, i8* %97, i64 1
store i8 -1, i8* %98
store i32 -1, i32* %3
br label %123
99: ; preds = %82
%100 = load i32, i32* %6
%101 = load i32, i32* %7
%102 = or i32 %100, %101
%103 = trunc i32 %102 to i8
%104 = load i8*, i8** %5
%105 = getelementptr inbounds i8, i8* %104, i64 0
store i8 %103, i8* %105
%106 = load i32, i32* %9
%107 = and i32 %106, 255
%108 = trunc i32 %107 to i8
%109 = load i8*, i8** %5
%110 = getelementptr inbounds i8, i8* %109, i64 3
store i8 %108, i8* %110
%111 = load i32, i32* %9
%112 = ashr i32 %111, 8
%113 = and i32 %112, 255
%114 = trunc i32 %113 to i8
%115 = load i8*, i8** %5
%116 = getelementptr inbounds i8, i8* %115, i64 2
store i8 %114, i8* %116
%117 = load i32, i32* %9
%118 = ashr i32 %117, 16
%119 = and i32 %118, 255
%120 = trunc i32 %119 to i8
%121 = load i8*, i8** %5
%122 = getelementptr inbounds i8, i8* %121, i64 1
store i8 %120, i8* %122
store i32 0, i32* %3
br label %123
123: ; preds = %99, %85, %71, %13
%124 = load i32, i32* %3
ret i32 %124
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"underflow in flt2ibm\0A\00"
@.str.1 = [21 x i8] c"overflow in flt2ibm\0A\00"
define i32 @flt2ibm(float %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = fcmp oeq float %0, 0.000000e+00
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = bitcast i8* %1 to i32*
store i32 0, i32* %7
br label %86
8: ; preds = %2
%9 = fcmp olt float %0, 0.000000e+00
%10 = fneg float %0
%11 = select i1 %9, float %10, float %0
%12 = select i1 %9, i32 128, i32 0
%13 = fpext float %11 to double
%14 = call double @frexp(double %13, i32* %3)
%15 = fcmp ult double %14, 1.000000e+00
%16 = load i32, i32* %3
%17 = xor i1 %15, true
%18 = zext i1 %17 to i32
%19 = add nsw i32 %16, %18
%20 = select i1 %15, double %14, double 5.000000e-01
%21 = and i32 %19, 3
%22 = icmp eq i32 %21, 0
br i1 %22, label %41, label %23
23: ; preds = %8
%24 = fmul double %20, 5.000000e-01
%25 = add nsw i32 %19, 1
%26 = and i32 %25, 3
%27 = icmp eq i32 %26, 0
br i1 %27, label %41, label %28
28: ; preds = %23
%29 = fmul double %24, 5.000000e-01
%30 = add nsw i32 %19, 2
%31 = and i32 %30, 3
%32 = icmp eq i32 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %28
%34 = fmul double %29, 5.000000e-01
%35 = add nsw i32 %19, 3
%36 = and i32 %35, 3
%37 = icmp eq i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %33
%39 = fmul double %34, 5.000000e-01
%40 = add nsw i32 %19, 4
br label %41
41: ; preds = %23, %28, %33, %38, %8
%42 = phi i32 [ %19, %8 ], [ %25, %23 ], [ %30, %28 ], [ %35, %33 ], [ %40, %38 ]
%43 = phi double [ %20, %8 ], [ %24, %23 ], [ %29, %28 ], [ %34, %33 ], [ %39, %38 ]
%44 = fmul double %43, 2.560000e+02
%45 = fmul double %44, 2.560000e+02
%46 = tail call double @llvm.fmuladd.f64(double %45, double 2.560000e+02, double 5.000000e-01)
%47 = tail call i32 @floor(double %46)
%48 = icmp sgt i32 %47, 16777215
br i1 %48, label %49, label %55
49: ; preds = %41
%50 = fmul double %43, 1.600000e+01
%51 = fmul double %50, 2.560000e+02
%52 = tail call double @llvm.fmuladd.f64(double %51, double 2.560000e+02, double 5.000000e-01)
%53 = tail call i32 @floor(double %52)
%54 = add nsw i32 %42, -4
store i32 %54, i32* %3
br label %55
55: ; preds = %41, %49
%56 = phi i32 [ %54, %49 ], [ %42, %41 ]
%57 = phi i32 [ %53, %49 ], [ %47, %41 ]
%58 = sdiv i32 %56, 4
%59 = add nsw i32 %58, 64
%60 = icmp slt i32 %56, -259
br i1 %60, label %61, label %65
61: ; preds = %55
%62 = load i32, i32* @stderr
%63 = tail call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%64 = bitcast i8* %1 to i32*
store i32 0, i32* %64
br label %86
65: ; preds = %55
%66 = icmp sgt i32 %56, 255
br i1 %66, label %67, label %75
67: ; preds = %65
%68 = load i32, i32* @stderr
%69 = tail call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%70 = trunc i32 %12 to i8
%71 = or i8 %70, 127
store i8 %71, i8* %1
%72 = getelementptr inbounds i8, i8* %1, i64 3
store i8 -1, i8* %72
%73 = getelementptr inbounds i8, i8* %1, i64 2
store i8 -1, i8* %73
%74 = getelementptr inbounds i8, i8* %1, i64 1
store i8 -1, i8* %74
br label %86
75: ; preds = %65
%76 = or i32 %59, %12
%77 = trunc i32 %76 to i8
store i8 %77, i8* %1
%78 = trunc i32 %57 to i8
%79 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %78, i8* %79
%80 = lshr i32 %57, 8
%81 = trunc i32 %80 to i8
%82 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %81, i8* %82
%83 = lshr i32 %57, 16
%84 = trunc i32 %83 to i8
%85 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %84, i8* %85
br label %86
86: ; preds = %75, %67, %61, %6
%87 = phi i32 [ 0, %6 ], [ 0, %61 ], [ -1, %67 ], [ 0, %75 ]
ret i32 %87
}