#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 *, ...);
scalar_t__ rd_msg(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  FILE *out, *p[200];
  int eofs[200];
  int i, n, done;
  if (argc < 4) {
    fprintf(stderr,
            "%s bad arg: output (list of grib-inputs) list size <= %d\n",
            "gmerge v1.4 5/2018", 200);
    exit(8);
  }
  if (strcmp(argv[1], "-") == 0) {
    out = stdout;
  } else {
    if ((out = fopen(argv[1], "wb")) == NULL) {
      fprintf(stderr, "bad arg: output=%s\n", argv[1]);
      exit(8);
    }
  }
  n = argc - 2;
  for (i = 0; i < n; i++) {
    p[i] = fopen(argv[i + 2], "rb");
    if (p[i] == NULL) {
      fprintf(stderr, "bad file: %s\n", argv[i + 2]);
      exit(8);
    }
    eofs[i] = 0;
  }
  done = 0;
  while (done != n) {
    done = 0;
    for (i = 0; i < n; i++) {
      if (eofs[i] == 1) {
        done++;
      } else {
        if (rd_msg(p[i], out)) {
          done++;
          eofs[i] = 1;
        }
      }
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x990,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11a0 <main+0x50>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
lea    0xeb0(%rip),%rdx
mov    $0xc8,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11d1 <main+0x81>
mov    0x2e13(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1221 <main+0xd1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    121c <main+0xcc>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1070 <exit@plt>
jmp    1221 <main+0xd1>
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x988(%rbp)
movl   $0x0,-0x984(%rbp)
mov    -0x984(%rbp),%eax
cmp    -0x988(%rbp),%eax
jge    12ec <main+0x19c>
mov    -0x10(%rbp),%rax
mov    -0x984(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe02(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rcx
movslq -0x984(%rbp),%rax
mov    %rcx,-0x660(%rbp,%rax,8)
ff
movslq -0x984(%rbp),%rax
cmpq   $0x0,-0x660(%rbp,%rax,8)
jne    12c6 <main+0x176>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x984(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1070 <exit@plt>
movslq -0x984(%rbp),%rax
movl   $0x0,-0x980(%rbp,%rax,4)
mov    -0x984(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x984(%rbp)
jmp    1237 <main+0xe7>
movl   $0x0,-0x98c(%rbp)
mov    -0x98c(%rbp),%eax
cmp    -0x988(%rbp),%eax
je     13bd <main+0x26d>
movl   $0x0,-0x98c(%rbp)
movl   $0x0,-0x984(%rbp)
mov    -0x984(%rbp),%eax
cmp    -0x988(%rbp),%eax
jge    13b8 <main+0x268>
movslq -0x984(%rbp),%rax
cmpl   $0x1,-0x980(%rbp,%rax,4)
01
jne    1357 <main+0x207>
mov    -0x98c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98c(%rbp)
jmp    139f <main+0x24f>
movslq -0x984(%rbp),%rax
mov    -0x660(%rbp,%rax,8),%rdi
ff
mov    -0x18(%rbp),%rsi
call   1030 <rd_msg@plt>
cmp    $0x0,%rax
je     139a <main+0x24a>
mov    -0x98c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98c(%rbp)
movslq -0x984(%rbp),%rax
movl   $0x1,-0x980(%rbp,%rax,4)
jmp    139f <main+0x24f>
jmp    13a4 <main+0x254>
mov    -0x984(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x984(%rbp)
jmp    131c <main+0x1cc>
jmp    12f6 <main+0x1a6>
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    $0x968,%rsp
cmp    $0x3,%edi
jg     1193 <main+0x43>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
lea    0xebd(%rip),%rdx
mov    $0xc8,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1070 <exit@plt>
mov    %rsi,%r12
mov    %edi,%r14d
mov    0x8(%rsi),%rdi
lea    0xea9(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11ba <main+0x6a>
mov    0x2e23(%rip),%rax
mov    (%rax),%r15
jmp    11ed <main+0x9d>
mov    0x8(%r12),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11ed <main+0x9d>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r12),%rdx
lea    0xe6a(%rip),%rsi
jmp    12b1 <main+0x161>
add    $0xfffffffe,%r14d
mov    %r14,%rbx
neg    %rbx
mov    $0x2,%ebp
lea    0xe63(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12,%rbp,8),%rdi
mov    %r13,%rsi
call   1060 <fopen@plt>
mov    %rax,0x310(%rsp,%rbp,8)
test   %rax,%rax
je     129b <main+0x14b>
movl   $0x0,-0x8(%rsp,%rbp,4)
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbp
cmp    $0x2,%rax
jne    1210 <main+0xc0>
test   %r14d,%r14d
je     1294 <main+0x144>
mov    %r14d,%r12d
xor    %ebx,%ebx
xor    %ebp,%ebp
nop
cmpl   $0x1,(%rsp,%rbx,4)
jne    1260 <main+0x110>
add    $0x1,%ebp
jmp    127f <main+0x12f>
nopl   0x0(%rax,%rax,1)
mov    0x320(%rsp,%rbx,8),%rdi
mov    %r15,%rsi
call   1030 <rd_msg@plt>
test   %rax,%rax
je     127f <main+0x12f>
add    $0x1,%ebp
movl   $0x1,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    %r12,%rbx
jne    1250 <main+0x100>
xor    %ebx,%ebx
cmp    %r14d,%ebp
mov    $0x0,%ebp
jne    1250 <main+0x100>
xor    %edi,%edi
call   1070 <exit@plt>
mov    %ebp,%eax
mov    0x2d3c(%rip),%rcx
mov    (%rcx),%edi
mov    (%r12,%rax,8),%rdx
lea    0xdb8(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [58 x i8] c"%s bad arg: output (list of grib-inputs) list size <= %d\0A\00"
@.str.1 = [19 x i8] c"gmerge v1.4 5/2018\00"
@.str.2 = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [20 x i8] c"bad arg: output=%s\0A\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [14 x i8] c"bad file: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [200 x i32*]
%8 = alloca [200 x i32]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 200)
%17 = call i32 @exit(i32 8)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load i32*, i32** @stdout
store i32* %25, i32** %6
br label %40
26: ; preds = %18
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %30, i32** %6
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %39
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %36)
%38 = call i32 @exit(i32 8)
unreachable
39: ; preds = %26
br label %40
40: ; preds = %39, %24
%41 = load i32, i32* %4
%42 = sub nsw i32 %41, 2
store i32 %42, i32* %10
store i32 0, i32* %9
br label %43
43: ; preds = %77, %40
%44 = load i32, i32* %9
%45 = load i32, i32* %10
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %80
47: ; preds = %43
%48 = load i8**, i8*** %5
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %48, i64 %51
%53 = load i8*, i8** %52
%54 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [200 x i32*], [200 x i32*]* %7, i64 0, i64 %56
store i32* %54, i32** %57
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [200 x i32*], [200 x i32*]* %7, i64 0, i64 %59
%61 = load i32*, i32** %60
%62 = icmp eq i32* %61, null
br i1 %62, label %63, label %73
63: ; preds = %47
%64 = load i32, i32* @stderr
%65 = load i8**, i8*** %5
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 2
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %65, i64 %68
%70 = load i8*, i8** %69
%71 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %70)
%72 = call i32 @exit(i32 8)
unreachable
73: ; preds = %47
%74 = load i32, i32* %9
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [200 x i32], [200 x i32]* %8, i64 0, i64 %75
store i32 0, i32* %76
br label %77
77: ; preds = %73
%78 = load i32, i32* %9
%79 = add nsw i32 %78, 1
store i32 %79, i32* %9
br label %43
80: ; preds = %43
store i32 0, i32* %11
br label %81
81: ; preds = %118, %80
%82 = load i32, i32* %11
%83 = load i32, i32* %10
%84 = icmp ne i32 %82, %83
br i1 %84, label %85, label %119
85: ; preds = %81
store i32 0, i32* %11
store i32 0, i32* %9
br label %86
86: ; preds = %115, %85
%87 = load i32, i32* %9
%88 = load i32, i32* %10
%89 = icmp slt i32 %87, %88
br i1 %89, label %90, label %118
90: ; preds = %86
%91 = load i32, i32* %9
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [200 x i32], [200 x i32]* %8, i64 0, i64 %92
%94 = load i32, i32* %93
%95 = icmp eq i32 %94, 1
br i1 %95, label %96, label %99
96: ; preds = %90
%97 = load i32, i32* %11
%98 = add nsw i32 %97, 1
store i32 %98, i32* %11
br label %114
99: ; preds = %90
%100 = load i32, i32* %9
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [200 x i32*], [200 x i32*]* %7, i64 0, i64 %101
%103 = load i32*, i32** %102
%104 = load i32*, i32** %6
%105 = call i64 @rd_msg(i32* %103, i32* %104)
%106 = icmp ne i64 %105, 0
br i1 %106, label %107, label %113
107: ; preds = %99
%108 = load i32, i32* %11
%109 = add nsw i32 %108, 1
store i32 %109, i32* %11
%110 = load i32, i32* %9
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds [200 x i32], [200 x i32]* %8, i64 0, i64 %111
store i32 1, i32* %112
br label %113
113: ; preds = %107, %99
br label %114
114: ; preds = %113, %96
br label %115
115: ; preds = %114
%116 = load i32, i32* %9
%117 = add nsw i32 %116, 1
store i32 %117, i32* %9
br label %86
118: ; preds = %86
br label %81
119: ; preds = %81
%120 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [58 x i8] c"%s bad arg: output (list of grib-inputs) list size <= %d\0A\00"
@.str.1 = [19 x i8] c"gmerge v1.4 5/2018\00"
@.str.2 = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [20 x i8] c"bad arg: output=%s\0A\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [14 x i8] c"bad file: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [200 x i32*]
%4 = alloca [200 x i32]
%5 = bitcast [200 x i32*]* %3 to i8*
%6 = bitcast [200 x i32]* %4 to i8*
%7 = icmp slt i32 %0, 4
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 200)
%11 = tail call i32 @exit(i32 8)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = load i32*, i32** @stdout
br label %28
19: ; preds = %12
%20 = load i8*, i8** %13
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %13
%26 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = tail call i32 @exit(i32 8)
unreachable
28: ; preds = %17, %19
%29 = phi i32* [ %18, %17 ], [ %21, %19 ]
%30 = add nsw i32 %0, -2
%31 = zext i32 %30 to i64
br label %36
32: ; preds = %51
%33 = icmp eq i32 %30, 0
br i1 %33, label %79, label %34
34: ; preds = %32
%35 = zext i32 %30 to i64
br label %57
36: ; preds = %28, %51
%37 = phi i64 [ 0, %28 ], [ %53, %51 ]
%38 = add nuw nsw i64 %37, 2
%39 = getelementptr inbounds i8*, i8** %1, i64 %38
%40 = load i8*, i8** %39
%41 = tail call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%42 = getelementptr inbounds [200 x i32*], [200 x i32*]* %3, i64 0, i64 %37
store i32* %41, i32** %42
%43 = icmp eq i32* %41, null
br i1 %43, label %44, label %51
44: ; preds = %36
%45 = and i64 %38, 4294967295
%46 = getelementptr inbounds i8*, i8** %1, i64 %45
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %46
%49 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %48)
%50 = tail call i32 @exit(i32 8)
unreachable
51: ; preds = %36
%52 = getelementptr inbounds [200 x i32], [200 x i32]* %4, i64 0, i64 %37
store i32 0, i32* %52
%53 = add nuw nsw i64 %37, 1
%54 = icmp eq i64 %53, %31
br i1 %54, label %32, label %36
55: ; preds = %72
%56 = icmp eq i32 %73, %30
br i1 %56, label %79, label %76
57: ; preds = %76, %34
%58 = phi i64 [ 0, %34 ], [ %77, %76 ]
%59 = phi i32 [ 0, %34 ], [ %78, %76 ]
%60 = getelementptr inbounds [200 x i32], [200 x i32]* %4, i64 0, i64 %58
%61 = load i32, i32* %60
%62 = icmp eq i32 %61, 1
br i1 %62, label %63, label %65
63: ; preds = %57
%64 = add nsw i32 %59, 1
br label %72
65: ; preds = %57
%66 = getelementptr inbounds [200 x i32*], [200 x i32*]* %3, i64 0, i64 %58
%67 = load i32*, i32** %66
%68 = tail call i64 @rd_msg(i32* %67, i32* %29)
%69 = icmp eq i64 %68, 0
br i1 %69, label %72, label %70
70: ; preds = %65
%71 = add nsw i32 %59, 1
store i32 1, i32* %60
br label %72
72: ; preds = %63, %70, %65
%73 = phi i32 [ %64, %63 ], [ %71, %70 ], [ %59, %65 ]
%74 = add nuw nsw i64 %58, 1
%75 = icmp eq i64 %74, %35
br i1 %75, label %55, label %76
76: ; preds = %72, %55
%77 = phi i64 [ %74, %72 ], [ 0, %55 ]
%78 = phi i32 [ %73, %72 ], [ 0, %55 ]
br label %57
79: ; preds = %55, %32
%80 = tail call i32 @exit(i32 0)
unreachable
}