#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int write_avs(char *, float *, int, float, float, float, float, float, float);
int write_phi_grid(char *, int, float *, float, float, float, float);
int write_grid(char *filename, int dim, float *grid, float cen_x, float cen_y,
               float cen_z, float wid) {
  const int DELPHI_FORMAT = 0;
  const int MEAD_FORMAT = 1;
  const int BAD_ARGS = -1;
  const int FILE_PROBLEMS = 0;
  const int SUCCESS = 1;
  int format, length, ret_val;
  char *finalname = NULL;
  float min_x, min_y, min_z, max_x, max_y, max_z;
  if (filename == NULL) {
    fprintf(stderr, "error in write_grid, null filename\n");
    return BAD_ARGS;
  }
  length = strlen(filename);
  if ((length < 5) || (filename[length - 1] == '/')) {
    fprintf(stderr, "Error in write_grid, grid is not a discernable file type "
                    "or it is a directory\n");
    return BAD_ARGS;
  }
  if (filename[length - 4] == '.') {
    if (strcmp(&filename[length - 4], ".fld") == 0) {
      finalname = (char *)malloc(length * sizeof(char));
      strcpy(finalname, filename);
      format = MEAD_FORMAT;
    } else if (strcmp(&filename[length - 4], ".phi") == 0) {
      finalname = (char *)malloc(length * sizeof(char));
      strcpy(finalname, filename);
      format = DELPHI_FORMAT;
    } else {
      finalname = (char *)malloc((length + 4) * sizeof(char));
      sprintf(finalname, "%s.phi", filename);
      format = DELPHI_FORMAT;
    }
  } else {
    finalname = (char *)malloc((length + 4) * sizeof(char));
    sprintf(finalname, "%s.phi", filename);
    format = DELPHI_FORMAT;
  }
  printf("Saving phimap file >%s< in %s format\n", finalname,
         ((format == DELPHI_FORMAT) ? "DelPhi" : "MEAD"));
  if (format == DELPHI_FORMAT) {
    ret_val = write_phi_grid(finalname, dim, grid, (wid) / (float)(dim - 1),
                             cen_x, cen_y, cen_z);
    if (!ret_val)
      return FILE_PROBLEMS;
  } else {
    min_x = cen_x - (wid / 2.);
    min_y = cen_y - (wid / 2.);
    min_z = cen_z - (wid / 2.);
    max_x = cen_x + (wid / 2.);
    max_y = cen_y + (wid / 2.);
    max_z = cen_z + (wid / 2.);
    ret_val = write_avs(finalname, grid, dim, min_x, min_y, min_z, max_x, max_y,
                        max_z);
    if (!ret_val)
      return FILE_PROBLEMS;
  }
  return SUCCESS;
}


