#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*/ v5dCreateSimple(char *, int, int, int, int, int, char **,
                                   int *, int *, float, float, float, float,
                                   float, 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;
  char VarName[200][10];
  int TimeStamp[400];
  int DateStamp[400];
  float NorthLat;
  float LatInc;
  float WestLon;
  float LonInc;
  float BottomHgt;
  float HgtInc;
  f = fopen(infile, "r");
  if (!f) {
    printf("Error: couldn't open %s for reading\n", infile);
    exit(1);
  }
  if (!v5dCreateSimple(outfile, NumTimes, NumVars, Nr, Nc, Nl, VarName,
                       TimeStamp, DateStamp, NorthLat, LatInc, WestLon, LonInc,
                       BottomHgt, HgtInc)) {
    printf("Error: couldn't create %s\n", outfile);
    exit(1);
  }
  g = (float *)malloc(Nr * Nc * Nl * 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
sub    $0x14d0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ce <convert+0x4e>
mov    -0x10(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    -0x44(%rbp),%edx
mov    -0x48(%rbp),%ecx
mov    -0x4c(%rbp),%r8d
mov    -0x50(%rbp),%r9d
lea    -0x820(%rbp),%r11
lea    -0xe60(%rbp),%r10
lea    -0x14a0(%rbp),%rax
movss  -0x14a4(%rbp),%xmm0
ff
movss  -0x14a8(%rbp),%xmm1
ff
movss  -0x14ac(%rbp),%xmm2
ff
movss  -0x14b0(%rbp),%xmm3
ff
movss  -0x14b4(%rbp),%xmm4
ff
movss  -0x14b8(%rbp),%xmm5
ff
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <v5dCreateSimple@plt>
cmp    $0x0,%eax
jne    1260 <convert+0xe0>
mov    -0x18(%rbp),%rsi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x48(%rbp),%eax
imul   -0x4c(%rbp),%eax
imul   -0x50(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    129f <convert+0x11f>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    1321 <convert+0x1a1>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    130e <convert+0x18e>
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
mov    -0x30(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%rdx
call   1060 <v5dWrite@plt>
cmp    $0x0,%eax
jne    12fb <convert+0x17b>
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1300 <convert+0x180>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12b9 <convert+0x139>
jmp    1313 <convert+0x193>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12a6 <convert+0x126>
mov    $0x0,%al
call   1070 <v5dClose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x14d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %r15
push   %r14
push   %rbx
sub    $0x1450,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe67(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11fa <convert+0x7a>
mov    %rax,%r15
sub    $0x8,%rsp
lea    0x8(%rsp),%rax
lea    0x648(%rsp),%rcx
lea    0xc88(%rsp),%rdx
mov    %r14,%rdi
push   %rax
push   %rcx
push   %rdx
call   1050 <v5dCreateSimple@plt>
add    $0x20,%rsp
test   %eax,%eax
je     1206 <convert+0x86>
xor    %edi,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1221 <convert+0xa1>
xor    %eax,%eax
call   1070 <v5dClose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x1450,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe01(%rip),%rdi
mov    %rbx,%rsi
jmp    1210 <convert+0x90>
lea    0xe1a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe1a(%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 i32
%18 = alloca [200 x [10 x i8]]
%19 = alloca [400 x i32]
%20 = alloca [400 x i32]
%21 = alloca float
%22 = alloca float
%23 = alloca float
%24 = alloca float
%25 = alloca float
%26 = alloca float
store i8* %0, i8** %4
store i8* %1, i8** %5
%27 = load i8*, i8** %4
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %28, i32** %7
%29 = load i32*, i32** %7
%30 = icmp ne i32* %29, null
br i1 %30, label %35, label %31
31: ; preds = %2
%32 = load i8*, i8** %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %2
%36 = load i8*, i8** %5
%37 = load i32, i32* %13
%38 = load i32, i32* %14
%39 = load i32, i32* %15
%40 = load i32, i32* %16
%41 = load i32, i32* %17
%42 = getelementptr inbounds [200 x [10 x i8]], [200 x [10 x i8]]* %18, i64 0, i64 0
%43 = bitcast [10 x i8]* %42 to i8**
%44 = getelementptr inbounds [400 x i32], [400 x i32]* %19, i64 0, i64 0
%45 = getelementptr inbounds [400 x i32], [400 x i32]* %20, i64 0, i64 0
%46 = load float, float* %21
%47 = load float, float* %22
%48 = load float, float* %23
%49 = load float, float* %24
%50 = load float, float* %25
%51 = load float, float* %26
%52 = call i32 @v5dCreateSimple(i8* %36, i32 %37, i32 %38, i32 %39, i32 %40, i32 %41, i8** %43, i32* %44, i32* %45, float %46, float %47, float %48, float %49, float %50, float %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %35
%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 = %35
%59 = load i32, i32* %15
%60 = load i32, i32* %16
%61 = mul nsw i32 %59, %60
%62 = load i32, i32* %17
%63 = mul nsw i32 %61, %62
%64 = sext i32 %63 to i64
%65 = mul i64 %64, 4
%66 = trunc i64 %65 to i32
%67 = call i64 @malloc(i32 %66)
%68 = inttoptr i64 %67 to float*
store float* %68, float** %6
%69 = load float*, float** %6
%70 = icmp ne float* %69, null
br i1 %70, label %74, label %71
71: ; preds = %58
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %58
store i32 0, i32* %8
br label %75
75: ; preds = %100, %74
%76 = load i32, i32* %8
%77 = load i32, i32* %13
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %103
79: ; preds = %75
store i32 0, i32* %9
br label %80
80: ; preds = %96, %79
%81 = load i32, i32* %9
%82 = load i32, i32* %14
%83 = icmp slt i32 %81, %82
br i1 %83, label %84, label %99
84: ; preds = %80
%85 = load i32, i32* %8
%86 = add nsw i32 %85, 1
%87 = load i32, i32* %9
%88 = add nsw i32 %87, 1
%89 = load float*, float** %6
%90 = call i32 @v5dWrite(i32 %86, i32 %88, float* %89)
%91 = icmp ne i32 %90, 0
br i1 %91, label %95, label %92
92: ; preds = %84
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %84
br label %96
96: ; preds = %95
%97 = load i32, i32* %9
%98 = add nsw i32 %97, 1
store i32 %98, i32* %9
br label %80
99: ; preds = %80
br label %100
100: ; preds = %99
%101 = load i32, i32* %8
%102 = add nsw i32 %101, 1
store i32 %102, i32* %8
br label %75
103: ; preds = %75
%104 = call i32 (...) @v5dClose()
%105 = load i32*, i32** %7
%106 = call i32 @fclose(i32* %105)
%107 = load i32, i32* %3
ret i32 %107
}

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 [10 x i8]]
%4 = alloca [400 x i32]
%5 = alloca [400 x i32]
%6 = getelementptr inbounds [200 x [10 x i8]], [200 x [10 x i8]]* %3, i64 0, i64 0, i64 0
%7 = bitcast [400 x i32]* %4 to i8*
%8 = bitcast [400 x i32]* %5 to i8*
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = bitcast [200 x [10 x i8]]* %3 to i8**
%16 = getelementptr inbounds [400 x i32], [400 x i32]* %4, i64 0, i64 0
%17 = getelementptr inbounds [400 x i32], [400 x i32]* %5, i64 0, i64 0
%18 = call i32 @v5dCreateSimple(i8* %1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i8** %15, i32* %16, i32* %17, float undef, float undef, float undef, float undef, float undef, float undef)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = call i64 @malloc(i32 0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %23
%30 = call i32 (...) @v5dClose()
%31 = call i32 @fclose(i32* %9)
ret i32 undef
}