#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*/ printf(char *, int, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ streamClose(int);
int /*<<< orphan*/ streamInqTimestep(int, int);
int streamInqVlist(int);
int streamOpenRead(char *);
int /*<<< orphan*/ streamReadVar(int, int, double *, int *);
int taxisInqVdate(int);
int taxisInqVtime(int);
int vlistInqTaxis(int);
int main(void) {
  const int nlon = 12;
  const int nlat = 6;
  const int nlev = 5;
  const int nts = 3;
  int nmiss, vdate, vtime;
  double var1[nlon * nlat];
  double var2[nlon * nlat * nlev];
  int streamID = streamOpenRead("example.nc");
  if (streamID < 0) {
    fprintf(stderr, "%s\n", cdiStringError(streamID));
    return 1;
  }
  int vlistID = streamInqVlist(streamID);
  int varID1 = 0;
  int varID2 = 1;
  int taxisID = vlistInqTaxis(vlistID);
  for (int tsID = 0; tsID < nts; tsID++) {
    streamInqTimestep(streamID, tsID);
    vdate = taxisInqVdate(taxisID);
    vtime = taxisInqVtime(taxisID);
    printf("read timestep %d:  date=%d  time=%d\n", tsID + 1, vdate, vtime);
    streamReadVar(streamID, varID1, var1, &nmiss);
    streamReadVar(streamID, varID2, var2, &nmiss);
  }
  streamClose(streamID);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xde0,%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,-0x28(%rbp)
lea    0xe14(%rip),%rdi
call   1030 <streamOpenRead@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    123d <main+0x8d>
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xdd4(%rbp)
mov    -0x2c(%rbp),%edi
call   10a0 <cdiStringError@plt>
mov    -0xdd4(%rbp),%edi
mov    %rax,%rdx
lea    0xde6(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    12fb <main+0x14b>
mov    -0x2c(%rbp),%edi
call   10c0 <streamInqVlist@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x34(%rbp),%edi
call   1090 <vlistInqTaxis@plt>
mov    %eax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x3,-0x44(%rbp)
jge    12e5 <main+0x135>
mov    -0x2c(%rbp),%edi
mov    -0x44(%rbp),%esi
call   1070 <streamInqTimestep@plt>
mov    -0x40(%rbp),%edi
call   10b0 <taxisInqVdate@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x40(%rbp),%edi
call   1060 <taxisInqVtime@plt>
mov    %eax,-0x20(%rbp)
mov    -0x44(%rbp),%esi
add    $0x1,%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xd69(%rip),%rdi
call   1050 <printf@plt>
mov    -0x2c(%rbp),%edi
mov    -0x38(%rbp),%esi
lea    -0x290(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   10d0 <streamReadVar@plt>
mov    -0x2c(%rbp),%edi
mov    -0x3c(%rbp),%esi
lea    -0xdd0(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   10d0 <streamReadVar@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1268 <main+0xb8>
mov    -0x2c(%rbp),%edi
call   1040 <streamClose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0xde0,%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,%rbp
lea    0xe35(%rip),%rdi
call   1030 <streamOpenRead@plt>
mov    %eax,%ebx
test   %eax,%eax
js     130f <main+0x15f>
mov    %ebx,%edi
call   10c0 <streamInqVlist@plt>
mov    %eax,%edi
call   1090 <vlistInqTaxis@plt>
mov    %eax,%r12d
mov    %ebx,%edi
xor    %esi,%esi
call   1070 <streamInqTimestep@plt>
mov    %r12d,%edi
call   10b0 <taxisInqVdate@plt>
mov    %rbp,(%rsp)
mov    %eax,%r15d
mov    %r12d,%edi
call   1060 <taxisInqVtime@plt>
lea    0xdfd(%rip),%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %eax,%ecx
call   1050 <printf@plt>
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
mov    %ebx,%edi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   10d0 <streamReadVar@plt>
lea    0x250(%rsp),%rbp
mov    %ebx,%edi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %r15,%rcx
call   10d0 <streamReadVar@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1070 <streamInqTimestep@plt>
mov    %r12d,%edi
call   10b0 <taxisInqVdate@plt>
mov    %eax,%r13d
mov    %r12d,%edi
call   1060 <taxisInqVtime@plt>
lea    0xd95(%rip),%rdi
mov    $0x2,%esi
mov    %r13d,%edx
mov    %eax,%ecx
call   1050 <printf@plt>
mov    %ebx,%edi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   10d0 <streamReadVar@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %r15,%rcx
call   10d0 <streamReadVar@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1070 <streamInqTimestep@plt>
mov    %r12d,%edi
call   10b0 <taxisInqVdate@plt>
mov    %eax,%r13d
mov    %r12d,%edi
call   1060 <taxisInqVtime@plt>
lea    0xd3f(%rip),%rdi
mov    $0x3,%esi
mov    %r13d,%edx
mov    %eax,%ecx
call   1050 <printf@plt>
mov    %ebx,%edi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   10d0 <streamReadVar@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %r15,%rcx
mov    (%rsp),%rbp
call   10d0 <streamReadVar@plt>
mov    %ebx,%edi
call   1040 <streamClose@plt>
xor    %eax,%eax
jmp    1337 <main+0x187>
mov    0x2cca(%rip),%rax
mov    (%rax),%r14d
mov    %ebx,%edi
call   10a0 <cdiStringError@plt>
lea    0xce4(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    $0x1,%eax
mov    %rbp,%rsp
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 = [37 x i8] c"read timestep %d: date=%d time=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = 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
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %9
%18 = alloca double, i64 72
%19 = alloca double, i64 360
%20 = call i32 @streamOpenRead(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %0
%24 = load i32, i32* @stderr
%25 = load i32, i32* %10
%26 = call i8* @cdiStringError(i32 %25)
%27 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %26)
store i32 1, i32* %1
store i32 1, i32* %11
br label %61
28: ; preds = %0
%29 = load i32, i32* %10
%30 = call i32 @streamInqVlist(i32 %29)
store i32 %30, i32* %12
store i32 0, i32* %13
store i32 1, i32* %14
%31 = load i32, i32* %12
%32 = call i32 @vlistInqTaxis(i32 %31)
store i32 %32, i32* %15
store i32 0, i32* %16
br label %33
33: ; preds = %55, %28
%34 = load i32, i32* %16
%35 = icmp slt i32 %34, 3
br i1 %35, label %36, label %58
36: ; preds = %33
%37 = load i32, i32* %10
%38 = load i32, i32* %16
%39 = call i32 @streamInqTimestep(i32 %37, i32 %38)
%40 = load i32, i32* %15
%41 = call i32 @taxisInqVdate(i32 %40)
store i32 %41, i32* %7
%42 = load i32, i32* %15
%43 = call i32 @taxisInqVtime(i32 %42)
store i32 %43, i32* %8
%44 = load i32, i32* %16
%45 = add nsw i32 %44, 1
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %45, i32 %46, i32 %47)
%49 = load i32, i32* %10
%50 = load i32, i32* %13
%51 = call i32 @streamReadVar(i32 %49, i32 %50, double* %18, i32* %6)
%52 = load i32, i32* %10
%53 = load i32, i32* %14
%54 = call i32 @streamReadVar(i32 %52, i32 %53, double* %19, i32* %6)
br label %55
55: ; preds = %36
%56 = load i32, i32* %16
%57 = add nsw i32 %56, 1
store i32 %57, i32* %16
br label %33
58: ; preds = %33
%59 = load i32, i32* %10
%60 = call i32 @streamClose(i32 %59)
store i32 0, i32* %1
store i32 1, i32* %11
br label %61
61: ; preds = %58, %23
%62 = load i8*, i8** %9
%63 = load i32, i32* %1
ret i32 %63
}

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 = [37 x i8] c"read timestep %d: date=%d time=%d\0A\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 %36
14: ; preds = %0
%15 = tail call i32 @streamInqVlist(i32 %8)
%16 = tail call i32 @vlistInqTaxis(i32 %15)
%17 = call i32 @streamInqTimestep(i32 %8, i32 0)
%18 = call i32 @taxisInqVdate(i32 %16)
%19 = call i32 @taxisInqVtime(i32 %16)
%20 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %18, i32 %19)
%21 = call i32 @streamReadVar(i32 %8, i32 0, double* %7, i32* %1)
%22 = call i32 @streamReadVar(i32 %8, i32 1, double* %6, i32* %1)
%23 = call i32 @streamInqTimestep(i32 %8, i32 1)
%24 = call i32 @taxisInqVdate(i32 %16)
%25 = call i32 @taxisInqVtime(i32 %16)
%26 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 %24, i32 %25)
%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 = call i32 @streamInqTimestep(i32 %8, i32 2)
%30 = call i32 @taxisInqVdate(i32 %16)
%31 = call i32 @taxisInqVtime(i32 %16)
%32 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 %30, i32 %31)
%33 = call i32 @streamReadVar(i32 %8, i32 0, double* %7, i32* %1)
%34 = call i32 @streamReadVar(i32 %8, i32 1, double* %6, i32* %1)
%35 = call i32 @streamClose(i32 %8)
br label %36
36: ; preds = %14, %10
%37 = phi i32 [ 1, %10 ], [ 0, %14 ]
ret i32 %37
}