#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
long rd_grib_msg(int /*<<< orphan*/ *, long, unsigned char **, unsigned char **,
                 unsigned char **, unsigned char **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wrt_grib_msg(int /*<<< orphan*/ *, unsigned char *,
                                unsigned char *, unsigned char *,
                                unsigned char *);
void main(int argc, char **argv) {
  long int len_grib, pos;
  unsigned char *pds, *gds, *bms, *bds;
  FILE *input, *output;
  if (argc != 3) {
    fprintf(stderr, "%s [in] [out] (time range)\n", argv[0]);
    exit(8);
  }
  if ((input = fopen(argv[1], "rb")) == NULL) {
    fprintf(stderr, "could not open file: %s\n", argv[1]);
    exit(7);
  }
  if ((output = fopen(argv[2], "wb")) == NULL) {
    fprintf(stderr, "could not open file: %s\n", argv[2]);
    exit(7);
  }
  pos = 0;
  while ((len_grib = rd_grib_msg(input, pos, &pds, &gds, &bms, &bds)) > 0) {
    wrt_grib_msg(output, pds, gds, bms, bds);
    pos += len_grib;
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x4(%rbp)
je     118f <main+0x3f>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x8,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    11d8 <main+0x88>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe56(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x7,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe51(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    1221 <main+0xd1>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe0d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x7,%edi
call   1070 <exit@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%r8
lea    -0x40(%rbp),%r9
call   1050 <rd_grib_msg@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jle    127e <main+0x12e>
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
call   1030 <wrt_grib_msg@plt>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1229 <main+0xd9>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    118a <main+0x3a>
mov    0x8(%rbx),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11ac <main+0x5c>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
jmp    11d1 <main+0x81>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x8,%edi
call   1070 <exit@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11e7 <main+0x97>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbx),%rdx
lea    0xe47(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x7,%edi
call   1070 <exit@plt>
mov    %rax,%r15
lea    0x20(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0x8(%rsp),%r9
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <rd_grib_msg@plt>
test   %rax,%rax
jle    125d <main+0x10d>
xor    %ebx,%ebx
lea    0x18(%rsp),%r13
lea    0x10(%rsp),%rbp
lea    0x8(%rsp),%r12
xchg   %ax,%ax
add    %rax,%rbx
mov    0x20(%rsp),%rsi
mov    0x18(%rsp),%rdx
mov    0x10(%rsp),%rcx
mov    0x8(%rsp),%r8
mov    %r15,%rdi
call   1030 <wrt_grib_msg@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
lea    0x20(%rsp),%rdx
mov    %r13,%rcx
mov    %rbp,%r8
mov    %r12,%r9
call   1050 <rd_grib_msg@plt>
test   %rax,%rax
jg     1220 <main+0xd0>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"%s [in] [out] (time range)\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [25 x i8] c"could not open file: %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 8)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %11
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %35
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %4
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 7)
unreachable
35: ; preds = %22
%36 = load i8**, i8*** %4
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %39, i32** %12
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %48
41: ; preds = %35
%42 = load i32, i32* @stderr
%43 = load i8**, i8*** %4
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 7)
unreachable
48: ; preds = %35
store i64 0, i64* %6
br label %49
49: ; preds = %54, %48
%50 = load i32*, i32** %11
%51 = load i64, i64* %6
%52 = call i64 @rd_grib_msg(i32* %50, i64 %51, i8** %7, i8** %8, i8** %9, i8** %10)
store i64 %52, i64* %5
%53 = icmp sgt i64 %52, 0
br i1 %53, label %54, label %64
54: ; preds = %49
%55 = load i32*, i32** %12
%56 = load i8*, i8** %7
%57 = load i8*, i8** %8
%58 = load i8*, i8** %9
%59 = load i8*, i8** %10
%60 = call i32 @wrt_grib_msg(i32* %55, i8* %56, i8* %57, i8* %58, i8* %59)
%61 = load i64, i64* %5
%62 = load i64, i64* %6
%63 = add nsw i64 %62, %61
store i64 %63, i64* %6
br label %49
64: ; preds = %49
%65 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"%s [in] [out] (time range)\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [25 x i8] c"could not open file: %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = bitcast i8** %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = bitcast i8** %5 to i8*
%10 = bitcast i8** %6 to i8*
%11 = icmp eq i32 %0, 3
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 8)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %18
%25 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = tail call i32 @exit(i32 7)
unreachable
27: ; preds = %17
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = tail call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = call i64 @rd_grib_msg(i32* %20, i64 0, i8** %3, i8** %4, i8** %5, i8** %6)
%34 = icmp sgt i64 %33, 0
br i1 %34, label %40, label %51
35: ; preds = %27
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %28
%38 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = tail call i32 @exit(i32 7)
unreachable
40: ; preds = %32, %40
%41 = phi i64 [ %49, %40 ], [ %33, %32 ]
%42 = phi i64 [ %48, %40 ], [ 0, %32 ]
%43 = load i8*, i8** %3
%44 = load i8*, i8** %4
%45 = load i8*, i8** %5
%46 = load i8*, i8** %6
%47 = call i32 @wrt_grib_msg(i32* %30, i8* %43, i8* %44, i8* %45, i8* %46)
%48 = add nsw i64 %41, %42
%49 = call i64 @rd_grib_msg(i32* %20, i64 %48, i8** %3, i8** %4, i8** %5, i8** %6)
%50 = icmp sgt i64 %49, 0
br i1 %50, label %40, label %51
51: ; preds = %40, %32
%52 = call i32 @exit(i32 0)
unreachable
}