#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ v5dClose();
int /*<<< orphan*/ v5dCreate(char *, int, int, int, int, int *, char **, int *,
                             int *, int, int, float *, int, float *);
int /*<<< orphan*/ v5dWrite(int, int, float *);
int convert(char *infile, char *outfile) {
  float *g;
  FILE *f;
  int it, iv, ir, ic, il;
  int NumTimes;
  int NumVars;
  int Nr, Nc, Nl[200];
  char VarName[200][10];
  int TimeStamp[400];
  int DateStamp[400];
  int CompressMode;
  int Projection;
  float ProjArgs[100];
  int Vertical;
  float VertArgs[400];
  f = fopen(infile, "r");
  if (!f) {
    printf("Error: couldn't open %s for reading\n", infile);
    exit(1);
  }
  if (!v5dCreate(outfile, NumTimes, NumVars, Nr, Nc, Nl, VarName, TimeStamp,
                 DateStamp, CompressMode, Projection, ProjArgs, Vertical,
                 VertArgs)) {
    printf("Error: couldn't create %s\n", outfile);
    exit(1);
  }
  {
    int maxnl, i;
    maxnl = Nl[0];
    for (i = 1; i < NumVars; i++) {
      if (Nl[i] > maxnl)
        maxnl = Nl[i];
    }
    g = (float *)malloc(Nr * Nc * maxnl * sizeof(float));
    if (!g) {
      printf("Error: out of memory\n");
      exit(1);
    }
  }
  for (it = 0; it < NumTimes; it++) {
    for (iv = 0; iv < NumVars; iv++) {
      if (!v5dWrite(it + 1, iv + 1, g)) {
        printf("Error while writing grid.  Disk full?\n");
        exit(1);
      }
    }
  }
  v5dClose();
  fclose(f);
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2008,%rsp
mov    %rdi,-0x38(%rbp)
mov    %rsi,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    11d7 <convert+0x57>
mov    -0x38(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x68(%rbp),%esi
mov    -0x6c(%rbp),%edx
mov    -0x70(%rbp),%ecx
mov    -0x74(%rbp),%r8d
lea    -0x3a0(%rbp),%r9
lea    -0xb70(%rbp),%r13
lea    -0x11b0(%rbp),%r12
lea    -0x17f0(%rbp),%r15
mov    -0x17f4(%rbp),%r14d
mov    -0x17f8(%rbp),%ebx
lea    -0x1990(%rbp),%r11
mov    -0x1994(%rbp),%r10d
lea    -0x1fe0(%rbp),%rax
mov    %r13,(%rsp)
mov    %r12,0x8(%rsp)
mov    %r15,0x10(%rsp)
mov    %r14d,0x18(%rsp)
mov    %ebx,0x20(%rsp)
mov    %r11,0x28(%rsp)
mov    %r10d,0x30(%rsp)
mov    %rax,0x38(%rsp)
call   1040 <v5dCreate@plt>
cmp    $0x0,%eax
jne    1276 <convert+0xf6>
mov    -0x40(%rbp),%rsi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x3a0(%rbp),%eax
mov    %eax,-0x1fe4(%rbp)
movl   $0x1,-0x1fe8(%rbp)
mov    -0x1fe8(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jge    12e2 <convert+0x162>
movslq -0x1fe8(%rbp),%rax
mov    -0x3a0(%rbp,%rax,4),%eax
cmp    -0x1fe4(%rbp),%eax
jle    12c9 <convert+0x149>
movslq -0x1fe8(%rbp),%rax
mov    -0x3a0(%rbp,%rax,4),%eax
mov    %eax,-0x1fe4(%rbp)
jmp    12ce <convert+0x14e>
mov    -0x1fe8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1fe8(%rbp)
jmp    128c <convert+0x10c>
mov    -0x70(%rbp),%eax
imul   -0x74(%rbp),%eax
imul   -0x1fe4(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1324 <convert+0x1a4>
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x68(%rbp),%eax
jge    13a6 <convert+0x226>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jge    1393 <convert+0x213>
mov    -0x54(%rbp),%edi
add    $0x1,%edi
mov    -0x58(%rbp),%esi
add    $0x1,%esi
mov    -0x48(%rbp),%rdx
call   1060 <v5dWrite@plt>
cmp    $0x0,%eax
jne    1380 <convert+0x200>
lea    0xce9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1385 <convert+0x205>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    133e <convert+0x1be>
jmp    1398 <convert+0x218>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    132b <convert+0x1ab>
mov    $0x0,%al
call   1070 <v5dClose@plt>
mov    -0x50(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%eax
add    $0x2008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %r15
push   %r14
push   %rbx
sub    $0x1f80,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe67(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     121f <convert+0x9f>
mov    %rax,%r15
lea    0x4f0(%rsp),%rax
mov    %rax,0x38(%rsp)
lea    0x40(%rsp),%rax
mov    %rax,0x28(%rsp)
lea    0xb30(%rsp),%rax
mov    %rax,0x10(%rsp)
lea    0x1170(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0x17b0(%rsp),%rax
mov    %rax,(%rsp)
lea    0x1d0(%rsp),%r9
mov    %r14,%rdi
call   1050 <v5dCreate@plt>
test   %eax,%eax
je     122b <convert+0xab>
xor    %edi,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1246 <convert+0xc6>
xor    %eax,%eax
call   1070 <v5dClose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x1f80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xddc(%rip),%rdi
mov    %rbx,%rsi
jmp    1235 <convert+0xb5>
lea    0xdf5(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdf5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [37 x i8] c"Error: couldn't open %s for reading\0A\00"
@.str.2 = [27 x i8] c"Error: couldn't create %s\0A\00"
@.str.3 = [22 x i8] c"Error: out of memory\0A\00"
@.str.4 = [39 x i8] c"Error while writing grid. Disk full?\0A\00"
define i32 @convert(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca float*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca [200 x i32]
%18 = alloca [200 x [10 x i8]]
%19 = alloca [400 x i32]
%20 = alloca [400 x i32]
%21 = alloca i32
%22 = alloca i32
%23 = alloca [100 x float]
%24 = alloca i32
%25 = alloca [400 x float]
%26 = alloca i32
%27 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%28 = load i8*, i8** %4
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %29, i32** %7
%30 = load i32*, i32** %7
%31 = icmp ne i32* %30, null
br i1 %31, label %36, label %32
32: ; preds = %2
%33 = load i8*, i8** %4
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %2
%37 = load i8*, i8** %5
%38 = load i32, i32* %13
%39 = load i32, i32* %14
%40 = load i32, i32* %15
%41 = load i32, i32* %16
%42 = getelementptr inbounds [200 x i32], [200 x i32]* %17, i64 0, i64 0
%43 = getelementptr inbounds [200 x [10 x i8]], [200 x [10 x i8]]* %18, i64 0, i64 0
%44 = bitcast [10 x i8]* %43 to i8**
%45 = getelementptr inbounds [400 x i32], [400 x i32]* %19, i64 0, i64 0
%46 = getelementptr inbounds [400 x i32], [400 x i32]* %20, i64 0, i64 0
%47 = load i32, i32* %21
%48 = load i32, i32* %22
%49 = getelementptr inbounds [100 x float], [100 x float]* %23, i64 0, i64 0
%50 = load i32, i32* %24
%51 = getelementptr inbounds [400 x float], [400 x float]* %25, i64 0, i64 0
%52 = call i32 @v5dCreate(i8* %37, i32 %38, i32 %39, i32 %40, i32 %41, i32* %42, i8** %44, i32* %45, i32* %46, i32 %47, i32 %48, float* %49, i32 %50, float* %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %36
%55 = load i8*, i8** %5
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %36
%59 = getelementptr inbounds [200 x i32], [200 x i32]* %17, i64 0, i64 0
%60 = load i32, i32* %59
store i32 %60, i32* %26
store i32 1, i32* %27
br label %61
61: ; preds = %78, %58
%62 = load i32, i32* %27
%63 = load i32, i32* %14
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %81
65: ; preds = %61
%66 = load i32, i32* %27
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [200 x i32], [200 x i32]* %17, i64 0, i64 %67
%69 = load i32, i32* %68
%70 = load i32, i32* %26
%71 = icmp sgt i32 %69, %70
br i1 %71, label %72, label %77
72: ; preds = %65
%73 = load i32, i32* %27
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [200 x i32], [200 x i32]* %17, i64 0, i64 %74
%76 = load i32, i32* %75
store i32 %76, i32* %26
br label %77
77: ; preds = %72, %65
br label %78
78: ; preds = %77
%79 = load i32, i32* %27
%80 = add nsw i32 %79, 1
store i32 %80, i32* %27
br label %61
81: ; preds = %61
%82 = load i32, i32* %15
%83 = load i32, i32* %16
%84 = mul nsw i32 %82, %83
%85 = load i32, i32* %26
%86 = mul nsw i32 %84, %85
%87 = sext i32 %86 to i64
%88 = mul i64 %87, 4
%89 = trunc i64 %88 to i32
%90 = call i64 @malloc(i32 %89)
%91 = inttoptr i64 %90 to float*
store float* %91, float** %6
%92 = load float*, float** %6
%93 = icmp ne float* %92, null
br i1 %93, label %97, label %94
94: ; preds = %81
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %81
store i32 0, i32* %8
br label %98
98: ; preds = %123, %97
%99 = load i32, i32* %8
%100 = load i32, i32* %13
%101 = icmp slt i32 %99, %100
br i1 %101, label %102, label %126
102: ; preds = %98
store i32 0, i32* %9
br label %103
103: ; preds = %119, %102
%104 = load i32, i32* %9
%105 = load i32, i32* %14
%106 = icmp slt i32 %104, %105
br i1 %106, label %107, label %122
107: ; preds = %103
%108 = load i32, i32* %8
%109 = add nsw i32 %108, 1
%110 = load i32, i32* %9
%111 = add nsw i32 %110, 1
%112 = load float*, float** %6
%113 = call i32 @v5dWrite(i32 %109, i32 %111, float* %112)
%114 = icmp ne i32 %113, 0
br i1 %114, label %118, label %115
115: ; preds = %107
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %107
br label %119
119: ; preds = %118
%120 = load i32, i32* %9
%121 = add nsw i32 %120, 1
store i32 %121, i32* %9
br label %103
122: ; preds = %103
br label %123
123: ; preds = %122
%124 = load i32, i32* %8
%125 = add nsw i32 %124, 1
store i32 %125, i32* %8
br label %98
126: ; preds = %98
%127 = call i32 (...) @v5dClose()
%128 = load i32*, i32** %7
%129 = call i32 @fclose(i32* %128)
%130 = load i32, i32* %3
ret i32 %130
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [37 x i8] c"Error: couldn't open %s for reading\0A\00"
@.str.2 = [27 x i8] c"Error: couldn't create %s\0A\00"
@str = [21 x i8] c"Error: out of memory\00"
define i32 @convert(i8* %0, i8* %1) {
%3 = alloca [200 x i32]
%4 = alloca [200 x [10 x i8]]
%5 = alloca [400 x i32]
%6 = alloca [400 x i32]
%7 = alloca [100 x float]
%8 = alloca [400 x float]
%9 = bitcast [200 x i32]* %3 to i8*
%10 = getelementptr inbounds [200 x [10 x i8]], [200 x [10 x i8]]* %4, i64 0, i64 0, i64 0
%11 = bitcast [400 x i32]* %5 to i8*
%12 = bitcast [400 x i32]* %6 to i8*
%13 = bitcast [100 x float]* %7 to i8*
%14 = bitcast [400 x float]* %8 to i8*
%15 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds [200 x i32], [200 x i32]* %3, i64 0, i64 0
%22 = bitcast [200 x [10 x i8]]* %4 to i8**
%23 = getelementptr inbounds [400 x i32], [400 x i32]* %5, i64 0, i64 0
%24 = getelementptr inbounds [400 x i32], [400 x i32]* %6, i64 0, i64 0
%25 = getelementptr inbounds [100 x float], [100 x float]* %7, i64 0, i64 0
%26 = getelementptr inbounds [400 x float], [400 x float]* %8, i64 0, i64 0
%27 = call i32 @v5dCreate(i8* %1, i32 undef, i32 undef, i32 undef, i32 undef, i32* %21, i8** %22, i32* %23, i32* %24, i32 undef, i32 undef, float* %25, i32 undef, float* %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %20
%33 = call i64 @malloc(i32 0)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %32
%39 = call i32 (...) @v5dClose()
%40 = call i32 @fclose(i32* %15)
ret i32 undef
}