#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 */
long pow(double, int);
double ibm2flt(unsigned char *ibm) {
  int positive;
  long mant;
  double value;
  mant = (ibm[1] << 16) + (ibm[2] << 8) + ibm[3];
  if (mant == 0)
    return 0.0;
  positive = (ibm[0] & 0x80);
  value = pow(16.0, (int)(ibm[0] & 0x7f) - 64) * mant / 16777216.0;
  return (positive) ? -value : value;
}


x86 assembly (clang, -O0):
<ibm2flt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
shl    $0x10,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115c <ibm2flt+0x4c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e4 <ibm2flt+0xd4>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0x80,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
and    $0x7f,%edi
sub    $0x40,%edi
movsd  0xe88(%rip),%xmm0
call   1030 <pow@plt>
imul   -0x20(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  0xe69(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d0 <ibm2flt+0xc0>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11da <ibm2flt+0xca>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ibm2flt>:
push   %rbp
push   %rbx
push   %rax
movzbl 0x1(%rdi),%eax
shl    $0x10,%rax
movzbl 0x2(%rdi),%ecx
shl    $0x8,%rcx
or     %rax,%rcx
movzbl 0x3(%rdi),%ebx
or     %rcx,%rbx
je     116d <ibm2flt+0x5d>
movzbl (%rdi),%ebp
mov    %ebp,%edi
and    $0x7f,%edi
add    $0xffffffc0,%edi
movsd  0xebe(%rip),%xmm0
call   1030 <pow@plt>
imul   %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mulsd  0xead(%rip),%xmm0
test   $0x80,%ebp
je     1171 <ibm2flt+0x61>
xorpd  0xea5(%rip),%xmm0
jmp    1171 <ibm2flt+0x61>
xorpd  %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @ibm2flt(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca double
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = shl i32 %10, 16
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 2
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = shl i32 %15, 8
%17 = add nsw i32 %11, %16
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 3
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = add nsw i32 %17, %21
%23 = sext i32 %22 to i64
store i64 %23, i64* %5
%24 = load i64, i64* %5
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %1
store double 0.000000e+00, double* %2
br label %53
27: ; preds = %1
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = and i32 %31, 128
store i32 %32, i32* %4
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = and i32 %36, 127
%38 = sub nsw i32 %37, 64
%39 = call i64 @pow(double 1.600000e+01, i32 %38)
%40 = load i64, i64* %5
%41 = mul nsw i64 %39, %40
%42 = sitofp i64 %41 to double
%43 = fdiv double %42, 0x4170000000000000
store double %43, double* %6
%44 = load i32, i32* %4
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %27
%47 = load double, double* %6
%48 = fneg double %47
br label %51
49: ; preds = %27
%50 = load double, double* %6
br label %51
51: ; preds = %49, %46
%52 = phi double [ %48, %46 ], [ %50, %49 ]
store double %52, double* %2
br label %53
53: ; preds = %51, %26
%54 = load double, double* %2
ret double %54
}

LLVM IR (-O2):
define double @ibm2flt(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %2
%4 = zext i8 %3 to i64
%5 = shl nuw nsw i64 %4, 16
%6 = getelementptr inbounds i8, i8* %0, i64 2
%7 = load i8, i8* %6
%8 = zext i8 %7 to i64
%9 = shl nuw nsw i64 %8, 8
%10 = or i64 %9, %5
%11 = getelementptr inbounds i8, i8* %0, i64 3
%12 = load i8, i8* %11
%13 = zext i8 %12 to i64
%14 = or i64 %10, %13
%15 = icmp eq i64 %14, 0
br i1 %15, label %29, label %16
16: ; preds = %1
%17 = load i8, i8* %0
%18 = zext i8 %17 to i32
%19 = and i32 %18, 128
%20 = and i32 %18, 127
%21 = add nsw i32 %20, -64
%22 = tail call i64 @pow(double 1.600000e+01, i32 %21)
%23 = mul nsw i64 %22, %14
%24 = sitofp i64 %23 to double
%25 = fmul double %24, 0x3E70000000000000
%26 = icmp eq i32 %19, 0
%27 = fneg double %25
%28 = select i1 %26, double %25, double %27
br label %29
29: ; preds = %1, %16
%30 = phi double [ %28, %16 ], [ 0.000000e+00, %1 ]
ret double %30
}