#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*/ mode_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
double **alloc_doublematrix(int, int);
int /*<<< orphan*/ calc_psi_zeta(double **, double **, double **, double **,
                                 char **, int, int, double, double);
int /*<<< orphan*/ fabs(double);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free_matrix(double **);
int /*<<< orphan*/ mkdir(char *, int);
int pow(int /*<<< orphan*/, double);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ umask(int /*<<< orphan*/);
void write_ppm(double **u, double **v, double **p, char **flag, int imax,
               int jmax, double xlength, double ylength, char *outname,
               int iters, int freq) {
  int i, j;
  double zmax = -1e10, zmin = 1e10;
  double pmax = -1e10, pmin = 1e10;
  double umax = -1e10, umin = 1e10;
  double vmax = -1e10, vmin = 1e10;
  char outfile[64];
  sprintf(outfile, "%s/%06d.ppm", outname, (iters / freq));
  mode_t process_mask = umask(0);
  mkdir(outname, S_IRWXU | S_IRWXG | S_IRWXO);
  umask(process_mask);
  FILE *fout = fopen(outfile, "wb");
  if (!fout) {
    fprintf(stderr, "Could not open '%s'\n", outfile);
    return;
  }
  double delx = xlength / imax;
  double dely = ylength / jmax;
  int outmode = 0;
  double **psi;
  double **zeta;
  if (outmode == 0 || outmode == 1) {
    if (outmode == 1) {
      psi = alloc_doublematrix(imax + 2, jmax + 2);
    } else {
      zeta = alloc_doublematrix(imax + 2, jmax + 2);
    }
    calc_psi_zeta(u, v, psi, zeta, flag, imax, jmax, delx, dely);
  } else {
    for (j = 1; j < jmax + 1; j++) {
      for (i = 1; i < imax + 1; i++) {
        if (flag[i][j] & 0x0010) {
          pmax = (((pmax) > (p[i][j])) ? (pmax) : (p[i][j]));
          pmin = (((pmin) < (p[i][j])) ? (pmin) : (p[i][j]));
        }
      }
    }
  }
  fprintf(fout, "P6 %d %d 255\n", imax, jmax);
  for (j = 1; j < jmax + 1; j++) {
    for (i = 1; i < imax + 1; i++) {
      int r, g, b;
      if (!(flag[i][j] & 0x0010)) {
        r = 0;
        b = 0;
        g = 255;
      } else {
        if (outmode == 0) {
          double z = (i < imax && j < jmax) ? zeta[i][j] : 0.0;
          r = g = b = pow(fabs(z / 12.6), .4) * 255;
        } else if (outmode == 1) {
          double p = (i < imax && j < jmax) ? psi[i][j] : 0.0;
          r = g = b = (p + 3.0) / 7.5 * 255;
        } else if (outmode == 2) {
          r = g = b = (p[i][j] - pmin) / (pmax - pmin) * 255;
        }
      }
      fprintf(fout, "%c%c%c", r, g, b);
    }
  }
  fclose(fout);
  if (outmode == 1) {
    free_matrix(psi);
  }
  if (outmode == 0) {
    free_matrix(zeta);
  }
}


