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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int grb2_get_data(float *, long long);
int grb2_get_gridmeta(char *, int);
int grb2_get_lonlat(float *, float *, long long);
int grb2_get_meta(char *, int);
long long grb2_inqVA(char *, char *, int, char *, char *, char *,
                     int /*<<< orphan*/ *);
int grb2_mk_inv(char *, char *);
scalar_t__ malloc(long long);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  long long int ndata;
  int ierr;
  float *data, *lat, *lon;
  char meta[200], gridmeta[1000];
  ierr = grb2_mk_inv("merc.g2", "merc.inv");
  if (ierr)
    exit(1);
  ndata = grb2_inqVA("merc.g2", "merc.inv", 2 | 4 | 32 | 64,
                     ":TMP:", ":d=2014050600:", ":surface:", NULL);
  if (ndata <= 0)
    exit(2);
  data = (float *)malloc(ndata * sizeof(float));
  lat = (float *)malloc(ndata * sizeof(float));
  lon = (float *)malloc(ndata * sizeof(float));
  if (data == NULL | lat == NULL || lon == NULL)
    exit(3);
  ierr = grb2_get_data(data, ndata);
  if (ierr)
    exit(4);
  ierr = grb2_get_lonlat(lon, lat, ndata);
  if (ierr)
    exit(5);
  ierr = grb2_get_meta(meta, sizeof(meta));
  if (ierr)
    exit(6);
  ierr = grb2_get_gridmeta(gridmeta, sizeof(gridmeta));
  if (ierr)
    exit(7);
  printf("That was easy: data[0[=%lf, lon[0]=%lf lat[0]=%lf ndata=%d\n",
         data[0], lon[0], lat[0], ndata);
  printf("meta=%s\n", meta);
  printf("gridmeta=%s\n", gridmeta);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x500,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
