#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ free(unsigned char *);
unsigned char *mk_BDS(unsigned char *, float *, int);
unsigned char *mk_BMS(unsigned char *, float *, int *, double, double);
int /*<<< orphan*/ wrt_grib_msg(int /*<<< orphan*/ *, unsigned char *,
                                unsigned char *, unsigned char *,
                                unsigned char *);
void wrt_grib_rec(unsigned char *pds, unsigned char *gds, float *data,
                  int ndata, FILE *output) {
  unsigned char *bms, *bds;
  bms = mk_BMS(pds, data, &ndata, 9.9989e20, 9.9991e20);
  if (ndata != 0) {
    bds = mk_BDS(pds, data, ndata);
    wrt_grib_msg(output, pds, gds, bms, bds);
    free(bds);
  }
  if (bms)
    free(bms);
}


x86 assembly (clang, -O0):
<wrt_grib_rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
movsd  0xe91(%rip),%xmm0
movsd  0xe91(%rip),%xmm1
call   1060 <mk_BMS@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11c0 <wrt_grib_rec+0x80>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <mk_BDS@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1040 <wrt_grib_msg@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x30(%rbp)
je     11d4 <wrt_grib_rec+0x94>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrt_grib_rec>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %ecx,0xc(%rsp)
lea    0xc(%rsp),%rdx
movsd  0xe96(%rip),%xmm0
movsd  0xe96(%rip),%xmm1
mov    %r13,%rsi
call   1060 <mk_BMS@plt>
mov    %rax,%r12
mov    0xc(%rsp),%edx
test   %edx,%edx
je     11af <wrt_grib_rec+0x6f>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <mk_BDS@plt>
mov    %rax,%r13
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %rax,%r8
call   1040 <wrt_grib_msg@plt>
mov    %r13,%rdi
call   1030 <free@plt>
test   %r12,%r12
je     11bc <wrt_grib_rec+0x7c>
mov    %r12,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @wrt_grib_rec(i8* %0, i8* %1, float* %2, i32 %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca float*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store float* %2, float** %8
store i32 %3, i32* %9
store i32* %4, i32** %10
%13 = load i8*, i8** %6
%14 = load float*, float** %8
%15 = call i8* @mk_BMS(i8* %13, float* %14, i32* %9, double 0x444B1A2170AD88AA, double 9.999100e+20)
store i8* %15, i8** %11
%16 = load i32, i32* %9
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %5
%19 = load i8*, i8** %6
%20 = load float*, float** %8
%21 = load i32, i32* %9
%22 = call i8* @mk_BDS(i8* %19, float* %20, i32 %21)
store i8* %22, i8** %12
%23 = load i32*, i32** %10
%24 = load i8*, i8** %6
%25 = load i8*, i8** %7
%26 = load i8*, i8** %11
%27 = load i8*, i8** %12
%28 = call i32 @wrt_grib_msg(i32* %23, i8* %24, i8* %25, i8* %26, i8* %27)
%29 = load i8*, i8** %12
%30 = call i32 @free(i8* %29)
br label %31
31: ; preds = %18, %5
%32 = load i8*, i8** %11
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i8*, i8** %11
%36 = call i32 @free(i8* %35)
br label %37
37: ; preds = %34, %31
ret void
}

LLVM IR (-O2):
define void @wrt_grib_rec(i8* %0, i8* %1, float* %2, i32 %3, i32* %4) {
%6 = alloca i32
store i32 %3, i32* %6
%7 = call i8* @mk_BMS(i8* %0, float* %2, i32* %6, double 0x444B1A2170AD88AA, double 9.999100e+20)
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = call i8* @mk_BDS(i8* %0, float* %2, i32 %8)
%12 = call i32 @wrt_grib_msg(i32* %4, i8* %0, i8* %1, i8* %7, i8* %11)
%13 = call i32 @free(i8* %11)
br label %14
14: ; preds = %10, %5
%15 = icmp eq i8* %7, null
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = call i32 @free(i8* %7)
br label %18
18: ; preds = %16, %14
ret void
}