#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 */
char *cdiStringError(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ streamClose(int);
int /*<<< orphan*/ streamDefTimestep(int, int);
int /*<<< orphan*/ streamDefVlist(int, int);
int /*<<< orphan*/ streamInqTimestep(int, int);
int streamInqVlist(int);
int streamOpenRead(char *);
int streamOpenWrite(char *, int);
int /*<<< orphan*/ streamReadVar(int, int, double *, int *);
int /*<<< orphan*/ streamWriteVar(int, int, double *, int);
int vlistDuplicate(int);
int main(void) {
  const int nlon = 12;
  const int nlat = 6;
  const int nlev = 5;
  const int nts = 3;
  int nmiss;
  double var1[nlon * nlat];
  double var2[nlon * nlat * nlev];
  int streamID1 = streamOpenRead("example.nc");
  if (streamID1 < 0) {
    fprintf(stderr, "%s\n", cdiStringError(streamID1));
    return 1;
  }
  int vlistID1 = streamInqVlist(streamID1);
  int varID1 = 0;
  int varID2 = 1;
  int streamID2 = streamOpenWrite("example.grb", 1);
  if (streamID2 < 0) {
    fprintf(stderr, "%s\n", cdiStringError(streamID2));
    return 1;
  }
  int vlistID2 = vlistDuplicate(vlistID1);
  streamDefVlist(streamID2, vlistID2);
  for (int tsID = 0; tsID < nts; tsID++) {
    streamInqTimestep(streamID1, tsID);
    streamDefTimestep(streamID2, tsID);
    streamReadVar(streamID1, varID1, var1, &nmiss);
    streamReadVar(streamID1, varID2, var2, &nmiss);
    streamWriteVar(streamID2, varID1, var1, nmiss);
    streamWriteVar(streamID2, varID2, var2, nmiss);
  }
  streamClose(streamID1);
  streamClose(streamID2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xdd0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc,-0x8(%rbp)
movl   $0x6,-0xc(%rbp)
movl   $0x5,-0x10(%rbp)
movl   $0x3,-0x14(%rbp)
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
lea    0xe04(%rip),%rdi
call   1030 <streamOpenRead@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    124d <main+0x8d>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xdc4(%rbp)
mov    -0x24(%rbp),%edi
call   10b0 <cdiStringError@plt>
mov    -0xdc4(%rbp),%edi
mov    %rax,%rdx
lea    0xdd6(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    1382 <main+0x1c2>
mov    -0x24(%rbp),%edi
call   10c0 <streamInqVlist@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
lea    0xda2(%rip),%rdi
mov    $0x1,%esi
call   1080 <streamOpenWrite@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    12c3 <main+0x103>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xdc8(%rbp)
mov    -0x38(%rbp),%edi
call   10b0 <cdiStringError@plt>
mov    -0xdc8(%rbp),%edi
mov    %rax,%rdx
lea    0xd60(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    1382 <main+0x1c2>
mov    -0x2c(%rbp),%edi
call   1090 <vlistDuplicate@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x3c(%rbp),%esi
call   1050 <streamDefVlist@plt>
movl   $0x0,-0x40(%rbp)
cmpl   $0x3,-0x40(%rbp)
jge    1364 <main+0x1a4>
mov    -0x24(%rbp),%edi
mov    -0x40(%rbp),%esi
call   1060 <streamInqTimestep@plt>
mov    -0x38(%rbp),%edi
mov    -0x40(%rbp),%esi
call   1070 <streamDefTimestep@plt>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%esi
lea    -0x280(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   10d0 <streamReadVar@plt>
mov    -0x24(%rbp),%edi
mov    -0x34(%rbp),%esi
lea    -0xdc0(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   10d0 <streamReadVar@plt>
mov    -0x38(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x18(%rbp),%ecx
lea    -0x280(%rbp),%rdx
call   10e0 <streamWriteVar@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    -0x18(%rbp),%ecx
lea    -0xdc0(%rbp),%rdx
call   10e0 <streamWriteVar@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12e0 <main+0x120>
mov    -0x24(%rbp),%edi
call   1040 <streamClose@plt>
mov    -0x38(%rbp),%edi
call   1040 <streamClose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0xdd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd98,%rsp
mov    %rsp,%r12
lea    0xe25(%rip),%rdi
call   1030 <streamOpenRead@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1363 <main+0x1a3>
mov    %ebp,%edi
call   10c0 <streamInqVlist@plt>
mov    %eax,%r15d
lea    0xe14(%rip),%rdi
mov    $0x1,%r14d
mov    $0x1,%esi
call   1080 <streamOpenWrite@plt>
mov    %eax,%ebx
test   %eax,%eax
js     138c <main+0x1cc>
mov    %r15d,%edi
call   1090 <vlistDuplicate@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <streamDefVlist@plt>
xor    %r14d,%r14d
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <streamInqTimestep@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1070 <streamDefTimestep@plt>
lea    0x10(%rsp),%r15
lea    0x4(%rsp),%r13
mov    %ebp,%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %r13,%rcx
call   10d0 <streamReadVar@plt>
mov    %r12,0x8(%rsp)
lea    0x250(%rsp),%r12
mov    %ebp,%edi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %r13,%rcx
call   10d0 <streamReadVar@plt>
mov    0x4(%rsp),%ecx
mov    %ebx,%edi
xor    %esi,%esi
mov    %r15,%rdx
call   10e0 <streamWriteVar@plt>
mov    0x4(%rsp),%ecx
mov    %ebx,%edi
mov    $0x1,%esi
mov    %r12,%rdx
call   10e0 <streamWriteVar@plt>
mov    %ebp,%edi
mov    $0x1,%esi
call   1060 <streamInqTimestep@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1070 <streamDefTimestep@plt>
mov    %ebp,%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %r13,%rcx
call   10d0 <streamReadVar@plt>
mov    %ebp,%edi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %r13,%rcx
call   10d0 <streamReadVar@plt>
mov    0x4(%rsp),%ecx
mov    %ebx,%edi
xor    %esi,%esi
mov    %r15,%rdx
call   10e0 <streamWriteVar@plt>
mov    0x4(%rsp),%ecx
mov    %ebx,%edi
mov    $0x1,%esi
mov    %r12,%rdx
call   10e0 <streamWriteVar@plt>
mov    %ebp,%edi
mov    $0x2,%esi
call   1060 <streamInqTimestep@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1070 <streamDefTimestep@plt>
mov    %ebp,%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %r13,%rcx
call   10d0 <streamReadVar@plt>
mov    %ebp,%edi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %r13,%rcx
call   10d0 <streamReadVar@plt>
mov    0x4(%rsp),%ecx
mov    %ebx,%edi
xor    %esi,%esi
mov    %r15,%rdx
call   10e0 <streamWriteVar@plt>
mov    0x4(%rsp),%ecx
mov    %ebx,%edi
mov    $0x1,%esi
mov    %r12,%rdx
mov    0x8(%rsp),%r12
call   10e0 <streamWriteVar@plt>
mov    %ebp,%edi
call   1040 <streamClose@plt>
mov    %ebx,%edi
call   1040 <streamClose@plt>
jmp    13ad <main+0x1ed>
mov    0x2c76(%rip),%rax
mov    (%rax),%ebx
mov    %ebp,%edi
call   10b0 <cdiStringError@plt>
lea    0xc91(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    $0x1,%r14d
jmp    13ad <main+0x1ed>
mov    0x2c4d(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   10b0 <cdiStringError@plt>
lea    0xc68(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    %r12,%rsp
mov    %r14d,%eax
add    $0xd98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"example.nc\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [12 x i8] c"example.grb\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %1
store i32 12, i32* %2
store i32 6, i32* %3
store i32 5, i32* %4
store i32 3, i32* %5
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %7
%17 = alloca double, i64 72
%18 = alloca double, i64 360
%19 = call i32 @streamOpenRead(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %0
%23 = load i32, i32* @stderr
%24 = load i32, i32* %8
%25 = call i8* @cdiStringError(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store i32 1, i32* %1
store i32 1, i32* %9
br label %76
27: ; preds = %0
%28 = load i32, i32* %8
%29 = call i32 @streamInqVlist(i32 %28)
store i32 %29, i32* %10
store i32 0, i32* %11
store i32 1, i32* %12
%30 = call i32 @streamOpenWrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 1)
store i32 %30, i32* %13
%31 = load i32, i32* %13
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = load i32, i32* %13
%36 = call i8* @cdiStringError(i32 %35)
%37 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %36)
store i32 1, i32* %1
store i32 1, i32* %9
br label %76
38: ; preds = %27
%39 = load i32, i32* %10
%40 = call i32 @vlistDuplicate(i32 %39)
store i32 %40, i32* %14
%41 = load i32, i32* %13
%42 = load i32, i32* %14
%43 = call i32 @streamDefVlist(i32 %41, i32 %42)
store i32 0, i32* %15
br label %44
44: ; preds = %68, %38
%45 = load i32, i32* %15
%46 = icmp slt i32 %45, 3
br i1 %46, label %47, label %71
47: ; preds = %44
%48 = load i32, i32* %8
%49 = load i32, i32* %15
%50 = call i32 @streamInqTimestep(i32 %48, i32 %49)
%51 = load i32, i32* %13
%52 = load i32, i32* %15
%53 = call i32 @streamDefTimestep(i32 %51, i32 %52)
%54 = load i32, i32* %8
%55 = load i32, i32* %11
%56 = call i32 @streamReadVar(i32 %54, i32 %55, double* %17, i32* %6)
%57 = load i32, i32* %8
%58 = load i32, i32* %12
%59 = call i32 @streamReadVar(i32 %57, i32 %58, double* %18, i32* %6)
%60 = load i32, i32* %13
%61 = load i32, i32* %11
%62 = load i32, i32* %6
%63 = call i32 @streamWriteVar(i32 %60, i32 %61, double* %17, i32 %62)
%64 = load i32, i32* %13
%65 = load i32, i32* %12
%66 = load i32, i32* %6
%67 = call i32 @streamWriteVar(i32 %64, i32 %65, double* %18, i32 %66)
br label %68
68: ; preds = %47
%69 = load i32, i32* %15
%70 = add nsw i32 %69, 1
store i32 %70, i32* %15
br label %44
71: ; preds = %44
%72 = load i32, i32* %8
%73 = call i32 @streamClose(i32 %72)
%74 = load i32, i32* %13
%75 = call i32 @streamClose(i32 %74)
store i32 0, i32* %1
store i32 1, i32* %9
br label %76
76: ; preds = %71, %33, %22
%77 = load i8*, i8** %7
%78 = load i32, i32* %1
ret i32 %78
}

LLVM IR (-O2):
@.str = [11 x i8] c"example.nc\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [12 x i8] c"example.grb\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i8* @llvm.stacksave()
%4 = alloca [72 x double]
%5 = alloca [360 x double]
%6 = getelementptr inbounds [360 x double], [360 x double]* %5, i64 0, i64 0
%7 = getelementptr inbounds [72 x double], [72 x double]* %4, i64 0, i64 0
%8 = tail call i32 @streamOpenRead(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = tail call i8* @cdiStringError(i32 %8)
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %51
14: ; preds = %0
%15 = tail call i32 @streamInqVlist(i32 %8)
%16 = tail call i32 @streamOpenWrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 1)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = tail call i8* @cdiStringError(i32 %16)
%21 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %51
22: ; preds = %14
%23 = tail call i32 @vlistDuplicate(i32 %15)
%24 = tail call i32 @streamDefVlist(i32 %16, i32 %23)
%25 = call i32 @streamInqTimestep(i32 %8, i32 0)
%26 = call i32 @streamDefTimestep(i32 %16, i32 0)
%27 = call i32 @streamReadVar(i32 %8, i32 0, double* %7, i32* %1)
%28 = call i32 @streamReadVar(i32 %8, i32 1, double* %6, i32* %1)
%29 = load i32, i32* %1
%30 = call i32 @streamWriteVar(i32 %16, i32 0, double* %7, i32 %29)
%31 = load i32, i32* %1
%32 = call i32 @streamWriteVar(i32 %16, i32 1, double* %6, i32 %31)
%33 = call i32 @streamInqTimestep(i32 %8, i32 1)
%34 = call i32 @streamDefTimestep(i32 %16, i32 1)
%35 = call i32 @streamReadVar(i32 %8, i32 0, double* %7, i32* %1)
%36 = call i32 @streamReadVar(i32 %8, i32 1, double* %6, i32* %1)
%37 = load i32, i32* %1
%38 = call i32 @streamWriteVar(i32 %16, i32 0, double* %7, i32 %37)
%39 = load i32, i32* %1
%40 = call i32 @streamWriteVar(i32 %16, i32 1, double* %6, i32 %39)
%41 = call i32 @streamInqTimestep(i32 %8, i32 2)
%42 = call i32 @streamDefTimestep(i32 %16, i32 2)
%43 = call i32 @streamReadVar(i32 %8, i32 0, double* %7, i32* %1)
%44 = call i32 @streamReadVar(i32 %8, i32 1, double* %6, i32* %1)
%45 = load i32, i32* %1
%46 = call i32 @streamWriteVar(i32 %16, i32 0, double* %7, i32 %45)
%47 = load i32, i32* %1
%48 = call i32 @streamWriteVar(i32 %16, i32 1, double* %6, i32 %47)
%49 = call i32 @streamClose(i32 %8)
%50 = call i32 @streamClose(i32 %16)
br label %51
51: ; preds = %18, %22, %10
%52 = phi i32 [ 1, %10 ], [ 1, %18 ], [ 0, %22 ]
ret i32 %52
}