x86 assembly (clang, -O0):
<write_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movss  %xmm0,-0x24(%rbp)
movss  %xmm1,-0x28(%rbp)
movss  %xmm2,-0x2c(%rbp)
movss  %xmm3,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
movq   $0x0,-0x58(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    120e <write_grid+0x7e>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1560 <write_grid+0x3d0>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x5,-0x4c(%rbp)
jl     123e <write_grid+0xae>
mov    -0x10(%rbp),%rax
mov    -0x4c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    125f <write_grid+0xcf>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1560 <write_grid+0x3d0>
mov    -0x10(%rbp),%rax
mov    -0x4c(%rbp),%ecx
sub    $0x4,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1357 <write_grid+0x1c7>
mov    -0x10(%rbp),%rdi
mov    -0x4c(%rbp),%eax
sub    $0x4,%eax
cltq
add    %rax,%rdi
lea    0xdec(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12ca <write_grid+0x13a>
movslq -0x4c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x48(%rbp)
jmp    1352 <write_grid+0x1c2>
mov    -0x10(%rbp),%rdi
mov    -0x4c(%rbp),%eax
sub    $0x4,%eax
cltq
add    %rax,%rdi
lea    0xda2(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    131b <write_grid+0x18b>
movslq -0x4c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x48(%rbp)
jmp    134d <write_grid+0x1bd>
mov    -0x4c(%rbp),%eax
add    $0x4,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd3f(%rip),%rsi
call   10b0 <sprintf@plt>
movl   $0x0,-0x48(%rbp)
jmp    1352 <write_grid+0x1c2>
jmp    1389 <write_grid+0x1f9>
mov    -0x4c(%rbp),%eax
add    $0x4,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd03(%rip),%rsi
call   10b0 <sprintf@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x58(%rbp),%rsi
mov    -0x48(%rbp),%ecx
lea    0xd1d(%rip),%rdx
lea    0xd0f(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rdx
lea    0xcdb(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x0,-0x48(%rbp)
jne    140b <write_grid+0x27b>
mov    -0x58(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
movss  -0x30(%rbp),%xmm0
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
movss  -0x24(%rbp),%xmm1
movss  -0x28(%rbp),%xmm2
movss  -0x2c(%rbp),%xmm3
call   1060 <write_phi_grid@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jne    1406 <write_grid+0x276>
movl   $0x0,-0x4(%rbp)
jmp    1560 <write_grid+0x3d0>
jmp    1559 <write_grid+0x3c9>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x30(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xbdb(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x5c(%rbp)
movss  -0x28(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x30(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xbb0(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x60(%rbp)
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x30(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xb85(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x64(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x30(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xb5a(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x68(%rbp)
movss  -0x28(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x30(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xb2f(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x6c(%rbp)
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x30(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xb04(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x70(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
movss  -0x5c(%rbp),%xmm0
movss  -0x60(%rbp),%xmm1
movss  -0x64(%rbp),%xmm2
movss  -0x68(%rbp),%xmm3
movss  -0x6c(%rbp),%xmm4
movss  -0x70(%rbp),%xmm5
call   10a0 <write_avs@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jne    1554 <write_grid+0x3c4>
movl   $0x0,-0x4(%rbp)
jmp    1560 <write_grid+0x3d0>
jmp    1559 <write_grid+0x3c9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_grid>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     11ec <write_grid+0x5c>
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
movss  %xmm0,(%rsp)
movss  %xmm3,0x4(%rsp)
movss  %xmm1,0x8(%rsp)
movss  %xmm2,0xc(%rsp)
call   1040 <strlen@plt>
cmp    $0x5,%eax
jl     11da <write_grid+0x4a>
mov    %eax,%r12d
lea    -0x1(%r12),%eax
cmpb   $0x2f,(%rbx,%rax,1)
jne    1214 <write_grid+0x84>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
jmp    11fc <write_grid+0x6c>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    -0x4(%r12),%r13d
cmpb   $0x2e,(%rbx,%r13,1)
jne    1253 <write_grid+0xc3>
add    %rbx,%r13
lea    0xe51(%rip),%rsi
mov    %r13,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12d0 <write_grid+0x140>
lea    0xe40(%rip),%rsi
mov    %r13,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1385 <write_grid+0x1f5>
add    $0x4,%r12d
mov    %r12d,%edi
call   1090 <malloc@plt>
mov    %rax,%r12
lea    0xe17(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   10b0 <sprintf@plt>
lea    0xe0c(%rip),%rdi
lea    0xe2b(%rip),%rdx
mov    %r12,%rsi
call   1050 <printf@plt>
lea    -0x1(%r15),%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
movss  0x4(%rsp),%xmm0
divss  %xmm1,%xmm0
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
movss  (%rsp),%xmm1
movss  0x8(%rsp),%xmm2
movss  0xc(%rsp),%xmm3
call   1060 <write_phi_grid@plt>
test   %eax,%eax
je     137e <write_grid+0x1ee>
mov    $0x1,%eax
jmp    1206 <write_grid+0x76>
mov    %r12d,%edi
call   1090 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xd9a(%rip),%rdi
lea    0xdc0(%rip),%rdx
mov    %r12,%rsi
call   1050 <printf@plt>
movss  (%rsp),%xmm0
xorps  %xmm3,%xmm3
cvtss2sd %xmm0,%xmm3
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm5
mulsd  0xce6(%rip),%xmm5
movaps %xmm3,%xmm0
subsd  %xmm5,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  0x8(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
movapd %xmm5,%xmm4
addsd  %xmm1,%xmm4
subsd  %xmm5,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  0xc(%rsp),%xmm2
cvtss2sd %xmm2,%xmm6
movaps %xmm6,%xmm2
subsd  %xmm5,%xmm2
cvtsd2ss %xmm2,%xmm2
addsd  %xmm5,%xmm3
cvtsd2ss %xmm3,%xmm3
cvtsd2ss %xmm4,%xmm4
addsd  %xmm6,%xmm5
cvtsd2ss %xmm5,%xmm5
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   10a0 <write_avs@plt>
test   %eax,%eax
jne    12c6 <write_grid+0x136>
xor    %eax,%eax
jmp    1206 <write_grid+0x76>
mov    %r12d,%edi
call   1090 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    1274 <write_grid+0xe4>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"error in write_grid, null filename\0A\00"
@.str.1 = [79 x i8] c"Error in write_grid, grid is not a discernable file type or it is a directory\0A\00"
@.str.2 = [5 x i8] c".fld\00"
@.str.3 = [5 x i8] c".phi\00"
@.str.4 = [7 x i8] c"%s.phi\00"
@.str.5 = [38 x i8] c"Saving phimap file >%s< in %s format\0A\00"
@.str.6 = [7 x i8] c"DelPhi\00"
@.str.7 = [5 x i8] c"MEAD\00"
define i32 @write_grid(i8* %0, i32 %1, float* %2, float %3, float %4, float %5, float %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca float*
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca float
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i8*
%25 = alloca float
%26 = alloca float
%27 = alloca float
%28 = alloca float
%29 = alloca float
%30 = alloca float
store i8* %0, i8** %9
store i32 %1, i32* %10
store float* %2, float** %11
store float %3, float* %12
store float %4, float* %13
store float %5, float* %14
store float %6, float* %15
store i32 0, i32* %16
store i32 1, i32* %17
store i32 -1, i32* %18
store i32 0, i32* %19
store i32 1, i32* %20
store i8* null, i8** %24
%31 = load i8*, i8** %9
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %36
33: ; preds = %7
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %8
br label %206
36: ; preds = %7
%37 = load i8*, i8** %9
%38 = call i32 @strlen(i8* %37)
store i32 %38, i32* %22
%39 = load i32, i32* %22
%40 = icmp slt i32 %39, 5
br i1 %40, label %50, label %41
41: ; preds = %36
%42 = load i8*, i8** %9
%43 = load i32, i32* %22
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 47
br i1 %49, label %50, label %53
50: ; preds = %41, %36
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %8
br label %206
53: ; preds = %41
%54 = load i8*, i8** %9
%55 = load i32, i32* %22
%56 = sub nsw i32 %55, 4
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %54, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 46
br i1 %61, label %62, label %111
62: ; preds = %53
%63 = load i8*, i8** %9
%64 = load i32, i32* %22
%65 = sub nsw i32 %64, 4
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %63, i64 %66
%68 = call i64 @strcmp(i8* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %80
70: ; preds = %62
%71 = load i32, i32* %22
%72 = sext i32 %71 to i64
%73 = mul i64 %72, 1
%74 = trunc i64 %73 to i32
%75 = call i64 @malloc(i32 %74)
%76 = inttoptr i64 %75 to i8*
store i8* %76, i8** %24
%77 = load i8*, i8** %24
%78 = load i8*, i8** %9
%79 = call i32 @strcpy(i8* %77, i8* %78)
store i32 1, i32* %21
br label %110
80: ; preds = %62
%81 = load i8*, i8** %9
%82 = load i32, i32* %22
%83 = sub nsw i32 %82, 4
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %81, i64 %84
%86 = call i64 @strcmp(i8* %85, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%87 = icmp eq i64 %86, 0
br i1 %87, label %88, label %98
88: ; preds = %80
%89 = load i32, i32* %22
%90 = sext i32 %89 to i64
%91 = mul i64 %90, 1
%92 = trunc i64 %91 to i32
%93 = call i64 @malloc(i32 %92)
%94 = inttoptr i64 %93 to i8*
store i8* %94, i8** %24
%95 = load i8*, i8** %24
%96 = load i8*, i8** %9
%97 = call i32 @strcpy(i8* %95, i8* %96)
store i32 0, i32* %21
br label %109
98: ; preds = %80
%99 = load i32, i32* %22
%100 = add nsw i32 %99, 4
%101 = sext i32 %100 to i64
%102 = mul i64 %101, 1
%103 = trunc i64 %102 to i32
%104 = call i64 @malloc(i32 %103)
%105 = inttoptr i64 %104 to i8*
store i8* %105, i8** %24
%106 = load i8*, i8** %24
%107 = load i8*, i8** %9
%108 = call i32 @sprintf(i8* %106, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %107)
store i32 0, i32* %21
br label %109
109: ; preds = %98, %88
br label %110
110: ; preds = %109, %70
br label %122
111: ; preds = %53
%112 = load i32, i32* %22
%113 = add nsw i32 %112, 4
%114 = sext i32 %113 to i64
%115 = mul i64 %114, 1
%116 = trunc i64 %115 to i32
%117 = call i64 @malloc(i32 %116)
%118 = inttoptr i64 %117 to i8*
store i8* %118, i8** %24
%119 = load i8*, i8** %24
%120 = load i8*, i8** %9
%121 = call i32 @sprintf(i8* %119, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %120)
store i32 0, i32* %21
br label %122
122: ; preds = %111, %110
%123 = load i8*, i8** %24
%124 = load i32, i32* %21
%125 = icmp eq i32 %124, 0
%126 = zext i1 %125 to i64
%127 = select i1 %125, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0)
%128 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %123, i8* %127)
%129 = load i32, i32* %21
%130 = icmp eq i32 %129, 0
br i1 %130, label %131, label %148
131: ; preds = %122
%132 = load i8*, i8** %24
%133 = load i32, i32* %10
%134 = load float*, float** %11
%135 = load float, float* %15
%136 = load i32, i32* %10
%137 = sub nsw i32 %136, 1
%138 = sitofp i32 %137 to float
%139 = fdiv float %135, %138
%140 = load float, float* %12
%141 = load float, float* %13
%142 = load float, float* %14
%143 = call i32 @write_phi_grid(i8* %132, i32 %133, float* %134, float %139, float %140, float %141, float %142)
store i32 %143, i32* %23
%144 = load i32, i32* %23
%145 = icmp ne i32 %144, 0
br i1 %145, label %147, label %146
146: ; preds = %131
store i32 0, i32* %8
br label %206
147: ; preds = %131
br label %205
148: ; preds = %122
%149 = load float, float* %12
%150 = fpext float %149 to double
%151 = load float, float* %15
%152 = fpext float %151 to double
%153 = fdiv double %152, 2.000000e+00
%154 = fsub double %150, %153
%155 = fptrunc double %154 to float
store float %155, float* %25
%156 = load float, float* %13
%157 = fpext float %156 to double
%158 = load float, float* %15
%159 = fpext float %158 to double
%160 = fdiv double %159, 2.000000e+00
%161 = fsub double %157, %160
%162 = fptrunc double %161 to float
store float %162, float* %26
%163 = load float, float* %14
%164 = fpext float %163 to double
%165 = load float, float* %15
%166 = fpext float %165 to double
%167 = fdiv double %166, 2.000000e+00
%168 = fsub double %164, %167
%169 = fptrunc double %168 to float
store float %169, float* %27
%170 = load float, float* %12
%171 = fpext float %170 to double
%172 = load float, float* %15
%173 = fpext float %172 to double
%174 = fdiv double %173, 2.000000e+00
%175 = fadd double %171, %174
%176 = fptrunc double %175 to float
store float %176, float* %28
%177 = load float, float* %13
%178 = fpext float %177 to double
%179 = load float, float* %15
%180 = fpext float %179 to double
%181 = fdiv double %180, 2.000000e+00
%182 = fadd double %178, %181
%183 = fptrunc double %182 to float
store float %183, float* %29
%184 = load float, float* %14
%185 = fpext float %184 to double
%186 = load float, float* %15
%187 = fpext float %186 to double
%188 = fdiv double %187, 2.000000e+00
%189 = fadd double %185, %188
%190 = fptrunc double %189 to float
store float %190, float* %30
%191 = load i8*, i8** %24
%192 = load float*, float** %11
%193 = load i32, i32* %10
%194 = load float, float* %25
%195 = load float, float* %26
%196 = load float, float* %27
%197 = load float, float* %28
%198 = load float, float* %29
%199 = load float, float* %30
%200 = call i32 @write_avs(i8* %191, float* %192, i32 %193, float %194, float %195, float %196, float %197, float %198, float %199)
store i32 %200, i32* %23
%201 = load i32, i32* %23
%202 = icmp ne i32 %201, 0
br i1 %202, label %204, label %203
203: ; preds = %148
store i32 0, i32* %8
br label %206
204: ; preds = %148
br label %205
205: ; preds = %204, %147
store i32 1, i32* %8
br label %206
206: ; preds = %205, %203, %146, %50, %33
%207 = load i32, i32* %8
ret i32 %207
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"error in write_grid, null filename\0A\00"
@.str.1 = [79 x i8] c"Error in write_grid, grid is not a discernable file type or it is a directory\0A\00"
@.str.2 = [5 x i8] c".fld\00"
@.str.3 = [5 x i8] c".phi\00"
@.str.4 = [7 x i8] c"%s.phi\00"
@.str.5 = [38 x i8] c"Saving phimap file >%s< in %s format\0A\00"
@.str.6 = [7 x i8] c"DelPhi\00"
@.str.7 = [5 x i8] c"MEAD\00"
define i32 @write_grid(i8* %0, i32 %1, float* %2, float %3, float %4, float %5, float %6) {
%8 = icmp eq i8* %0, null
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %83
12: ; preds = %7
%13 = tail call i32 @strlen(i8* %0)
%14 = icmp slt i32 %13, 5
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = add nsw i32 %13, -1
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 47
br i1 %20, label %21, label %24
21: ; preds = %15, %12
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0))
br label %83
24: ; preds = %15
%25 = add nsw i32 %13, -4
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 46
br i1 %29, label %30, label %45
30: ; preds = %24
%31 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %58, label %33
33: ; preds = %30
%34 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = tail call i64 @malloc(i32 %13)
%38 = inttoptr i64 %37 to i8*
%39 = tail call i32 @strcpy(i8* %38, i8* %0)
br label %50
40: ; preds = %33
%41 = add nuw nsw i32 %13, 4
%42 = tail call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i8*
%44 = tail call i32 @sprintf(i8* dereferenceable(1) %43, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %50
45: ; preds = %24
%46 = add nuw nsw i32 %13, 4
%47 = tail call i64 @malloc(i32 %46)
%48 = inttoptr i64 %47 to i8*
%49 = tail call i32 @sprintf(i8* dereferenceable(1) %48, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %50
50: ; preds = %36, %40, %45
%51 = phi i8* [ %38, %36 ], [ %43, %40 ], [ %48, %45 ]
%52 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %51, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%53 = add nsw i32 %1, -1
%54 = sitofp i32 %53 to float
%55 = fdiv float %6, %54
%56 = tail call i32 @write_phi_grid(i8* %51, i32 %1, float* %2, float %55, float %3, float %4, float %5)
%57 = icmp eq i32 %56, 0
br i1 %57, label %83, label %82
58: ; preds = %30
%59 = tail call i64 @malloc(i32 %13)
%60 = inttoptr i64 %59 to i8*
%61 = tail call i32 @strcpy(i8* %60, i8* %0)
%62 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%63 = fpext float %3 to double
%64 = fpext float %6 to double
%65 = fmul double %64, 5.000000e-01
%66 = fsub double %63, %65
%67 = fptrunc double %66 to float
%68 = fpext float %4 to double
%69 = fsub double %68, %65
%70 = fptrunc double %69 to float
%71 = fpext float %5 to double
%72 = fsub double %71, %65
%73 = fptrunc double %72 to float
%74 = fadd double %65, %63
%75 = fptrunc double %74 to float
%76 = fadd double %65, %68
%77 = fptrunc double %76 to float
%78 = fadd double %65, %71
%79 = fptrunc double %78 to float
%80 = tail call i32 @write_avs(i8* %60, float* %2, i32 %1, float %67, float %70, float %73, float %75, float %77, float %79)
%81 = icmp eq i32 %80, 0
br i1 %81, label %83, label %82
82: ; preds = %58, %50
br label %83
83: ; preds = %58, %50, %82, %21, %9
%84 = phi i32 [ -1, %9 ], [ -1, %21 ], [ 1, %82 ], [ 0, %50 ], [ 0, %58 ]
ret i32 %84
}