x86 assembly (clang, -O0):
<write_ppm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
movsd  %xmm1,-0x38(%rbp)
movsd  0xe19(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe04(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xdff(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xdea(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xde5(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xdd0(%rip),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xdcb(%rip),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xdb6(%rip),%xmm0
movsd  %xmm0,-0x80(%rbp)
lea    -0xc0(%rbp),%rdi
mov    0x10(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    0x18(%rbp),%eax
cltd
idivl  0x20(%rbp)
mov    -0x120(%rbp),%rdx
mov    %eax,%ecx
lea    0xdc0(%rip),%rsi
call   10d0 <sprintf@plt>
xor    %edi,%edi
call   1080 <umask@plt>
mov    %eax,-0xc4(%rbp)
mov    0x10(%rbp),%rdi
mov    0x2d4b(%rip),%rax
mov    (%rax),%esi
mov    0x2d3a(%rip),%rax
or     (%rax),%esi
mov    0x2d49(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
mov    -0xc4(%rbp),%edi
call   1080 <umask@plt>
lea    -0xc0(%rbp),%rdi
lea    0xd7d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0xd0(%rbp)
cmpq   $0x0,-0xd0(%rbp)
jne    1305 <write_ppm+0x155>
mov    0x2ce0(%rip),%rax
movslq (%rax),%rdi
lea    -0xc0(%rbp),%rdx
lea    0xd4e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    17e3 <write_ppm+0x633>
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xd8(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xe0(%rbp)
ff
movl   $0x0,-0xe4(%rbp)
cmpl   $0x0,-0xe4(%rbp)
je     1355 <write_ppm+0x1a5>
cmpl   $0x1,-0xe4(%rbp)
jne    13d5 <write_ppm+0x225>
cmpl   $0x1,-0xe4(%rbp)
jne    137f <write_ppm+0x1cf>
mov    -0x24(%rbp),%edi
add    $0x2,%edi
mov    -0x28(%rbp),%esi
add    $0x2,%esi
call   10c0 <alloc_doublematrix@plt>
mov    %rax,-0xf0(%rbp)
jmp    1397 <write_ppm+0x1e7>
mov    -0x24(%rbp),%edi
add    $0x2,%edi
mov    -0x28(%rbp),%esi
add    $0x2,%esi
call   10c0 <alloc_doublematrix@plt>
mov    %rax,-0xf8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0xf0(%rbp),%rdx
mov    -0xf8(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
mov    -0x28(%rbp),%eax
movsd  -0xd8(%rbp),%xmm0
ff
movsd  -0xe0(%rbp),%xmm1
ff
mov    %eax,(%rsp)
call   1090 <calc_psi_zeta@plt>
jmp    150c <write_ppm+0x35c>
movl   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1507 <write_ppm+0x357>
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    14f4 <write_ppm+0x344>
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x40(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     14e1 <write_ppm+0x331>
movsd  -0x58(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x40(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jbe    1457 <write_ppm+0x2a7>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x128(%rbp)
ff
jmp    1474 <write_ppm+0x2c4>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x128(%rbp)
ff
movsd  -0x128(%rbp),%xmm0
ff
movsd  %xmm0,-0x58(%rbp)
movsd  -0x60(%rbp),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    14b7 <write_ppm+0x307>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x130(%rbp)
ff
jmp    14d4 <write_ppm+0x324>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x130(%rbp)
ff
movsd  -0x130(%rbp),%xmm0
ff
movsd  %xmm0,-0x60(%rbp)
jmp    14e6 <write_ppm+0x336>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    13f4 <write_ppm+0x244>
jmp    14f9 <write_ppm+0x349>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    13dc <write_ppm+0x22c>
jmp    150c <write_ppm+0x35c>
mov    -0xd0(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xb3c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    17a5 <write_ppm+0x5f5>
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1792 <write_ppm+0x5e2>
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x40(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0x10,%eax
cmp    $0x0,%eax
jne    159a <write_ppm+0x3ea>
movl   $0x0,-0xfc(%rbp)
movl   $0x0,-0x104(%rbp)
movl   $0xff,-0x100(%rbp)
jmp    175c <write_ppm+0x5ac>
cmpl   $0x0,-0xe4(%rbp)
jne    1649 <write_ppm+0x499>
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    15e4 <write_ppm+0x434>
mov    -0x40(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    15e4 <write_ppm+0x434>
mov    -0xf8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x138(%rbp)
ff
jmp    15f4 <write_ppm+0x444>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x138(%rbp)
ff
jmp    15f4 <write_ppm+0x444>
movsd  -0x138(%rbp),%xmm0
ff
movsd  %xmm0,-0x110(%rbp)
ff
movsd  -0x110(%rbp),%xmm0
ff
movsd  0xa1c(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1060 <fabs@plt>
mov    %eax,%edi
movsd  0xa01(%rip),%xmm0
call   10b0 <pow@plt>
imul   $0xff,%eax,%eax
mov    %eax,-0x104(%rbp)
mov    %eax,-0x100(%rbp)
mov    %eax,-0xfc(%rbp)
jmp    1757 <write_ppm+0x5a7>
cmpl   $0x1,-0xe4(%rbp)
jne    16f6 <write_ppm+0x546>
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1693 <write_ppm+0x4e3>
mov    -0x40(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1693 <write_ppm+0x4e3>
mov    -0xf0(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x140(%rbp)
ff
jmp    16a3 <write_ppm+0x4f3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x140(%rbp)
ff
jmp    16a3 <write_ppm+0x4f3>
movsd  -0x140(%rbp),%xmm0
ff
movsd  %xmm0,-0x118(%rbp)
ff
movsd  0x965(%rip),%xmm0
addsd  -0x118(%rbp),%xmm0
ff
movsd  0x94d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0x939(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x104(%rbp)
mov    %eax,-0x100(%rbp)
mov    %eax,-0xfc(%rbp)
jmp    1752 <write_ppm+0x5a2>
cmpl   $0x2,-0xe4(%rbp)
jne    174d <write_ppm+0x59d>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x60(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
subsd  -0x60(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0x8dd(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x104(%rbp)
mov    %eax,-0x100(%rbp)
mov    %eax,-0xfc(%rbp)
jmp    1752 <write_ppm+0x5a2>
jmp    1757 <write_ppm+0x5a7>
jmp    175c <write_ppm+0x5ac>
mov    -0xd0(%rbp),%rdi
mov    -0xfc(%rbp),%edx
mov    -0x100(%rbp),%ecx
mov    -0x104(%rbp),%r8d
lea    0x8ed(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1546 <write_ppm+0x396>
jmp    1797 <write_ppm+0x5e7>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    152e <write_ppm+0x37e>
mov    -0xd0(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x1,-0xe4(%rbp)
jne    17ca <write_ppm+0x61a>
mov    -0xf0(%rbp),%rdi
call   1040 <free_matrix@plt>
cmpl   $0x0,-0xe4(%rbp)
jne    17e3 <write_ppm+0x633>
mov    -0xf8(%rbp),%rdi
call   1040 <free_matrix@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_ppm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %r9d,%r14d
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rsi,0x20(%rsp)
mov    %rdi,0x18(%rsp)
mov    0xb0(%rsp),%rbp
mov    0xb8(%rsp),%eax
cltd
idivl  0xc0(%rsp)
lea    0xe15(%rip),%rsi
lea    0x30(%rsp),%r13
mov    %r13,%rdi
mov    %rbp,%rdx
mov    %eax,%ecx
call   10d0 <sprintf@plt>
xor    %edi,%edi
call   1080 <umask@plt>
mov    0x2dc5(%rip),%rcx
mov    0x2db6(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %eax,%ebx
mov    0x2dc1(%rip),%rax
or     (%rax),%esi
mov    %rbp,%rdi
call   1030 <mkdir@plt>
mov    %ebx,%edi
call   1080 <umask@plt>
lea    0xdd5(%rip),%rsi
mov    %r13,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     13e3 <write_ppm+0x233>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
movsd  0x8(%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0x2(%r15),%edi
lea    0x2(%r14),%esi
call   10c0 <alloc_doublematrix@plt>
mov    %r14d,(%rsp)
mov    0x18(%rsp),%rdi
mov    0x20(%rsp),%rsi
mov    %rax,0x20(%rsp)
mov    %rax,%rcx
mov    %r12,%r8
mov    %r15d,%r9d
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   1090 <calc_psi_zeta@plt>
lea    0xd68(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,0x18(%rsp)
mov    %r15d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %r14d,%r14d
jle    13c3 <write_ppm+0x213>
mov    0x18(%rsp),%rax
movslq %eax,%rcx
mov    %rcx,0x10(%rsp)
lea    0x1(%rax),%r15d
mov    %r14d,%eax
mov    %rax,0x8(%rsp)
add    $0x1,%r14d
mov    $0x1,%r13d
lea    0xd2e(%rip),%rbp
mov    %r14,0x28(%rsp)
jmp    1332 <write_ppm+0x182>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
mov    0x28(%rsp),%r14
cmp    %r14,%r13
je     13c3 <write_ppm+0x213>
cmpl   $0x0,0x18(%rsp)
jle    1320 <write_ppm+0x170>
mov    $0x1,%r14d
jmp    1370 <write_ppm+0x1c0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edx,%edx
mov    $0xff,%ecx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %edx,%r8d
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%r15
je     1320 <write_ppm+0x170>
mov    (%r12,%r14,8),%rax
testb  $0x10,(%rax,%r13,1)
je     1350 <write_ppm+0x1a0>
xorpd  %xmm0,%xmm0
cmp    0x10(%rsp),%r14
jge    139c <write_ppm+0x1ec>
cmp    0x8(%rsp),%r13
jae    139c <write_ppm+0x1ec>
mov    0x20(%rsp),%rax
mov    (%rax,%r14,8),%rax
movsd  (%rax,%r13,8),%xmm0
divsd  0xc5c(%rip),%xmm0
call   1060 <fabs@plt>
mov    %eax,%edi
movsd  0xc55(%rip),%xmm0
call   10b0 <pow@plt>
mov    %eax,%ecx
shl    $0x8,%ecx
sub    %eax,%ecx
mov    %ecx,%edx
jmp    1357 <write_ppm+0x1a7>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x20(%rsp),%rdi
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <free_matrix@plt>
mov    0x2bde(%rip),%rax
movslq (%rax),%rdi
lea    0xc2b(%rip),%rsi
lea    0x30(%rsp),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s/%06d.ppm\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str.1 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"Could not open '%s'\0A\00"
@.str.3 = [14 x i8] c"P6 %d %d 255\0A\00"
@.str.4 = [7 x i8] c"%c%c%c\00"
define void @write_ppm(double** %0, double** %1, double** %2, i8** %3, i32 %4, i32 %5, double %6, double %7, i8* %8, i32 %9, i32 %10) {
%12 = alloca double**
%13 = alloca double**
%14 = alloca double**
%15 = alloca i8**
%16 = alloca i32
%17 = alloca i32
%18 = alloca double
%19 = alloca double
%20 = alloca i8*
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca double
%26 = alloca double
%27 = alloca double
%28 = alloca double
%29 = alloca double
%30 = alloca double
%31 = alloca double
%32 = alloca double
%33 = alloca [64 x i8]
%34 = alloca i32
%35 = alloca i32*
%36 = alloca double
%37 = alloca double
%38 = alloca i32
%39 = alloca double**
%40 = alloca double**
%41 = alloca i32
%42 = alloca i32
%43 = alloca i32
%44 = alloca double
%45 = alloca double
store double** %0, double*** %12
store double** %1, double*** %13
store double** %2, double*** %14
store i8** %3, i8*** %15
store i32 %4, i32* %16
store i32 %5, i32* %17
store double %6, double* %18
store double %7, double* %19
store i8* %8, i8** %20
store i32 %9, i32* %21
store i32 %10, i32* %22
store double -1.000000e+10, double* %25
store double 1.000000e+10, double* %26
store double -1.000000e+10, double* %27
store double 1.000000e+10, double* %28
store double -1.000000e+10, double* %29
store double 1.000000e+10, double* %30
store double -1.000000e+10, double* %31
store double 1.000000e+10, double* %32
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %33, i64 0, i64 0
%47 = load i8*, i8** %20
%48 = load i32, i32* %21
%49 = load i32, i32* %22
%50 = sdiv i32 %48, %49
%51 = call i32 @sprintf(i8* %46, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %47, i32 %50)
%52 = call i32 @umask(i32 0)
store i32 %52, i32* %34
%53 = load i8*, i8** %20
%54 = load i32, i32* @S_IRWXU
%55 = load i32, i32* @S_IRWXG
%56 = or i32 %54, %55
%57 = load i32, i32* @S_IRWXO
%58 = or i32 %56, %57
%59 = call i32 @mkdir(i8* %53, i32 %58)
%60 = load i32, i32* %34
%61 = call i32 @umask(i32 %60)
%62 = getelementptr inbounds [64 x i8], [64 x i8]* %33, i64 0, i64 0
%63 = call i32* @fopen(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %63, i32** %35
%64 = load i32*, i32** %35
%65 = icmp ne i32* %64, null
br i1 %65, label %72, label %66
66: ; preds = %11
%67 = load i32, i32* @stderr
%68 = sext i32 %67 to i64
%69 = inttoptr i64 %68 to i32*
%70 = getelementptr inbounds [64 x i8], [64 x i8]* %33, i64 0, i64 0
%71 = call i32 (i32*, i8*, ...) @fprintf(i32* %69, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %70)
br label %336
72: ; preds = %11
%73 = load double, double* %18
%74 = load i32, i32* %16
%75 = sitofp i32 %74 to double
%76 = fdiv double %73, %75
store double %76, double* %36
%77 = load double, double* %19
%78 = load i32, i32* %17
%79 = sitofp i32 %78 to double
%80 = fdiv double %77, %79
store double %80, double* %37
store i32 0, i32* %38
%81 = load i32, i32* %38
%82 = icmp eq i32 %81, 0
br i1 %82, label %86, label %83
83: ; preds = %72
%84 = load i32, i32* %38
%85 = icmp eq i32 %84, 1
br i1 %85, label %86, label %112
86: ; preds = %83, %72
%87 = load i32, i32* %38
%88 = icmp eq i32 %87, 1
br i1 %88, label %89, label %95
89: ; preds = %86
%90 = load i32, i32* %16
%91 = add nsw i32 %90, 2
%92 = load i32, i32* %17
%93 = add nsw i32 %92, 2
%94 = call double** @alloc_doublematrix(i32 %91, i32 %93)
store double** %94, double*** %39
br label %101
95: ; preds = %86
%96 = load i32, i32* %16
%97 = add nsw i32 %96, 2
%98 = load i32, i32* %17
%99 = add nsw i32 %98, 2
%100 = call double** @alloc_doublematrix(i32 %97, i32 %99)
store double** %100, double*** %40
br label %101
101: ; preds = %95, %89
%102 = load double**, double*** %12
%103 = load double**, double*** %13
%104 = load double**, double*** %39
%105 = load double**, double*** %40
%106 = load i8**, i8*** %15
%107 = load i32, i32* %16
%108 = load i32, i32* %17
%109 = load double, double* %36
%110 = load double, double* %37
%111 = call i32 @calc_psi_zeta(double** %102, double** %103, double** %104, double** %105, i8** %106, i32 %107, i32 %108, double %109, double %110)
br label %197
112: ; preds = %83
store i32 1, i32* %24
br label %113
113: ; preds = %193, %112
%114 = load i32, i32* %24
%115 = load i32, i32* %17
%116 = add nsw i32 %115, 1
%117 = icmp slt i32 %114, %116
br i1 %117, label %118, label %196
118: ; preds = %113
store i32 1, i32* %23
br label %119
119: ; preds = %189, %118
%120 = load i32, i32* %23
%121 = load i32, i32* %16
%122 = add nsw i32 %121, 1
%123 = icmp slt i32 %120, %122
br i1 %123, label %124, label %192
124: ; preds = %119
%125 = load i8**, i8*** %15
%126 = load i32, i32* %23
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i8*, i8** %125, i64 %127
%129 = load i8*, i8** %128
%130 = load i32, i32* %24
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds i8, i8* %129, i64 %131
%133 = load i8, i8* %132
%134 = sext i8 %133 to i32
%135 = and i32 %134, 16
%136 = icmp ne i32 %135, 0
br i1 %136, label %137, label %188
137: ; preds = %124
%138 = load double, double* %27
%139 = load double**, double*** %14
%140 = load i32, i32* %23
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds double*, double** %139, i64 %141
%143 = load double*, double** %142
%144 = load i32, i32* %24
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds double, double* %143, i64 %145
%147 = load double, double* %146
%148 = fcmp ogt double %138, %147
br i1 %148, label %149, label %151
149: ; preds = %137
%150 = load double, double* %27
br label %161
151: ; preds = %137
%152 = load double**, double*** %14
%153 = load i32, i32* %23
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds double*, double** %152, i64 %154
%156 = load double*, double** %155
%157 = load i32, i32* %24
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds double, double* %156, i64 %158
%160 = load double, double* %159
br label %161
161: ; preds = %151, %149
%162 = phi double [ %150, %149 ], [ %160, %151 ]
store double %162, double* %27
%163 = load double, double* %28
%164 = load double**, double*** %14
%165 = load i32, i32* %23
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds double*, double** %164, i64 %166
%168 = load double*, double** %167
%169 = load i32, i32* %24
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds double, double* %168, i64 %170
%172 = load double, double* %171
%173 = fcmp olt double %163, %172
br i1 %173, label %174, label %176
174: ; preds = %161
%175 = load double, double* %28
br label %186
176: ; preds = %161
%177 = load double**, double*** %14
%178 = load i32, i32* %23
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds double*, double** %177, i64 %179
%181 = load double*, double** %180
%182 = load i32, i32* %24
%183 = sext i32 %182 to i64
%184 = getelementptr inbounds double, double* %181, i64 %183
%185 = load double, double* %184
br label %186
186: ; preds = %176, %174
%187 = phi double [ %175, %174 ], [ %185, %176 ]
store double %187, double* %28
br label %188
188: ; preds = %186, %124
br label %189
189: ; preds = %188
%190 = load i32, i32* %23
%191 = add nsw i32 %190, 1
store i32 %191, i32* %23
br label %119
192: ; preds = %119
br label %193
193: ; preds = %192
%194 = load i32, i32* %24
%195 = add nsw i32 %194, 1
store i32 %195, i32* %24
br label %113
196: ; preds = %113
br label %197
197: ; preds = %196, %101
%198 = load i32*, i32** %35
%199 = load i32, i32* %16
%200 = load i32, i32* %17
%201 = call i32 (i32*, i8*, ...) @fprintf(i32* %198, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %199, i32 %200)
store i32 1, i32* %24
br label %202
202: ; preds = %319, %197
%203 = load i32, i32* %24
%204 = load i32, i32* %17
%205 = add nsw i32 %204, 1
%206 = icmp slt i32 %203, %205
br i1 %206, label %207, label %322
207: ; preds = %202
store i32 1, i32* %23
br label %208
208: ; preds = %315, %207
%209 = load i32, i32* %23
%210 = load i32, i32* %16
%211 = add nsw i32 %210, 1
%212 = icmp slt i32 %209, %211
br i1 %212, label %213, label %318
213: ; preds = %208
%214 = load i8**, i8*** %15
%215 = load i32, i32* %23
%216 = sext i32 %215 to i64
%217 = getelementptr inbounds i8*, i8** %214, i64 %216
%218 = load i8*, i8** %217
%219 = load i32, i32* %24
%220 = sext i32 %219 to i64
%221 = getelementptr inbounds i8, i8* %218, i64 %220
%222 = load i8, i8* %221
%223 = sext i8 %222 to i32
%224 = and i32 %223, 16
%225 = icmp ne i32 %224, 0
br i1 %225, label %227, label %226
226: ; preds = %213
store i32 0, i32* %41
store i32 0, i32* %43
store i32 255, i32* %42
br label %309
227: ; preds = %213
%228 = load i32, i32* %38
%229 = icmp eq i32 %228, 0
br i1 %229, label %230, label %256
230: ; preds = %227
%231 = load i32, i32* %23
%232 = load i32, i32* %16
%233 = icmp slt i32 %231, %232
br i1 %233, label %234, label %248
234: ; preds = %230
%235 = load i32, i32* %24
%236 = load i32, i32* %17
%237 = icmp slt i32 %235, %236
br i1 %237, label %238, label %248
238: ; preds = %234
%239 = load double**, double*** %40
%240 = load i32, i32* %23
%241 = sext i32 %240 to i64
%242 = getelementptr inbounds double*, double** %239, i64 %241
%243 = load double*, double** %242
%244 = load i32, i32* %24
%245 = sext i32 %244 to i64
%246 = getelementptr inbounds double, double* %243, i64 %245
%247 = load double, double* %246
br label %249
248: ; preds = %234, %230
br label %249
249: ; preds = %248, %238
%250 = phi double [ %247, %238 ], [ 0.000000e+00, %248 ]
store double %250, double* %44
%251 = load double, double* %44
%252 = fdiv double %251, 1.260000e+01
%253 = call i32 @fabs(double %252)
%254 = call i32 @pow(i32 %253, double 4.000000e-01)
%255 = mul nsw i32 %254, 255
store i32 %255, i32* %43
store i32 %255, i32* %42
store i32 %255, i32* %41
br label %308
256: ; preds = %227
%257 = load i32, i32* %38
%258 = icmp eq i32 %257, 1
br i1 %258, label %259, label %285
259: ; preds = %256
%260 = load i32, i32* %23
%261 = load i32, i32* %16
%262 = icmp slt i32 %260, %261
br i1 %262, label %263, label %277
263: ; preds = %259
%264 = load i32, i32* %24
%265 = load i32, i32* %17
%266 = icmp slt i32 %264, %265
br i1 %266, label %267, label %277
267: ; preds = %263
%268 = load double**, double*** %39
%269 = load i32, i32* %23
%270 = sext i32 %269 to i64
%271 = getelementptr inbounds double*, double** %268, i64 %270
%272 = load double*, double** %271
%273 = load i32, i32* %24
%274 = sext i32 %273 to i64
%275 = getelementptr inbounds double, double* %272, i64 %274
%276 = load double, double* %275
br label %278
277: ; preds = %263, %259
br label %278
278: ; preds = %277, %267
%279 = phi double [ %276, %267 ], [ 0.000000e+00, %277 ]
store double %279, double* %45
%280 = load double, double* %45
%281 = fadd double %280, 3.000000e+00
%282 = fdiv double %281, 7.500000e+00
%283 = fmul double %282, 2.550000e+02
%284 = fptosi double %283 to i32
store i32 %284, i32* %43
store i32 %284, i32* %42
store i32 %284, i32* %41
br label %307
285: ; preds = %256
%286 = load i32, i32* %38
%287 = icmp eq i32 %286, 2
br i1 %287, label %288, label %306
288: ; preds = %285
%289 = load double**, double*** %14
%290 = load i32, i32* %23
%291 = sext i32 %290 to i64
%292 = getelementptr inbounds double*, double** %289, i64 %291
%293 = load double*, double** %292
%294 = load i32, i32* %24
%295 = sext i32 %294 to i64
%296 = getelementptr inbounds double, double* %293, i64 %295
%297 = load double, double* %296
%298 = load double, double* %28
%299 = fsub double %297, %298
%300 = load double, double* %27
%301 = load double, double* %28
%302 = fsub double %300, %301
%303 = fdiv double %299, %302
%304 = fmul double %303, 2.550000e+02
%305 = fptosi double %304 to i32
store i32 %305, i32* %43
store i32 %305, i32* %42
store i32 %305, i32* %41
br label %306
306: ; preds = %288, %285
br label %307
307: ; preds = %306, %278
br label %308
308: ; preds = %307, %249
br label %309
309: ; preds = %308, %226
%310 = load i32*, i32** %35
%311 = load i32, i32* %41
%312 = load i32, i32* %42
%313 = load i32, i32* %43
%314 = call i32 (i32*, i8*, ...) @fprintf(i32* %310, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %311, i32 %312, i32 %313)
br label %315
315: ; preds = %309
%316 = load i32, i32* %23
%317 = add nsw i32 %316, 1
store i32 %317, i32* %23
br label %208
318: ; preds = %208
br label %319
319: ; preds = %318
%320 = load i32, i32* %24
%321 = add nsw i32 %320, 1
store i32 %321, i32* %24
br label %202
322: ; preds = %202
%323 = load i32*, i32** %35
%324 = call i32 @fclose(i32* %323)
%325 = load i32, i32* %38
%326 = icmp eq i32 %325, 1
br i1 %326, label %327, label %330
327: ; preds = %322
%328 = load double**, double*** %39
%329 = call i32 @free_matrix(double** %328)
br label %330
330: ; preds = %327, %322
%331 = load i32, i32* %38
%332 = icmp eq i32 %331, 0
br i1 %332, label %333, label %336
333: ; preds = %330
%334 = load double**, double*** %40
%335 = call i32 @free_matrix(double** %334)
br label %336
336: ; preds = %66, %333, %330
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s/%06d.ppm\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str.1 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"Could not open '%s'\0A\00"
@.str.3 = [14 x i8] c"P6 %d %d 255\0A\00"
@.str.4 = [7 x i8] c"%c%c%c\00"
define void @write_ppm(double** %0, double** %1, double** nocapture readnone %2, i8** %3, i32 %4, i32 %5, double %6, double %7, i8* %8, i32 %9, i32 %10) {
%12 = alloca [64 x i8]
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%14 = sdiv i32 %9, %10
%15 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %14)
%16 = tail call i32 @umask(i32 0)
%17 = load i32, i32* @S_IRWXU
%18 = load i32, i32* @S_IRWXG
%19 = or i32 %18, %17
%20 = load i32, i32* @S_IRWXO
%21 = or i32 %19, %20
%22 = tail call i32 @mkdir(i8* %8, i32 %21)
%23 = tail call i32 @umask(i32 %16)
%24 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %31
26: ; preds = %11
%27 = load i32, i32* @stderr
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i32*
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %88
31: ; preds = %11
%32 = sitofp i32 %4 to double
%33 = fdiv double %6, %32
%34 = sitofp i32 %5 to double
%35 = fdiv double %7, %34
%36 = add nsw i32 %4, 2
%37 = add nsw i32 %5, 2
%38 = tail call double** @alloc_doublematrix(i32 %36, i32 %37)
%39 = tail call i32 @calc_psi_zeta(double** %0, double** %1, double** undef, double** %38, i8** %3, i32 %4, i32 %5, double %33, double %35)
%40 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %4, i32 %5)
%41 = icmp slt i32 %5, 1
br i1 %41, label %85, label %42
42: ; preds = %31
%43 = icmp slt i32 %4, 1
%44 = sext i32 %4 to i64
%45 = add i32 %4, 1
%46 = zext i32 %5 to i64
%47 = add nuw i32 %5, 1
%48 = zext i32 %47 to i64
%49 = zext i32 %45 to i64
br label %50
50: ; preds = %42, %82
%51 = phi i64 [ 1, %42 ], [ %83, %82 ]
br i1 %43, label %82, label %52
52: ; preds = %50
%53 = icmp ult i64 %51, %46
br label %54
54: ; preds = %52, %76
%55 = phi i64 [ 1, %52 ], [ %80, %76 ]
%56 = getelementptr inbounds i8*, i8** %3, i64 %55
%57 = load i8*, i8** %56
%58 = getelementptr inbounds i8, i8* %57, i64 %51
%59 = load i8, i8* %58
%60 = and i8 %59, 16
%61 = icmp eq i8 %60, 0
br i1 %61, label %76, label %62
62: ; preds = %54
%63 = icmp slt i64 %55, %44
%64 = select i1 %63, i1 %53, i1 false
br i1 %64, label %65, label %70
65: ; preds = %62
%66 = getelementptr inbounds double*, double** %38, i64 %55
%67 = load double*, double** %66
%68 = getelementptr inbounds double, double* %67, i64 %51
%69 = load double, double* %68
br label %70
70: ; preds = %62, %65
%71 = phi double [ %69, %65 ], [ 0.000000e+00, %62 ]
%72 = fdiv double %71, 1.260000e+01
%73 = tail call i32 @fabs(double %72)
%74 = tail call i32 @pow(i32 %73, double 4.000000e-01)
%75 = mul nsw i32 %74, 255
br label %76
76: ; preds = %54, %70
%77 = phi i32 [ %75, %70 ], [ 255, %54 ]
%78 = phi i32 [ %75, %70 ], [ 0, %54 ]
%79 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %78, i32 %77, i32 %78)
%80 = add nuw nsw i64 %55, 1
%81 = icmp eq i64 %80, %49
br i1 %81, label %82, label %54
82: ; preds = %76, %50
%83 = add nuw nsw i64 %51, 1
%84 = icmp eq i64 %83, %48
br i1 %84, label %85, label %50
85: ; preds = %82, %31
%86 = tail call i32 @fclose(i32* %24)
%87 = tail call i32 @free_matrix(double** %38)
br label %88
88: ; preds = %85, %26
ret void
}