#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(float *);
int get_nxny(unsigned char *, unsigned char *, unsigned char *,
             unsigned char *);
scalar_t__ malloc(int);
int rd_grib_msg(int /*<<< orphan*/ *, long, unsigned char **, unsigned char **,
                unsigned char **, unsigned char **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unpk_bds(float *, unsigned char *, unsigned char *,
                            unsigned char *, unsigned char *, int);
int rd_grib_rec2(FILE *input, long int pos, unsigned char **pds,
                 unsigned char **gds, float **data, int *ndata, int *scale10,
                 int *scale2) {
  int len, nxny;
  unsigned char *lpds, *lgds, *lbms, *lbds;
  static float *array = NULL;
  static int array_size = 0;
  len = rd_grib_msg(input, pos, &lpds, &lgds, &lbms, &lbds);
  if (len <= 0)
    return len;
  *scale10 = ((1 - (int)((unsigned)((lpds)[26] & 0x80) >> 6)) *
              (int)((((lpds)[26] & 0x7f) << 8) + (lpds)[27]));
  *scale2 = ((1 - (int)((unsigned)((lbds)[4] & 0x80) >> 6)) *
             (int)((((lbds)[4] & 0x7f) << 8) + (lbds)[5]));
  nxny = get_nxny(lpds, lgds, lbms, lbds);
  if (nxny > array_size) {
    if (array_size)
      free(array);
    if ((array = (float *)malloc(nxny * sizeof(float))) == NULL) {
      fprintf(stderr, "malloc failure in "
                      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/MennoTammens/"
                      "harmonie-grib/refs/heads/master/gribw/rd_grib_rec.c");
      exit(8);
    }
    array_size = nxny;
  }
  unpk_bds(array, lpds, lgds, lbms, lbds, nxny);
  *pds = lpds;
  *gds = lgds;
  *data = array;
  *ndata = nxny;
  return len;
}


x86 assembly (clang, -O0):
<rd_grib_rec2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
lea    -0x58(%rbp),%r8
lea    -0x60(%rbp),%r9
call   1070 <rd_grib_msg@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jg     11cd <rd_grib_rec2+0x5d>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1318 <rd_grib_rec2+0x1a8>
mov    -0x48(%rbp),%rax
movzbl 0x1a(%rax),%eax
and    $0x80,%eax
shr    $0x6,%eax
mov    $0x1,%ecx
sub    %eax,%ecx
mov    -0x48(%rbp),%rax
movzbl 0x1a(%rax),%eax
and    $0x7f,%eax
shl    $0x8,%eax
mov    -0x48(%rbp),%rdx
movzbl 0x1b(%rdx),%edx
add    %edx,%eax
imul   %eax,%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x60(%rbp),%rax
movzbl 0x4(%rax),%eax
and    $0x80,%eax
shr    $0x6,%eax
mov    $0x1,%ecx
sub    %eax,%ecx
mov    -0x60(%rbp),%rax
movzbl 0x4(%rax),%eax
and    $0x7f,%eax
shl    $0x8,%eax
mov    -0x60(%rbp),%rdx
movzbl 0x5(%rdx),%edx
add    %edx,%eax
imul   %eax,%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    -0x60(%rbp),%rcx
call   1080 <get_nxny@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    0x2e0a(%rip),%eax
jle    12c5 <rd_grib_rec2+0x155>
cmpl   $0x0,0x2dfd(%rip)
je     127d <rd_grib_rec2+0x10d>
mov    0x2de8(%rip),%rdi
call   1030 <free@plt>
movslq -0x40(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,0x2dcd(%rip)
cmp    $0x0,%rax
jne    12bc <rd_grib_rec2+0x14c>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
lea    0xd53(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1090 <exit@plt>
mov    -0x40(%rbp),%eax
mov    %eax,0x2da3(%rip)
mov    0x2d94(%rip),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rdx
mov    -0x58(%rbp),%rcx
mov    -0x60(%rbp),%r8
mov    -0x40(%rbp),%r9d
call   1040 <unpk_bds@plt>
mov    -0x48(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x50(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2d5e(%rip),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rd_grib_rec2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x20(%rsp),%r8
lea    0x18(%rsp),%r9
call   1070 <rd_grib_msg@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1298 <rd_grib_rec2+0x128>
mov    0x68(%rsp),%r8
mov    0x60(%rsp),%rcx
mov    0x10(%rsp),%rdi
movzbl 0x1a(%rdi),%edx
mov    %edx,%esi
shr    $0x6,%esi
and    $0xfffffffe,%esi
mov    $0x1,%ebx
mov    $0x1,%eax
sub    %esi,%eax
and    $0x7f,%edx
shl    $0x8,%edx
movzbl 0x1b(%rdi),%esi
or     %edx,%esi
imul   %eax,%esi
mov    %esi,(%rcx)
mov    0x18(%rsp),%rcx
movzbl 0x4(%rcx),%eax
mov    %eax,%edx
shr    $0x6,%edx
and    $0xfffffffe,%edx
sub    %edx,%ebx
and    $0x7f,%eax
shl    $0x8,%eax
movzbl 0x5(%rcx),%edx
or     %eax,%edx
imul   %ebx,%edx
mov    %edx,(%r8)
mov    0x8(%rsp),%rsi
mov    0x20(%rsp),%rdx
call   1080 <get_nxny@plt>
mov    %eax,%ebx
mov    0x2e47(%rip),%eax
cmp    %eax,%ebx
jle    1256 <rd_grib_rec2+0xe6>
test   %eax,%eax
je     1235 <rd_grib_rec2+0xc5>
mov    0x2e30(%rip),%rdi
call   1030 <free@plt>
mov    %ebx,%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,0x2e1a(%rip)
test   %rax,%rax
je     12a9 <rd_grib_rec2+0x139>
mov    %rax,%rdi
mov    %ebx,0x2e14(%rip)
jmp    125d <rd_grib_rec2+0xed>
mov    0x2e03(%rip),%rdi
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    0x20(%rsp),%rcx
mov    0x18(%rsp),%r8
mov    %ebx,%r9d
call   1040 <unpk_bds@plt>
mov    0x10(%rsp),%rax
mov    %rax,0x0(%r13)
mov    0x8(%rsp),%rax
mov    %rax,(%r12)
mov    0x2dce(%rip),%rax
mov    %rax,(%r15)
mov    %ebx,(%r14)
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xd47(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@rd_grib_rec2.array = internal global float* null
@rd_grib_rec2.array_size = internal global i32 0
@stderr = global i32 0
@.str = [173 x i8] c"malloc failure in /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/MennoTammens/harmonie-grib/refs/heads/master/gribw/rd_grib_rec.c\00"
define i32 @rd_grib_rec2(i32* %0, i64 %1, i8** %2, i8** %3, float** %4, i32* %5, i32* %6, i32* %7) {
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i8**
%13 = alloca i8**
%14 = alloca float**
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca i8*
%23 = alloca i8*
store i32* %0, i32** %10
store i64 %1, i64* %11
store i8** %2, i8*** %12
store i8** %3, i8*** %13
store float** %4, float*** %14
store i32* %5, i32** %15
store i32* %6, i32** %16
store i32* %7, i32** %17
%24 = load i32*, i32** %10
%25 = load i64, i64* %11
%26 = call i32 @rd_grib_msg(i32* %24, i64 %25, i8** %20, i8** %21, i8** %22, i8** %23)
store i32 %26, i32* %18
%27 = load i32, i32* %18
%28 = icmp sle i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %8
%30 = load i32, i32* %18
store i32 %30, i32* %9
br label %117
31: ; preds = %8
%32 = load i8*, i8** %20
%33 = getelementptr inbounds i8, i8* %32, i64 26
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = and i32 %35, 128
%37 = lshr i32 %36, 6
%38 = sub nsw i32 1, %37
%39 = load i8*, i8** %20
%40 = getelementptr inbounds i8, i8* %39, i64 26
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = and i32 %42, 127
%44 = shl i32 %43, 8
%45 = load i8*, i8** %20
%46 = getelementptr inbounds i8, i8* %45, i64 27
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = add nsw i32 %44, %48
%50 = mul nsw i32 %38, %49
%51 = load i32*, i32** %16
store i32 %50, i32* %51
%52 = load i8*, i8** %23
%53 = getelementptr inbounds i8, i8* %52, i64 4
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = and i32 %55, 128
%57 = lshr i32 %56, 6
%58 = sub nsw i32 1, %57
%59 = load i8*, i8** %23
%60 = getelementptr inbounds i8, i8* %59, i64 4
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = and i32 %62, 127
%64 = shl i32 %63, 8
%65 = load i8*, i8** %23
%66 = getelementptr inbounds i8, i8* %65, i64 5
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = add nsw i32 %64, %68
%70 = mul nsw i32 %58, %69
%71 = load i32*, i32** %17
store i32 %70, i32* %71
%72 = load i8*, i8** %20
%73 = load i8*, i8** %21
%74 = load i8*, i8** %22
%75 = load i8*, i8** %23
%76 = call i32 @get_nxny(i8* %72, i8* %73, i8* %74, i8* %75)
store i32 %76, i32* %19
%77 = load i32, i32* %19
%78 = load i32, i32* @rd_grib_rec2.array_size
%79 = icmp sgt i32 %77, %78
br i1 %79, label %80, label %100
80: ; preds = %31
%81 = load i32, i32* @rd_grib_rec2.array_size
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %80
%84 = load float*, float** @rd_grib_rec2.array
%85 = call i32 @free(float* %84)
br label %86
86: ; preds = %83, %80
%87 = load i32, i32* %19
%88 = sext i32 %87 to i64
%89 = mul i64 %88, 4
%90 = trunc i64 %89 to i32
%91 = call i64 @malloc(i32 %90)
%92 = inttoptr i64 %91 to float*
store float* %92, float** @rd_grib_rec2.array
%93 = icmp eq float* %92, null
br i1 %93, label %94, label %98
94: ; preds = %86
%95 = load i32, i32* @stderr
%96 = call i32 @fprintf(i32 %95, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0))
%97 = call i32 @exit(i32 8)
unreachable
98: ; preds = %86
%99 = load i32, i32* %19
store i32 %99, i32* @rd_grib_rec2.array_size
br label %100
100: ; preds = %98, %31
%101 = load float*, float** @rd_grib_rec2.array
%102 = load i8*, i8** %20
%103 = load i8*, i8** %21
%104 = load i8*, i8** %22
%105 = load i8*, i8** %23
%106 = load i32, i32* %19
%107 = call i32 @unpk_bds(float* %101, i8* %102, i8* %103, i8* %104, i8* %105, i32 %106)
%108 = load i8*, i8** %20
%109 = load i8**, i8*** %12
store i8* %108, i8** %109
%110 = load i8*, i8** %21
%111 = load i8**, i8*** %13
store i8* %110, i8** %111
%112 = load float*, float** @rd_grib_rec2.array
%113 = load float**, float*** %14
store float* %112, float** %113
%114 = load i32, i32* %19
%115 = load i32*, i32** %15
store i32 %114, i32* %115
%116 = load i32, i32* %18
store i32 %116, i32* %9
br label %117
117: ; preds = %100, %29
%118 = load i32, i32* %9
ret i32 %118
}

LLVM IR (-O2):
@rd_grib_rec2.array = internal unnamed_addr global float* null
@rd_grib_rec2.array_size = internal unnamed_addr global i32 0
@stderr = global i32 0
@.str = [173 x i8] c"malloc failure in /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/MennoTammens/harmonie-grib/refs/heads/master/gribw/rd_grib_rec.c\00"
define i32 @rd_grib_rec2(i32* %0, i64 %1, i8** nocapture writeonly %2, i8** nocapture writeonly %3, float** nocapture writeonly %4, i32* nocapture writeonly %5, i32* nocapture writeonly %6, i32* nocapture writeonly %7) {
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = bitcast i8** %9 to i8*
%14 = bitcast i8** %10 to i8*
%15 = bitcast i8** %11 to i8*
%16 = bitcast i8** %12 to i8*
%17 = call i32 @rd_grib_msg(i32* %0, i64 %1, i8** %9, i8** %10, i8** %11, i8** %12)
%18 = icmp slt i32 %17, 1
br i1 %18, label %80, label %19
19: ; preds = %8
%20 = load i8*, i8** %9
%21 = getelementptr inbounds i8, i8* %20, i64 26
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = lshr i32 %23, 6
%25 = and i32 %24, 2
%26 = sub nsw i32 1, %25
%27 = shl nuw nsw i32 %23, 8
%28 = and i32 %27, 32512
%29 = getelementptr inbounds i8, i8* %20, i64 27
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = or i32 %28, %31
%33 = mul nsw i32 %26, %32
store i32 %33, i32* %6
%34 = load i8*, i8** %12
%35 = getelementptr inbounds i8, i8* %34, i64 4
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = lshr i32 %37, 6
%39 = and i32 %38, 2
%40 = sub nsw i32 1, %39
%41 = shl nuw nsw i32 %37, 8
%42 = and i32 %41, 32512
%43 = getelementptr inbounds i8, i8* %34, i64 5
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = or i32 %42, %45
%47 = mul nsw i32 %40, %46
store i32 %47, i32* %7
%48 = load i8*, i8** %10
%49 = load i8*, i8** %11
%50 = call i32 @get_nxny(i8* %20, i8* %48, i8* %49, i8* %34)
%51 = load i32, i32* @rd_grib_rec2.array_size
%52 = icmp sgt i32 %50, %51
br i1 %52, label %55, label %53
53: ; preds = %19
%54 = load float*, float** @rd_grib_rec2.array
br label %70
55: ; preds = %19
%56 = icmp eq i32 %51, 0
br i1 %56, label %60, label %57
57: ; preds = %55
%58 = load float*, float** @rd_grib_rec2.array
%59 = call i32 @free(float* %58)
br label %60
60: ; preds = %57, %55
%61 = shl i32 %50, 2
%62 = call i64 @malloc(i32 %61)
%63 = inttoptr i64 %62 to float*
store float* %63, float** @rd_grib_rec2.array
%64 = icmp eq i64 %62, 0
br i1 %64, label %65, label %69
65: ; preds = %60
%66 = load i32, i32* @stderr
%67 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0))
%68 = call i32 @exit(i32 8)
unreachable
69: ; preds = %60
store i32 %50, i32* @rd_grib_rec2.array_size
br label %70
70: ; preds = %53, %69
%71 = phi float* [ %54, %53 ], [ %63, %69 ]
%72 = load i8*, i8** %9
%73 = load i8*, i8** %10
%74 = load i8*, i8** %11
%75 = load i8*, i8** %12
%76 = call i32 @unpk_bds(float* %71, i8* %72, i8* %73, i8* %74, i8* %75, i32 %50)
%77 = load i8*, i8** %9
store i8* %77, i8** %2
%78 = load i8*, i8** %10
store i8* %78, i8** %3
%79 = load float*, float** @rd_grib_rec2.array
store float* %79, float** %4
store i32 %50, i32* %5
br label %80
80: ; preds = %8, %70
ret i32 %17
}