#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 */
typedef int /*<<< orphan*/ *bms;

/* Variables and functions */
int /*<<< orphan*/ BDS_unpack(float *, unsigned char *, int /*<<< orphan*/ *,
                              int, int, double, double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int get_nxny(unsigned char *, unsigned char *, unsigned char *,
             unsigned char *);
double ibm2flt(unsigned char *);
double int_power(double, int);
int /*<<< orphan*/ stderr;
int unpk_bds(float *array, unsigned char *pds, unsigned char *gds,
             unsigned char *bms, unsigned char *bds, int array_size) {
  int nxny;
  double temp;
  nxny = get_nxny(pds, gds, bms, bds);
  if (array_size < nxny) {
    fprintf(stderr, "array_size too small .. %d %d\n", array_size, nxny);
    return -1;
  }
  temp = int_power(10.0, -((1 - (int)((unsigned)(pds[26] & 0x80) >> 6)) *
                           (int)(((pds[26] & 0x7f) << 8) + pds[27])));
  BDS_unpack(array, bds + 11, ((bms) == NULL ? NULL : (bms) + 6),
             ((int)bds[10]), nxny, temp * (ibm2flt(bds + 6)),
             temp *
                 int_power(2.0, ((1 - (int)((unsigned)(bds[4] & 0x80) >> 6)) *
                                 (int)(((bds[4] & 0x7f) << 8) + bds[5]))));
  return nxny;
}


x86 assembly (clang, -O0):
<unpk_bds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1070 <get_nxny@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    11be <unpk_bds+0x6e>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
lea    0xe63(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f6 <unpk_bds+0x1a6>
mov    -0x18(%rbp),%rax
movzbl 0x1a(%rax),%ecx
and    $0x80,%ecx
shr    $0x6,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
mov    -0x18(%rbp),%rcx
movzbl 0x1a(%rcx),%ecx
and    $0x7f,%ecx
shl    $0x8,%ecx
mov    -0x18(%rbp),%rdx
movzbl 0x1b(%rdx),%edx
add    %edx,%ecx
imul   %ecx,%eax
xor    %edi,%edi
sub    %eax,%edi
movsd  0xe03(%rip),%xmm0
call   1060 <int_power@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
add    $0xb,%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1231 <unpk_bds+0xe1>
xor    %eax,%eax
mov    %rax,-0x58(%rbp)
jmp    123d <unpk_bds+0xed>
mov    -0x28(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x30(%rbp),%rax
movzbl 0xa(%rax),%eax
mov    %eax,-0x68(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x64(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x6,%rdi
call   1050 <ibm2flt@plt>
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x30(%rbp),%rax
movzbl 0x4(%rax),%eax
and    $0x80,%eax
shr    $0x6,%eax
mov    $0x1,%edi
sub    %eax,%edi
mov    -0x30(%rbp),%rax
movzbl 0x4(%rax),%eax
and    $0x7f,%eax
shl    $0x8,%eax
mov    -0x30(%rbp),%rcx
movzbl 0x5(%rcx),%ecx
add    %ecx,%eax
imul   %eax,%edi
movsd  0xd46(%rip),%xmm0
call   1060 <int_power@plt>
movsd  -0x78(%rbp),%xmm1
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x68(%rbp),%ecx
mov    -0x64(%rbp),%r8d
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm2,%xmm1
call   1040 <BDS_unpack@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpk_bds>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r12d
mov    %r8,%r14
mov    %rcx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r13
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
call   1070 <get_nxny@plt>
mov    %eax,%r15d
cmp    %r12d,%eax
jle    11ac <unpk_bds+0x5c>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1030 <fprintf@plt>
mov    $0xffffffff,%r15d
jmp    125c <unpk_bds+0x10c>
movzbl 0x1a(%rbx),%eax
mov    %eax,%ecx
shr    $0x7,%ecx
add    %ecx,%ecx
add    $0xffffffff,%ecx
and    $0x7f,%eax
shl    $0x8,%eax
movzbl 0x1b(%rbx),%edi
or     %eax,%edi
imul   %ecx,%edi
movsd  0xe2f(%rip),%xmm0
call   1060 <int_power@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xb(%r14),%r12
mov    %r13,%rbx
lea    0x6(%rbp),%r13
test   %rbp,%rbp
cmove  %rbp,%r13
movzbl 0xa(%r14),%ebp
lea    0x6(%r14),%rdi
call   1050 <ibm2flt@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movzbl 0x4(%r14),%eax
mov    %eax,%ecx
shr    $0x6,%ecx
and    $0xfffffffe,%ecx
mov    $0x1,%edx
sub    %ecx,%edx
and    $0x7f,%eax
shl    $0x8,%eax
movzbl 0x5(%r14),%edi
or     %eax,%edi
imul   %edx,%edi
movsd  0xdd4(%rip),%xmm0
call   1060 <int_power@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %ebp,%ecx
mov    %r15d,%r8d
movsd  0x10(%rsp),%xmm0
call   1040 <BDS_unpack@plt>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"array_size too small .. %d %d\0A\00"
define i32 @unpk_bds(float* %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5) {
%7 = alloca i32
%8 = alloca float*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
store float* %0, float** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i32 %5, i32* %13
%16 = load i8*, i8** %9
%17 = load i8*, i8** %10
%18 = load i8*, i8** %11
%19 = load i8*, i8** %12
%20 = call i32 @get_nxny(i8* %16, i8* %17, i8* %18, i8* %19)
store i32 %20, i32* %14
%21 = load i32, i32* %13
%22 = load i32, i32* %14
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %29
24: ; preds = %6
%25 = load i32, i32* @stderr
%26 = load i32, i32* %13
%27 = load i32, i32* %14
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %27)
store i32 -1, i32* %7
br label %97
29: ; preds = %6
%30 = load i8*, i8** %9
%31 = getelementptr inbounds i8, i8* %30, i64 26
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = and i32 %33, 128
%35 = lshr i32 %34, 6
%36 = sub nsw i32 1, %35
%37 = load i8*, i8** %9
%38 = getelementptr inbounds i8, i8* %37, i64 26
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = and i32 %40, 127
%42 = shl i32 %41, 8
%43 = load i8*, i8** %9
%44 = getelementptr inbounds i8, i8* %43, i64 27
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = add nsw i32 %42, %46
%48 = mul nsw i32 %36, %47
%49 = sub nsw i32 0, %48
%50 = call double @int_power(double 1.000000e+01, i32 %49)
store double %50, double* %15
%51 = load float*, float** %8
%52 = load i8*, i8** %12
%53 = getelementptr inbounds i8, i8* %52, i64 11
%54 = load i8*, i8** %11
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %57
56: ; preds = %29
br label %60
57: ; preds = %29
%58 = load i8*, i8** %11
%59 = getelementptr inbounds i8, i8* %58, i64 6
br label %60
60: ; preds = %57, %56
%61 = phi i8* [ null, %56 ], [ %59, %57 ]
%62 = bitcast i8* %61 to i32*
%63 = load i8*, i8** %12
%64 = getelementptr inbounds i8, i8* %63, i64 10
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = load i32, i32* %14
%68 = load double, double* %15
%69 = load i8*, i8** %12
%70 = getelementptr inbounds i8, i8* %69, i64 6
%71 = call double @ibm2flt(i8* %70)
%72 = fmul double %68, %71
%73 = load double, double* %15
%74 = load i8*, i8** %12
%75 = getelementptr inbounds i8, i8* %74, i64 4
%76 = load i8, i8* %75
%77 = zext i8 %76 to i32
%78 = and i32 %77, 128
%79 = lshr i32 %78, 6
%80 = sub nsw i32 1, %79
%81 = load i8*, i8** %12
%82 = getelementptr inbounds i8, i8* %81, i64 4
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = and i32 %84, 127
%86 = shl i32 %85, 8
%87 = load i8*, i8** %12
%88 = getelementptr inbounds i8, i8* %87, i64 5
%89 = load i8, i8* %88
%90 = zext i8 %89 to i32
%91 = add nsw i32 %86, %90
%92 = mul nsw i32 %80, %91
%93 = call double @int_power(double 2.000000e+00, i32 %92)
%94 = fmul double %73, %93
%95 = call i32 @BDS_unpack(float* %51, i8* %53, i32* %62, i32 %66, i32 %67, double %72, double %94)
%96 = load i32, i32* %14
store i32 %96, i32* %7
br label %97
97: ; preds = %60, %24
%98 = load i32, i32* %7
ret i32 %98
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"array_size too small .. %d %d\0A\00"
define i32 @unpk_bds(float* %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5) {
%7 = tail call i32 @get_nxny(i8* %1, i8* %2, i8* %3, i8* %4)
%8 = icmp sgt i32 %7, %5
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %7)
br label %54
12: ; preds = %6
%13 = getelementptr inbounds i8, i8* %1, i64 26
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = lshr i32 %15, 6
%17 = and i32 %16, 2
%18 = add nsw i32 %17, -1
%19 = shl nuw nsw i32 %15, 8
%20 = and i32 %19, 32512
%21 = getelementptr inbounds i8, i8* %1, i64 27
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = or i32 %20, %23
%25 = mul nsw i32 %18, %24
%26 = tail call double @int_power(double 1.000000e+01, i32 %25)
%27 = getelementptr inbounds i8, i8* %4, i64 11
%28 = icmp eq i8* %3, null
%29 = getelementptr inbounds i8, i8* %3, i64 6
%30 = select i1 %28, i8* null, i8* %29
%31 = bitcast i8* %30 to i32*
%32 = getelementptr inbounds i8, i8* %4, i64 10
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = getelementptr inbounds i8, i8* %4, i64 6
%36 = tail call double @ibm2flt(i8* %35)
%37 = fmul double %26, %36
%38 = getelementptr inbounds i8, i8* %4, i64 4
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = lshr i32 %40, 6
%42 = and i32 %41, 2
%43 = sub nsw i32 1, %42
%44 = shl nuw nsw i32 %40, 8
%45 = and i32 %44, 32512
%46 = getelementptr inbounds i8, i8* %4, i64 5
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = or i32 %45, %48
%50 = mul nsw i32 %43, %49
%51 = tail call double @int_power(double 2.000000e+00, i32 %50)
%52 = fmul double %26, %51
%53 = tail call i32 @BDS_unpack(float* %0, i8* %27, i32* %31, i32 %34, i32 %7, double %37, double %52)
br label %54
54: ; preds = %12, %9
%55 = phi i32 [ -1, %9 ], [ %7, %12 ]
ret i32 %55
}