#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 */
int /*<<< orphan*/ callSystem(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ removeAFile(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, ...);
void chopGribFile(char *inFileName, char *outFileName, char *tempFileName,
                  char *tempFileName2, int type) {
  if (type < 0 || type > 2) {
    printf("Invalid chop type specified, exiting\n");
    exit(0);
  }
  char systemCall[4096];
  sprintf(systemCall,
          "./wgrib2 %s -if_n 6::6 -s -set_grib_type c3 -grib_out %s",
          inFileName, tempFileName);
  callSystem(systemCall);
  if (type == 0)
    sprintf(
        systemCall,
        "./wgrib2 %s | grep \":d=$YYYYMMDD\" | ./wgrib2 -i %s -if '00:TMAX:' "
        "-rpn sto_1 -fi -if '06:TMAX:' -rpn sto_2 -fi -if '12:TMAX:' -rpn "
        "sto_3 -fi -if '18:TMAX:' -rpn sto_4 -fi -if_reg '1:2:3:4' -rpn "
        "'rcl_1:rcl_2:rcl_3:rcl_4:max:max:max' -set_ave '4@6 hour max(0-6 hour "
        "max fcst),missing=0' -set_grib_type c3 -grib_out %s",
        tempFileName, tempFileName, tempFileName2);
  else if (type == 1)
    sprintf(
        systemCall,
        "./wgrib2 %s | grep \":d=$YYYYMMDD\" | ./wgrib2 -i %s -if '00:TMIN:' "
        "-rpn sto_1 -fi -if '06:TMIN:' -rpn sto_2 -fi -if '12:TMIN:' -rpn "
        "sto_3 -fi -if '18:TMIN:' -rpn sto_4 -fi -if_reg '1:2:3:4' -rpn "
        "'rcl_1:rcl_2:rcl_3:rcl_4:min:min:min' -set_ave '4@6 hour max(0-6 hour "
        "max fcst),missing=0' -set_grib_type c3 -grib_out %s",
        tempFileName, tempFileName, tempFileName2);
  else if (type == 2)
    sprintf(systemCall,
            "./wgrib2 %s | grep \":d=$YYYYMMDD\" | ./wgrib2 -i %s -if "
            "'00:PRATE:' -rpn sto_1 -fi -if '06:PRATE:' -rpn sto_2 -fi -if "
            "'12:PRATE:' -rpn sto_3 -fi -if '18:PRATE:' -rpn sto_4 -fi -if_reg "
            "'1:2:3:4' -rpn 'rcl_1:rcl_2:rcl_3:rcl_4:+:+:+' -set_ave '4@6 hour "
            "max(0-6 hour max fcst),missing=0' -set_grib_type c3 -grib_out %s",
            tempFileName, tempFileName, tempFileName2);
  callSystem(systemCall);
  sprintf(systemCall,
          "./wgrib2 %s -if_n 1::4 -s -set_grib_type c3 -grib_out %s",
          tempFileName2, outFileName);
  callSystem(systemCall);
  removeAFile(tempFileName);
  removeAFile(tempFileName2);
}


x86 assembly (clang, -O0):
<chopGribFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1183 <chopGribFile+0x33>
cmpl   $0x2,-0x24(%rbp)
jle    1196 <chopGribFile+0x46>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    -0x1030(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x1030(%rbp),%rdi
call   1040 <callSystem@plt>
cmpl   $0x0,-0x24(%rbp)
jne    11ef <chopGribFile+0x9f>
lea    -0x1030(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    1254 <chopGribFile+0x104>
cmpl   $0x1,-0x24(%rbp)
jne    121f <chopGribFile+0xcf>
lea    -0x1030(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xf88(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    124f <chopGribFile+0xff>
cmpl   $0x2,-0x24(%rbp)
jne    124a <chopGribFile+0xfa>
lea    -0x1030(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0x1094(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    124f <chopGribFile+0xff>
jmp    1254 <chopGribFile+0x104>
lea    -0x1030(%rbp),%rdi
call   1040 <callSystem@plt>
lea    -0x1030(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0x119b(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x1030(%rbp),%rdi
call   1040 <callSystem@plt>
mov    -0x18(%rbp),%rdi
call   1050 <removeAFile@plt>
mov    -0x20(%rbp),%rdi
call   1050 <removeAFile@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chopGribFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
cmp    $0x3,%r8d
jae    1213 <chopGribFile+0xc3>
mov    %r8d,%ebp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rdx
lea    0xe81(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %r12,%rdi
call   1040 <callSystem@plt>
cmp    $0x1,%ebp
lea    0xfd4(%rip),%rax
lea    0x1109(%rip),%rcx
cmove  %rax,%rcx
test   %ebp,%ebp
lea    0xe84(%rip),%rsi
cmovne %rcx,%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %r12,%rdi
call   1040 <callSystem@plt>
lea    0x1210(%rip),%rsi
mov    %r12,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %r12,%rdi
call   1040 <callSystem@plt>
mov    %rbx,%rdi
call   1050 <removeAFile@plt>
mov    %r14,%rdi
call   1050 <removeAFile@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x120a(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"Invalid chop type specified, exiting\0A\00"
@.str.1 = [57 x i8] c"./wgrib2 %s -if_n 6::6 -s -set_grib_type c3 -grib_out %s\00"
@.str.2 = [316 x i8] c"./wgrib2 %s | grep \22:d=$YYYYMMDD\22 | ./wgrib2 -i %s -if '00:TMAX:' -rpn sto_1 -fi -if '06:TMAX:' -rpn sto_2 -fi -if '12:TMAX:' -rpn sto_3 -fi -if '18:TMAX:' -rpn sto_4 -fi -if_reg '1:2:3:4' -rpn 'rcl_1:rcl_2:rcl_3:rcl_4:max:max:max' -set_ave '4@6 hour max(0-6 hour max fcst),missing=0' -set_grib_type c3 -grib_out %s\00"
@.str.3 = [316 x i8] c"./wgrib2 %s | grep \22:d=$YYYYMMDD\22 | ./wgrib2 -i %s -if '00:TMIN:' -rpn sto_1 -fi -if '06:TMIN:' -rpn sto_2 -fi -if '12:TMIN:' -rpn sto_3 -fi -if '18:TMIN:' -rpn sto_4 -fi -if_reg '1:2:3:4' -rpn 'rcl_1:rcl_2:rcl_3:rcl_4:min:min:min' -set_ave '4@6 hour max(0-6 hour max fcst),missing=0' -set_grib_type c3 -grib_out %s\00"
@.str.4 = [314 x i8] c"./wgrib2 %s | grep \22:d=$YYYYMMDD\22 | ./wgrib2 -i %s -if '00:PRATE:' -rpn sto_1 -fi -if '06:PRATE:' -rpn sto_2 -fi -if '12:PRATE:' -rpn sto_3 -fi -if '18:PRATE:' -rpn sto_4 -fi -if_reg '1:2:3:4' -rpn 'rcl_1:rcl_2:rcl_3:rcl_4:+:+:+' -set_ave '4@6 hour max(0-6 hour max fcst),missing=0' -set_grib_type c3 -grib_out %s\00"
@.str.5 = [57 x i8] c"./wgrib2 %s -if_n 1::4 -s -set_grib_type c3 -grib_out %s\00"
define void @chopGribFile(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca [4096 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%12 = load i32, i32* %10
%13 = icmp slt i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %5
%15 = load i32, i32* %10
%16 = icmp sgt i32 %15, 2
br i1 %16, label %17, label %20
17: ; preds = %14, %5
%18 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %14
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%22 = load i8*, i8** %6
%23 = load i8*, i8** %8
%24 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %23)
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%26 = call i32 @callSystem(i8* %25)
%27 = load i32, i32* %10
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %20
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%31 = load i8*, i8** %8
%32 = load i8*, i8** %8
%33 = load i8*, i8** %9
%34 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([316 x i8], [316 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %32, i8* %33)
br label %55
35: ; preds = %20
%36 = load i32, i32* %10
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%40 = load i8*, i8** %8
%41 = load i8*, i8** %8
%42 = load i8*, i8** %9
%43 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([316 x i8], [316 x i8]* @.str.3, i64 0, i64 0), i8* %40, i8* %41, i8* %42)
br label %54
44: ; preds = %35
%45 = load i32, i32* %10
%46 = icmp eq i32 %45, 2
br i1 %46, label %47, label %53
47: ; preds = %44
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%49 = load i8*, i8** %8
%50 = load i8*, i8** %8
%51 = load i8*, i8** %9
%52 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([314 x i8], [314 x i8]* @.str.4, i64 0, i64 0), i8* %49, i8* %50, i8* %51)
br label %53
53: ; preds = %47, %44
br label %54
54: ; preds = %53, %38
br label %55
55: ; preds = %54, %29
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%57 = call i32 @callSystem(i8* %56)
%58 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%59 = load i8*, i8** %9
%60 = load i8*, i8** %7
%61 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %58, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i8* %59, i8* %60)
%62 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%63 = call i32 @callSystem(i8* %62)
%64 = load i8*, i8** %8
%65 = call i32 @removeAFile(i8* %64)
%66 = load i8*, i8** %9
%67 = call i32 @removeAFile(i8* %66)
ret void
}

LLVM IR (-O2):
@.str.1 = [57 x i8] c"./wgrib2 %s -if_n 6::6 -s -set_grib_type c3 -grib_out %s\00"
@.str.2 = [316 x i8] c"./wgrib2 %s | grep \22:d=$YYYYMMDD\22 | ./wgrib2 -i %s -if '00:TMAX:' -rpn sto_1 -fi -if '06:TMAX:' -rpn sto_2 -fi -if '12:TMAX:' -rpn sto_3 -fi -if '18:TMAX:' -rpn sto_4 -fi -if_reg '1:2:3:4' -rpn 'rcl_1:rcl_2:rcl_3:rcl_4:max:max:max' -set_ave '4@6 hour max(0-6 hour max fcst),missing=0' -set_grib_type c3 -grib_out %s\00"
@.str.3 = [316 x i8] c"./wgrib2 %s | grep \22:d=$YYYYMMDD\22 | ./wgrib2 -i %s -if '00:TMIN:' -rpn sto_1 -fi -if '06:TMIN:' -rpn sto_2 -fi -if '12:TMIN:' -rpn sto_3 -fi -if '18:TMIN:' -rpn sto_4 -fi -if_reg '1:2:3:4' -rpn 'rcl_1:rcl_2:rcl_3:rcl_4:min:min:min' -set_ave '4@6 hour max(0-6 hour max fcst),missing=0' -set_grib_type c3 -grib_out %s\00"
@.str.4 = [314 x i8] c"./wgrib2 %s | grep \22:d=$YYYYMMDD\22 | ./wgrib2 -i %s -if '00:PRATE:' -rpn sto_1 -fi -if '06:PRATE:' -rpn sto_2 -fi -if '12:PRATE:' -rpn sto_3 -fi -if '18:PRATE:' -rpn sto_4 -fi -if_reg '1:2:3:4' -rpn 'rcl_1:rcl_2:rcl_3:rcl_4:+:+:+' -set_ave '4@6 hour max(0-6 hour max fcst),missing=0' -set_grib_type c3 -grib_out %s\00"
@.str.5 = [57 x i8] c"./wgrib2 %s -if_n 1::4 -s -set_grib_type c3 -grib_out %s\00"
@str = [37 x i8] c"Invalid chop type specified, exiting\00"
define void @chopGribFile(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca [4096 x i8]
%7 = icmp ugt i32 %4, 2
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %5
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%13 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %2)
%14 = call i32 @callSystem(i8* %12)
%15 = icmp eq i32 %4, 1
%16 = select i1 %15, i8* getelementptr inbounds ([316 x i8], [316 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([314 x i8], [314 x i8]* @.str.4, i64 0, i64 0)
%17 = icmp eq i32 %4, 0
%18 = select i1 %17, i8* getelementptr inbounds ([316 x i8], [316 x i8]* @.str.2, i64 0, i64 0), i8* %16
%19 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) %18, i8* %2, i8* %2, i8* %3)
%20 = call i32 @callSystem(i8* %12)
%21 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i8* %3, i8* %1)
%22 = call i32 @callSystem(i8* %12)
%23 = call i32 @removeAFile(i8* %2)
%24 = call i32 @removeAFile(i8* %3)
ret void
}