lea    0xe58(%rip),%rsi
call   1040 <grb2_mk_inv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11cc <main+0x3c>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe2d(%rip),%rdi
lea    0xe2e(%rip),%rsi
mov    $0x66,%edx
lea    0xe2b(%rip),%rcx
lea    0xe2a(%rip),%r8
lea    0xe32(%rip),%r9
xor    %eax,%eax
movq   $0x0,(%rsp)
call   1030 <grb2_inqVA@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jg     121c <main+0x8c>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rdi
shl    $0x2,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x2,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x2,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmpq   $0x0,-0x28(%rbp)
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
jne    1280 <main+0xf0>
cmpq   $0x0,-0x30(%rbp)
jne    128a <main+0xfa>
mov    $0x3,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <grb2_get_data@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12ae <main+0x11e>
mov    $0x4,%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <grb2_get_lonlat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12d6 <main+0x146>
mov    $0x5,%edi
call   10b0 <exit@plt>
lea    -0x100(%rbp),%rdi
mov    $0xc8,%esi
call   1090 <grb2_get_meta@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12fe <main+0x16e>
mov    $0x6,%edi
call   10b0 <exit@plt>
lea    -0x4f0(%rbp),%rdi
mov    $0x3e8,%esi
call   10a0 <grb2_get_gridmeta@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1326 <main+0x196>
mov    $0x7,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x30(%rbp),%rax
movss  (%rax),%xmm1
cvtss2sd %xmm1,%xmm1
mov    -0x28(%rbp),%rax
movss  (%rax),%xmm2
cvtss2sd %xmm2,%xmm2
mov    -0x10(%rbp),%rsi
lea    0xcdb(%rip),%rdi
mov    $0x3,%al
call   1050 <printf@plt>
lea    -0x100(%rbp),%rsi
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x4f0(%rbp),%rsi
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4d0,%rsp
lea    0xe59(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1040 <grb2_mk_inv@plt>
test   %eax,%eax
jne    11fb <main+0x6b>
movq   $0x0,(%rsp)
lea    0xe3a(%rip),%rdi
lea    0xe3b(%rip),%rsi
lea    0xe3d(%rip),%rcx
lea    0xe3c(%rip),%r8
lea    0xe44(%rip),%r9
mov    $0x66,%edx
call   1030 <grb2_inqVA@plt>
test   %rax,%rax
jg     1205 <main+0x75>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rax,%r13
lea    0x0(,%rax,4),%rbx
mov    %rbx,%rdi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1080 <malloc@plt>
test   %r14,%r14
je     1303 <main+0x173>
test   %r15,%r15
je     1303 <main+0x173>
mov    %rax,%r12
test   %rax,%rax
je     1303 <main+0x173>
mov    %r14,%rdi
mov    %r13,%rsi
call   1070 <grb2_get_data@plt>
test   %eax,%eax
jne    130d <main+0x17d>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1060 <grb2_get_lonlat@plt>
test   %eax,%eax
jne    1317 <main+0x187>
lea    0x10(%rsp),%rdi
mov    $0xc8,%esi
call   1090 <grb2_get_meta@plt>
test   %eax,%eax
jne    1321 <main+0x191>
lea    0xe0(%rsp),%rdi
mov    $0x3e8,%esi
call   10a0 <grb2_get_gridmeta@plt>
test   %eax,%eax
jne    132b <main+0x19b>
movss  (%r14),%xmm0
cvtss2sd %xmm0,%xmm0
movss  (%r12),%xmm1
cvtss2sd %xmm1,%xmm1
movss  (%r15),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xd67(%rip),%rdi
mov    %r13,%rsi
mov    $0x3,%al
call   1050 <printf@plt>
lea    0xd96(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd7f(%rip),%rdi
lea    0xe0(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
mov    $0x6,%edi
call   10b0 <exit@plt>
mov    $0x7,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"merc.g2\00"
@.str.1 = [9 x i8] c"merc.inv\00"
@.str.2 = [6 x i8] c":TMP:\00"
@.str.3 = [15 x i8] c":d=2014050600:\00"
@.str.4 = [10 x i8] c":surface:\00"
@.str.5 = [60 x i8] c"That was easy: data[0[=%lf, lon[0]=%lf lat[0]=%lf ndata=%d\0A\00"
@.str.6 = [9 x i8] c"meta=%s\0A\00"
@.str.7 = [13 x i8] c"gridmeta=%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca float*
%5 = alloca float*
%6 = alloca float*
%7 = alloca [200 x i8]
%8 = alloca [1000 x i8]
store i32 0, i32* %1
%9 = call i32 @grb2_mk_inv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i64 @grb2_inqVA(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 102, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32* null)
store i64 %15, i64* %2
%16 = load i64, i64* %2
%17 = icmp sle i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @exit(i32 2)
unreachable
20: ; preds = %14
%21 = load i64, i64* %2
%22 = mul i64 %21, 4
%23 = call i64 @malloc(i64 %22)
%24 = inttoptr i64 %23 to float*
store float* %24, float** %4
%25 = load i64, i64* %2
%26 = mul i64 %25, 4
%27 = call i64 @malloc(i64 %26)
%28 = inttoptr i64 %27 to float*
store float* %28, float** %5
%29 = load i64, i64* %2
%30 = mul i64 %29, 4
%31 = call i64 @malloc(i64 %30)
%32 = inttoptr i64 %31 to float*
store float* %32, float** %6
%33 = load float*, float** %4
%34 = icmp eq float* %33, null
%35 = zext i1 %34 to i32
%36 = load float*, float** %5
%37 = icmp eq float* %36, null
%38 = zext i1 %37 to i32
%39 = or i32 %35, %38
%40 = icmp ne i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %20
%42 = load float*, float** %6
%43 = icmp eq float* %42, null
br i1 %43, label %44, label %46
44: ; preds = %41, %20
%45 = call i32 @exit(i32 3)
unreachable
46: ; preds = %41
%47 = load float*, float** %4
%48 = load i64, i64* %2
%49 = call i32 @grb2_get_data(float* %47, i64 %48)
store i32 %49, i32* %3
%50 = load i32, i32* %3
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = call i32 @exit(i32 4)
unreachable
54: ; preds = %46
%55 = load float*, float** %6
%56 = load float*, float** %5
%57 = load i64, i64* %2
%58 = call i32 @grb2_get_lonlat(float* %55, float* %56, i64 %57)
store i32 %58, i32* %3
%59 = load i32, i32* %3
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %54
%62 = call i32 @exit(i32 5)
unreachable
63: ; preds = %54
%64 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%65 = call i32 @grb2_get_meta(i8* %64, i32 200)
store i32 %65, i32* %3
%66 = load i32, i32* %3
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %63
%69 = call i32 @exit(i32 6)
unreachable
70: ; preds = %63
%71 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%72 = call i32 @grb2_get_gridmeta(i8* %71, i32 1000)
store i32 %72, i32* %3
%73 = load i32, i32* %3
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %70
%76 = call i32 @exit(i32 7)
unreachable
77: ; preds = %70
%78 = load float*, float** %4
%79 = getelementptr inbounds float, float* %78, i64 0
%80 = load float, float* %79
%81 = fpext float %80 to double
%82 = load float*, float** %6
%83 = getelementptr inbounds float, float* %82, i64 0
%84 = load float, float* %83
%85 = fpext float %84 to double
%86 = load float*, float** %5
%87 = getelementptr inbounds float, float* %86, i64 0
%88 = load float, float* %87
%89 = fpext float %88 to double
%90 = load i64, i64* %2
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), double %81, double %85, double %89, i64 %90)
%92 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %92)
%94 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %94)
%96 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"merc.g2\00"
@.str.1 = [9 x i8] c"merc.inv\00"
@.str.2 = [6 x i8] c":TMP:\00"
@.str.3 = [15 x i8] c":d=2014050600:\00"
@.str.4 = [10 x i8] c":surface:\00"
@.str.5 = [60 x i8] c"That was easy: data[0[=%lf, lon[0]=%lf lat[0]=%lf ndata=%d\0A\00"
@.str.6 = [9 x i8] c"meta=%s\0A\00"
@.str.7 = [13 x i8] c"gridmeta=%s\0A\00"
define i32 @main() {
%1 = alloca [200 x i8]
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @grb2_mk_inv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = tail call i64 @grb2_inqVA(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 102, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32* null)
%11 = icmp slt i64 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @exit(i32 2)
unreachable
14: ; preds = %9
%15 = shl i64 %10, 2
%16 = tail call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to float*
%18 = tail call i64 @malloc(i64 %15)
%19 = inttoptr i64 %18 to float*
%20 = tail call i64 @malloc(i64 %15)
%21 = inttoptr i64 %20 to float*
%22 = icmp eq i64 %16, 0
%23 = icmp eq i64 %18, 0
%24 = or i1 %22, %23
%25 = icmp eq i64 %20, 0
%26 = select i1 %24, i1 true, i1 %25
br i1 %26, label %27, label %29
27: ; preds = %14
%28 = tail call i32 @exit(i32 3)
unreachable
29: ; preds = %14
%30 = tail call i32 @grb2_get_data(float* %17, i64 %10)
%31 = icmp eq i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = tail call i32 @exit(i32 4)
unreachable
34: ; preds = %29
%35 = tail call i32 @grb2_get_lonlat(float* %21, float* %19, i64 %10)
%36 = icmp eq i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = tail call i32 @exit(i32 5)
unreachable
39: ; preds = %34
%40 = call i32 @grb2_get_meta(i8* %3, i32 200)
%41 = icmp eq i32 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %39
%43 = call i32 @exit(i32 6)
unreachable
44: ; preds = %39
%45 = call i32 @grb2_get_gridmeta(i8* %4, i32 1000)
%46 = icmp eq i32 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %44
%48 = call i32 @exit(i32 7)
unreachable
49: ; preds = %44
%50 = load float, float* %17
%51 = fpext float %50 to double
%52 = load float, float* %21
%53 = fpext float %52 to double
%54 = load float, float* %19
%55 = fpext float %54 to double
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), double %51, double %53, double %55, i64 %10)
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %3)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%59 = call i32 @exit(i32 0)
unreachable
}