#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 calculateImagePixels(int);
double **constructColorArray(int, int);
double **constructNodeArray(int);
int /*<<< orphan*/ destroyColorArrays(double **, int, int);
int /*<<< orphan*/ destroyNodeArrays(double **, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fillColorArrays(unsigned char *, double **, int, double **,
                                   double **, double **);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ getBeliefs(int /*<<< orphan*/ *, double **, int);
int getSize(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *read, *write;
  int size;
  double **node_array;
  double **r, **g, **b;
  unsigned char *image;
  int width, height;
  int i, j;
  if (argc != 3) {
    printf("Incorrect number of arguments. \n Usage:%s inputfile outputfile\n",
           argv[0]);
    exit(-1);
  }
  read = fopen(argv[1], "r");
  write = fopen(argv[2], "w");
  if (read == NULL) {
    printf("Error: %s cannot be opened, or may not exist. \n", argv[1]);
    exit(-1);
  }
  if (write == NULL) {
    printf("Error: %s cannot be opened, or may not exist. \n", argv[2]);
    fclose(read);
    exit(-1);
  }
  size = getSize(read);
  printf("Size is: %d. Bottom layer will have %d nodes, and layer above it "
         "will have %d.\n",
         size, (int)pow(4, size - 1), (int)pow(4, size - 2));
  node_array = constructNodeArray(size);
  getBeliefs(read, node_array, size);
  width = calculateImagePixels(size);
  printf("width: %d", width);
  height = width * size + (size - 1);
  r = constructColorArray(width, height);
  g = constructColorArray(width, height);
  b = constructColorArray(width, height);
  image = (unsigned char *)malloc(3 * height * width);
  fillColorArrays(image, node_array, size, r, g, b);
  int red;
  int green;
  int blue;
  int current_location;
  unsigned char filesize = 54 + 3 * width * height;
  for (i = 0; i < width; i++) {
    for (j = 0; j < height; j++) {
      red = r[i][j] * 255;
      green = g[i][j] * 255;
      blue = b[i][j] * 255;
      if (red > 255)
        red = 255;
      if (green > 255)
        green = 255;
      if (blue > 255)
        blue = 255;
      if ((j + 1) % (width + 1) == 0 && j > 1) {
        red = 200;
        blue = 10;
        green = 20;
      }
      printf("(%d,%d) = R:%lf/G:%lf/B:%lf\n", i, j, r[i][j], g[i][j], b[i][j]);
      current_location = (i + (j * width)) * 3;
      image[current_location] = (unsigned char)(blue);
      image[current_location + 1] = (unsigned char)(green);
      image[current_location + 2] = (unsigned char)(red);
    }
  }
  unsigned char header[54] = {'B',
                              'M',
                              filesize,
                              filesize >> 8,
                              filesize >> 16,
                              filesize >> 24,
                              0,
                              0,
                              0,
                              0,
                              54,
                              0,
                              0,
                              0,
                              40,
                              0,
                              0,
                              0,
                              width,
                              width >> 8,
                              width >> 16,
                              width >> 24,
                              height,
                              height >> 8,
                              height >> 16,
                              height >> 24,
                              1,
                              0,
                              24,
                              0};
  unsigned char padding[3] = {0, 0, 0};
  fwrite(header, 1, 54, write);
  for (i = 0; i < height; i++) {
    fwrite(image + (width * (height - i - 1) * 3), 3, width, write);
    fwrite(padding, 1, (4 - (width * 3) % 4) % 4, write);
  }
  printf("Done.\n");
  fclose(read);
  fclose(write);
  destroyNodeArrays(node_array, size);
  destroyColorArrays(r, width, height);
  destroyColorArrays(g, width, height);
  destroyColorArrays(b, width, height);
  free(image);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1252 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde7(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdd1(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12ad <main+0x9d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12e1 <main+0xd1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1130 <getSize@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x24(%rbp),%esi
sub    $0x1,%esi
mov    $0x4,%edi
call   10d0 <pow@plt>
mov    %eax,-0xb8(%rbp)
mov    -0x24(%rbp),%esi
sub    $0x2,%esi
mov    $0x4,%edi
call   10d0 <pow@plt>
mov    -0xbc(%rbp),%esi
mov    -0xb8(%rbp),%edx
mov    %eax,%ecx
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x24(%rbp),%edi
call   1040 <constructNodeArray@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1110 <getBeliefs@plt>
mov    -0x24(%rbp),%edi
call   1050 <calculateImagePixels@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%esi
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x54(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x58(%rbp),%esi
call   1100 <constructColorArray@plt>
mov    %rax,-0x38(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x58(%rbp),%esi
call   1100 <constructColorArray@plt>
mov    %rax,-0x40(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x58(%rbp),%esi
call   1100 <constructColorArray@plt>
mov    %rax,-0x48(%rbp)
imul   $0x3,-0x58(%rbp),%edi
imul   -0x54(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x48(%rbp),%r9
call   1120 <fillColorArrays@plt>
imul   $0x3,-0x54(%rbp),%eax
imul   -0x58(%rbp),%eax
add    $0x36,%eax
mov    %al,-0x71(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    15af <main+0x39f>
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    159c <main+0x38c>
mov    -0x38(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x60(%rbp),%rcx
movsd  0xbd8(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x64(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x60(%rbp),%rcx
movsd  0xbb4(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x68(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x60(%rbp),%rcx
movsd  0xb90(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x6c(%rbp)
cmpl   $0xff,-0x64(%rbp)
jle    1490 <main+0x280>
movl   $0xff,-0x64(%rbp)
cmpl   $0xff,-0x68(%rbp)
jle    14a4 <main+0x294>
movl   $0xff,-0x68(%rbp)
cmpl   $0xff,-0x6c(%rbp)
jle    14b8 <main+0x2a8>
movl   $0xff,-0x6c(%rbp)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    -0x54(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    14ef <main+0x2df>
cmpl   $0x1,-0x60(%rbp)
jle    14ef <main+0x2df>
movl   $0xc8,-0x64(%rbp)
movl   $0xa,-0x6c(%rbp)
movl   $0x14,-0x68(%rbp)
mov    -0x5c(%rbp),%esi
mov    -0x60(%rbp),%edx
mov    -0x38(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x48(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
lea    0xb9b(%rip),%rdi
mov    $0x3,%al
call   1070 <printf@plt>
mov    -0x5c(%rbp),%eax
mov    -0x60(%rbp),%ecx
imul   -0x54(%rbp),%ecx
add    %ecx,%eax
imul   $0x3,%eax,%eax
mov    %eax,-0x70(%rbp)
mov    -0x6c(%rbp),%eax
mov    %al,%dl
mov    -0x50(%rbp),%rax
movslq -0x70(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x68(%rbp),%eax
mov    %al,%dl
mov    -0x50(%rbp),%rax
mov    -0x70(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x64(%rbp),%eax
mov    %al,%dl
mov    -0x50(%rbp),%rax
mov    -0x70(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1404 <main+0x1f4>
jmp    15a1 <main+0x391>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    13f1 <main+0x1e1>
lea    -0xb0(%rbp),%rcx
movb   $0x42,-0xb0(%rbp)
mov    %rcx,%rax
add    $0x1,%rax
movb   $0x4d,-0xaf(%rbp)
add    $0x1,%rax
mov    -0x71(%rbp),%dl
mov    %dl,-0xae(%rbp)
add    $0x1,%rax
movzbl -0x71(%rbp),%edx
sar    $0x8,%edx
mov    %dl,-0xad(%rbp)
add    $0x1,%rax
movzbl -0x71(%rbp),%edx
sar    $0x10,%edx
mov    %dl,-0xac(%rbp)
add    $0x1,%rax
movzbl -0x71(%rbp),%edx
sar    $0x18,%edx
mov    %dl,-0xab(%rbp)
add    $0x1,%rax
movb   $0x0,-0xaa(%rbp)
add    $0x1,%rax
movb   $0x0,-0xa9(%rbp)
add    $0x1,%rax
movb   $0x0,-0xa8(%rbp)
add    $0x1,%rax
movb   $0x0,-0xa7(%rbp)
add    $0x1,%rax
movb   $0x36,-0xa6(%rbp)
add    $0x1,%rax
movb   $0x0,-0xa5(%rbp)
add    $0x1,%rax
movb   $0x0,-0xa4(%rbp)
add    $0x1,%rax
movb   $0x0,-0xa3(%rbp)
add    $0x1,%rax
movb   $0x28,-0xa2(%rbp)
add    $0x1,%rax
movb   $0x0,-0xa1(%rbp)
add    $0x1,%rax
movb   $0x0,-0xa0(%rbp)
add    $0x1,%rax
movb   $0x0,-0x9f(%rbp)
add    $0x1,%rax
mov    -0x54(%rbp),%edx
mov    %dl,-0x9e(%rbp)
add    $0x1,%rax
mov    -0x54(%rbp),%edx
sar    $0x8,%edx
mov    %dl,-0x9d(%rbp)
add    $0x1,%rax
mov    -0x54(%rbp),%edx
sar    $0x10,%edx
mov    %dl,-0x9c(%rbp)
add    $0x1,%rax
mov    -0x54(%rbp),%edx
sar    $0x18,%edx
mov    %dl,-0x9b(%rbp)
add    $0x1,%rax
mov    -0x58(%rbp),%edx
mov    %dl,-0x9a(%rbp)
add    $0x1,%rax
mov    -0x58(%rbp),%edx
sar    $0x8,%edx
mov    %dl,-0x99(%rbp)
add    $0x1,%rax
mov    -0x58(%rbp),%edx
sar    $0x10,%edx
mov    %dl,-0x98(%rbp)
add    $0x1,%rax
mov    -0x58(%rbp),%edx
sar    $0x18,%edx
mov    %dl,-0x97(%rbp)
add    $0x1,%rax
movb   $0x1,-0x96(%rbp)
add    $0x1,%rax
movb   $0x0,-0x95(%rbp)
add    $0x1,%rax
movb   $0x18,-0x94(%rbp)
add    $0x1,%rax
movb   $0x0,-0x93(%rbp)
add    $0x1,%rax
add    $0x36,%rcx
mov    %rcx,-0xd0(%rbp)
mov    %rax,-0xc8(%rbp)
mov    -0xc8(%rbp),%rax
mov    -0xd0(%rbp),%rcx
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,-0xd8(%rbp)
cmp    %rcx,%rax
mov    %rax,-0xc8(%rbp)
jne    174b <main+0x53b>
lea    -0xb3(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1080 <memset@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x36,%edx
call   10f0 <fwrite@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    1821 <main+0x611>
mov    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%eax
mov    -0x58(%rbp),%ecx
sub    -0x5c(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
imul   $0x3,%eax,%eax
cltq
add    %rax,%rdi
mov    -0x54(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x3,%esi
call   10f0 <fwrite@plt>
lea    -0xb3(%rbp),%rdi
imul   $0x3,-0x54(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    $0x4,%eax
sub    %edx,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    17ab <main+0x59b>
lea    0x8cb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1090 <destroyNodeArrays@plt>
mov    -0x38(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x58(%rbp),%edx
call   10b0 <destroyColorArrays@plt>
mov    -0x40(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x58(%rbp),%edx
call   10b0 <destroyColorArrays@plt>
mov    -0x48(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x58(%rbp),%edx
call   10b0 <destroyColorArrays@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    16bb <main+0x4ab>
mov    0x8(%rbx),%rdi
lea    0xe10(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbp
mov    0x10(%rbx),%rdi
lea    0xdff(%rip),%rsi
call   10c0 <fopen@plt>
test   %rbp,%rbp
je     16c7 <main+0x4b7>
mov    %rax,0x90(%rsp)
test   %rax,%rax
je     16e3 <main+0x4d3>
mov    %rbp,%rdi
call   1130 <getSize@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%esi
mov    $0x4,%edi
call   10d0 <pow@plt>
mov    %rax,%r14
lea    -0x2(%rbx),%esi
mov    $0x4,%edi
call   10d0 <pow@plt>
lea    0xde4(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%edi
call   1050 <constructNodeArray@plt>
mov    %rax,0x30(%rsp)
mov    %rbp,0x88(%rsp)
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1110 <getBeliefs@plt>
mov    %ebx,%edi
call   1060 <calculateImagePixels@plt>
mov    %eax,%ebp
lea    0xdf5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebp,%eax
mov    %rbx,0x38(%rsp)
imul   %ebx,%eax
lea    (%rax,%rbx,1),%r15d
add    $0xffffffff,%r15d
mov    %ebp,%edi
mov    %r15d,%esi
call   1100 <constructColorArray@plt>
mov    %rax,%r12
mov    %ebp,%edi
mov    %r15d,%esi
call   1100 <constructColorArray@plt>
mov    %rax,%r13
mov    %ebp,%edi
mov    %r15d,%esi
call   1100 <constructColorArray@plt>
mov    %rax,%r14
lea    0x0(%rbp,%rbp,2),%ebx
mov    %ebx,0x8(%rsp)
imul   %r15d,%ebx
mov    %ebx,%edi
call   10a0 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    %rax,%rdi
mov    0x30(%rsp),%rsi
mov    0x38(%rsp),%rdx
mov    %r12,%rcx
mov    %r13,%r8
mov    %r14,%r9
call   1120 <fillColorArrays@plt>
add    $0x36,%bl
mov    %ebx,0x28(%rsp)
mov    %r15,0x18(%rsp)
mov    %r15d,%r10d
mov    %rbp,0x10(%rsp)
test   %ebp,%ebp
mov    %r14,0x48(%rsp)
jle    1519 <main+0x309>
mov    0x10(%rsp),%rax
lea    0x1(%rax),%edi
mov    %eax,%ecx
mov    0x20(%rsp),%rax
add    $0x2,%rax
mov    %rax,0x40(%rsp)
mov    %rcx,0x98(%rsp)
lea    (%rcx,%rcx,2),%rax
xor    %esi,%esi
movsd  0xc65(%rip),%xmm4
lea    0xd34(%rip),%r8
mov    %r12,0xb8(%rsp)
mov    %r13,0xb0(%rsp)
mov    %r10,0xa8(%rsp)
mov    %rax,0xa0(%rsp)
mov    %edi,0x2c(%rsp)
jmp    13e8 <main+0x1d8>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rsi
addq   $0x3,0x40(%rsp)
cmp    0x98(%rsp),%rsi
je     1519 <main+0x309>
cmpl   $0x0,0x18(%rsp)
jle    13d0 <main+0x1c0>
mov    0x40(%rsp),%rbx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
mov    (%r12,%rsi,8),%rax
movsd  (%rax,%rcx,8),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm4,%xmm1
cvttsd2si %xmm1,%ebp
mov    0x0(%r13,%rsi,8),%rax
movsd  (%rax,%rcx,8),%xmm1
movapd %xmm1,%xmm2
mulsd  %xmm4,%xmm2
cvttsd2si %xmm2,%r12d
mov    (%r14,%rsi,8),%rax
movsd  (%rax,%rcx,8),%xmm2
movapd %xmm2,%xmm3
mulsd  %xmm4,%xmm3
cvttsd2si %xmm3,%r15d
lea    0x1(%rcx),%rax
mov    %rax,0xc0(%rsp)
cltd
idiv   %edi
test   %edx,%edx
sete   0x7(%rsp)
cmp    $0x2,%rcx
setae  0x6(%rsp)
mov    %r8,%r14
mov    %r8,%rdi
mov    %ecx,%edx
mov    $0x3,%al
mov    %rsi,%r13
call   1080 <printf@plt>
mov    $0xa,%r9d
mov    $0xff,%ecx
mov    %r14,%r8
movsd  0xb77(%rip),%xmm4
mov    %r13,%rsi
mov    0xa0(%rsp),%rax
mov    0x2c(%rsp),%edi
mov    0xa8(%rsp),%r10
cmp    $0xff,%r15d
cmovge %ecx,%r15d
cmp    $0xff,%r12d
cmovge %ecx,%r12d
cmp    $0xff,%ebp
cmovge %ecx,%ebp
movzbl 0x6(%rsp),%ecx
test   %cl,0x7(%rsp)
mov    0x48(%rsp),%r14
cmovne %r9d,%r15d
mov    $0xc8,%edx
mov    $0x14,%ecx
mov    %r15b,-0x2(%rbx)
cmovne %ecx,%r12d
cmovne %edx,%ebp
mov    %r12b,-0x1(%rbx)
mov    0xb8(%rsp),%r12
mov    %bpl,(%rbx)
add    %rax,%rbx
mov    0xc0(%rsp),%rdx
mov    %rdx,%rcx
cmp    %rdx,%r10
mov    0xb0(%rsp),%r13
jne    1400 <main+0x1f0>
jmp    13d0 <main+0x1c0>
movw   $0x4d42,0x50(%rsp)
mov    0x28(%rsp),%eax
mov    %al,0x52(%rsp)
movl   $0x0,0x53(%rsp)
movl   $0x0,0x56(%rsp)
movabs $0x2800000036,%rax
mov    %rax,0x5a(%rsp)
mov    0x10(%rsp),%rcx
mov    %cl,0x62(%rsp)
mov    %ch,0x63(%rsp)
mov    %ecx,%eax
shr    $0x10,%eax
mov    %al,0x64(%rsp)
mov    %ecx,%eax
shr    $0x18,%eax
mov    %al,0x65(%rsp)
mov    0x18(%rsp),%rbx
mov    %bl,0x66(%rsp)
mov    %bh,0x67(%rsp)
mov    %ebx,%eax
shr    $0x10,%eax
mov    %al,0x68(%rsp)
mov    %ebx,%eax
shr    $0x18,%eax
mov    %al,0x69(%rsp)
movw   $0x1,0x6a(%rsp)
movb   $0x18,0x6c(%rsp)
xorpd  %xmm0,%xmm0
movupd %xmm0,0x76(%rsp)
movupd %xmm0,0x6d(%rsp)
movb   $0x0,0xe(%rsp)
movw   $0x0,0xc(%rsp)
lea    0x50(%rsp),%rdi
mov    $0x1,%esi
mov    %r10,%r14
mov    $0x36,%edx
mov    0x90(%rsp),%rbp
mov    %rbp,%rcx
call   10f0 <fwrite@plt>
test   %ebx,%ebx
mov    0x8(%rsp),%eax
jle    163d <main+0x42d>
neg    %eax
and    $0x3,%eax
mov    %eax,0x8(%rsp)
mov    0x18(%rsp),%rax
add    $0xffffffff,%eax
mov    0x10(%rsp),%rcx
imul   %ecx,%eax
lea    (%rax,%rax,2),%ebx
lea    (%rcx,%rcx,2),%r15d
nopw   0x0(%rax,%rax,1)
movslq %ebx,%rbx
mov    0x20(%rsp),%rax
lea    (%rax,%rbx,1),%rdi
mov    $0x3,%esi
mov    0x10(%rsp),%rdx
mov    %rbp,%rcx
call   10f0 <fwrite@plt>
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    0x8(%rsp),%edx
mov    %rbp,%rcx
call   10f0 <fwrite@plt>
sub    %r15d,%ebx
add    $0xffffffffffffffff,%r14
jne    1600 <main+0x3f0>
lea    0xaaf(%rip),%rdi
call   1040 <puts@plt>
mov    0x88(%rsp),%rdi
call   1070 <fclose@plt>
mov    %rbp,%rdi
call   1070 <fclose@plt>
mov    0x30(%rsp),%rdi
mov    0x38(%rsp),%rsi
call   1090 <destroyNodeArrays@plt>
mov    %r12,%rdi
mov    0x10(%rsp),%rbp
mov    %ebp,%esi
mov    0x18(%rsp),%rbx
mov    %ebx,%edx
call   10b0 <destroyColorArrays@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   10b0 <destroyColorArrays@plt>
mov    0x48(%rsp),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   10b0 <destroyColorArrays@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0x943(%rip),%rdi
jmp    16d2 <main+0x4c2>
mov    0x8(%rbx),%rsi
lea    0x97a(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    0x10(%rbx),%rsi
lea    0x95e(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbp,%rdi
call   1070 <fclose@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [64 x i8] c"Incorrect number of arguments. \0A Usage:%s inputfile outputfile\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [48 x i8] c"Error: %s cannot be opened, or may not exist. \0A\00"
@.str.4 = [80 x i8] c"Size is: %d. Bottom layer will have %d nodes, and layer above it will have %d.\0A\00"
@.str.5 = [10 x i8] c"width: %d\00"
@.str.6 = [29 x i8] c"(%d,%d) = R:%lf/G:%lf/B:%lf\0A\00"
@.str.7 = [7 x i8] c"Done.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca double**
%10 = alloca double**
%11 = alloca double**
%12 = alloca double**
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i8
%23 = alloca [54 x i8]
%24 = alloca [3 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 3
br i1 %26, label %27, label %33
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %2
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %37, i32** %6
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %41, i32** %7
%42 = load i32*, i32** %6
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %50
44: ; preds = %33
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %33
%51 = load i32*, i32** %7
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %61
53: ; preds = %50
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 2
%56 = load i8*, i8** %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = load i32*, i32** %6
%59 = call i32 @fclose(i32* %58)
%60 = call i32 @exit(i32 -1)
unreachable
61: ; preds = %50
%62 = load i32*, i32** %6
%63 = call i32 @getSize(i32* %62)
store i32 %63, i32* %8
%64 = load i32, i32* %8
%65 = load i32, i32* %8
%66 = sub nsw i32 %65, 1
%67 = call i64 @pow(i32 4, i32 %66)
%68 = trunc i64 %67 to i32
%69 = load i32, i32* %8
%70 = sub nsw i32 %69, 2
%71 = call i64 @pow(i32 4, i32 %70)
%72 = trunc i64 %71 to i32
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.4, i64 0, i64 0), i32 %64, i32 %68, i32 %72)
%74 = load i32, i32* %8
%75 = call double** @constructNodeArray(i32 %74)
store double** %75, double*** %9
%76 = load i32*, i32** %6
%77 = load double**, double*** %9
%78 = load i32, i32* %8
%79 = call i32 @getBeliefs(i32* %76, double** %77, i32 %78)
%80 = load i32, i32* %8
%81 = call i32 @calculateImagePixels(i32 %80)
store i32 %81, i32* %14
%82 = load i32, i32* %14
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %82)
%84 = load i32, i32* %14
%85 = load i32, i32* %8
%86 = mul nsw i32 %84, %85
%87 = load i32, i32* %8
%88 = sub nsw i32 %87, 1
%89 = add nsw i32 %86, %88
store i32 %89, i32* %15
%90 = load i32, i32* %14
%91 = load i32, i32* %15
%92 = call double** @constructColorArray(i32 %90, i32 %91)
store double** %92, double*** %10
%93 = load i32, i32* %14
%94 = load i32, i32* %15
%95 = call double** @constructColorArray(i32 %93, i32 %94)
store double** %95, double*** %11
%96 = load i32, i32* %14
%97 = load i32, i32* %15
%98 = call double** @constructColorArray(i32 %96, i32 %97)
store double** %98, double*** %12
%99 = load i32, i32* %15
%100 = mul nsw i32 3, %99
%101 = load i32, i32* %14
%102 = mul nsw i32 %100, %101
%103 = call i64 @malloc(i32 %102)
%104 = inttoptr i64 %103 to i8*
store i8* %104, i8** %13
%105 = load i8*, i8** %13
%106 = load double**, double*** %9
%107 = load i32, i32* %8
%108 = load double**, double*** %10
%109 = load double**, double*** %11
%110 = load double**, double*** %12
%111 = call i32 @fillColorArrays(i8* %105, double** %106, i32 %107, double** %108, double** %109, double** %110)
%112 = load i32, i32* %14
%113 = mul nsw i32 3, %112
%114 = load i32, i32* %15
%115 = mul nsw i32 %113, %114
%116 = add nsw i32 54, %115
%117 = trunc i32 %116 to i8
store i8 %117, i8* %22
store i32 0, i32* %16
br label %118
118: ; preds = %244, %61
%119 = load i32, i32* %16
%120 = load i32, i32* %14
%121 = icmp slt i32 %119, %120
br i1 %121, label %122, label %247
122: ; preds = %118
store i32 0, i32* %17
br label %123
123: ; preds = %240, %122
%124 = load i32, i32* %17
%125 = load i32, i32* %15
%126 = icmp slt i32 %124, %125
br i1 %126, label %127, label %243
127: ; preds = %123
%128 = load double**, double*** %10
%129 = load i32, i32* %16
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds double*, double** %128, i64 %130
%132 = load double*, double** %131
%133 = load i32, i32* %17
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds double, double* %132, i64 %134
%136 = load double, double* %135
%137 = fmul double %136, 2.550000e+02
%138 = fptosi double %137 to i32
store i32 %138, i32* %18
%139 = load double**, double*** %11
%140 = load i32, i32* %16
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds double*, double** %139, i64 %141
%143 = load double*, double** %142
%144 = load i32, i32* %17
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds double, double* %143, i64 %145
%147 = load double, double* %146
%148 = fmul double %147, 2.550000e+02
%149 = fptosi double %148 to i32
store i32 %149, i32* %19
%150 = load double**, double*** %12
%151 = load i32, i32* %16
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds double*, double** %150, i64 %152
%154 = load double*, double** %153
%155 = load i32, i32* %17
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds double, double* %154, i64 %156
%158 = load double, double* %157
%159 = fmul double %158, 2.550000e+02
%160 = fptosi double %159 to i32
store i32 %160, i32* %20
%161 = load i32, i32* %18
%162 = icmp sgt i32 %161, 255
br i1 %162, label %163, label %164
163: ; preds = %127
store i32 255, i32* %18
br label %164
164: ; preds = %163, %127
%165 = load i32, i32* %19
%166 = icmp sgt i32 %165, 255
br i1 %166, label %167, label %168
167: ; preds = %164
store i32 255, i32* %19
br label %168
168: ; preds = %167, %164
%169 = load i32, i32* %20
%170 = icmp sgt i32 %169, 255
br i1 %170, label %171, label %172
171: ; preds = %168
store i32 255, i32* %20
br label %172
172: ; preds = %171, %168
%173 = load i32, i32* %17
%174 = add nsw i32 %173, 1
%175 = load i32, i32* %14
%176 = add nsw i32 %175, 1
%177 = srem i32 %174, %176
%178 = icmp eq i32 %177, 0
br i1 %178, label %179, label %183
179: ; preds = %172
%180 = load i32, i32* %17
%181 = icmp sgt i32 %180, 1
br i1 %181, label %182, label %183
182: ; preds = %179
store i32 200, i32* %18
store i32 10, i32* %20
store i32 20, i32* %19
br label %183
183: ; preds = %182, %179, %172
%184 = load i32, i32* %16
%185 = load i32, i32* %17
%186 = load double**, double*** %10
%187 = load i32, i32* %16
%188 = sext i32 %187 to i64
%189 = getelementptr inbounds double*, double** %186, i64 %188
%190 = load double*, double** %189
%191 = load i32, i32* %17
%192 = sext i32 %191 to i64
%193 = getelementptr inbounds double, double* %190, i64 %192
%194 = load double, double* %193
%195 = load double**, double*** %11
%196 = load i32, i32* %16
%197 = sext i32 %196 to i64
%198 = getelementptr inbounds double*, double** %195, i64 %197
%199 = load double*, double** %198
%200 = load i32, i32* %17
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds double, double* %199, i64 %201
%203 = load double, double* %202
%204 = load double**, double*** %12
%205 = load i32, i32* %16
%206 = sext i32 %205 to i64
%207 = getelementptr inbounds double*, double** %204, i64 %206
%208 = load double*, double** %207
%209 = load i32, i32* %17
%210 = sext i32 %209 to i64
%211 = getelementptr inbounds double, double* %208, i64 %210
%212 = load double, double* %211
%213 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %184, i32 %185, double %194, double %203, double %212)
%214 = load i32, i32* %16
%215 = load i32, i32* %17
%216 = load i32, i32* %14
%217 = mul nsw i32 %215, %216
%218 = add nsw i32 %214, %217
%219 = mul nsw i32 %218, 3
store i32 %219, i32* %21
%220 = load i32, i32* %20
%221 = trunc i32 %220 to i8
%222 = load i8*, i8** %13
%223 = load i32, i32* %21
%224 = sext i32 %223 to i64
%225 = getelementptr inbounds i8, i8* %222, i64 %224
store i8 %221, i8* %225
%226 = load i32, i32* %19
%227 = trunc i32 %226 to i8
%228 = load i8*, i8** %13
%229 = load i32, i32* %21
%230 = add nsw i32 %229, 1
%231 = sext i32 %230 to i64
%232 = getelementptr inbounds i8, i8* %228, i64 %231
store i8 %227, i8* %232
%233 = load i32, i32* %18
%234 = trunc i32 %233 to i8
%235 = load i8*, i8** %13
%236 = load i32, i32* %21
%237 = add nsw i32 %236, 2
%238 = sext i32 %237 to i64
%239 = getelementptr inbounds i8, i8* %235, i64 %238
store i8 %234, i8* %239
br label %240
240: ; preds = %183
%241 = load i32, i32* %17
%242 = add nsw i32 %241, 1
store i32 %242, i32* %17
br label %123
243: ; preds = %123
br label %244
244: ; preds = %243
%245 = load i32, i32* %16
%246 = add nsw i32 %245, 1
store i32 %246, i32* %16
br label %118
247: ; preds = %118
%248 = getelementptr inbounds [54 x i8], [54 x i8]* %23, i64 0, i64 0
store i8 66, i8* %248
%249 = getelementptr inbounds i8, i8* %248, i64 1
store i8 77, i8* %249
%250 = getelementptr inbounds i8, i8* %249, i64 1
%251 = load i8, i8* %22
store i8 %251, i8* %250
%252 = getelementptr inbounds i8, i8* %250, i64 1
%253 = load i8, i8* %22
%254 = zext i8 %253 to i32
%255 = ashr i32 %254, 8
%256 = trunc i32 %255 to i8
store i8 %256, i8* %252
%257 = getelementptr inbounds i8, i8* %252, i64 1
%258 = load i8, i8* %22
%259 = zext i8 %258 to i32
%260 = ashr i32 %259, 16
%261 = trunc i32 %260 to i8
store i8 %261, i8* %257
%262 = getelementptr inbounds i8, i8* %257, i64 1
%263 = load i8, i8* %22
%264 = zext i8 %263 to i32
%265 = ashr i32 %264, 24
%266 = trunc i32 %265 to i8
store i8 %266, i8* %262
%267 = getelementptr inbounds i8, i8* %262, i64 1
store i8 0, i8* %267
%268 = getelementptr inbounds i8, i8* %267, i64 1
store i8 0, i8* %268
%269 = getelementptr inbounds i8, i8* %268, i64 1
store i8 0, i8* %269
%270 = getelementptr inbounds i8, i8* %269, i64 1
store i8 0, i8* %270
%271 = getelementptr inbounds i8, i8* %270, i64 1
store i8 54, i8* %271
%272 = getelementptr inbounds i8, i8* %271, i64 1
store i8 0, i8* %272
%273 = getelementptr inbounds i8, i8* %272, i64 1
store i8 0, i8* %273
%274 = getelementptr inbounds i8, i8* %273, i64 1
store i8 0, i8* %274
%275 = getelementptr inbounds i8, i8* %274, i64 1
store i8 40, i8* %275
%276 = getelementptr inbounds i8, i8* %275, i64 1
store i8 0, i8* %276
%277 = getelementptr inbounds i8, i8* %276, i64 1
store i8 0, i8* %277
%278 = getelementptr inbounds i8, i8* %277, i64 1
store i8 0, i8* %278
%279 = getelementptr inbounds i8, i8* %278, i64 1
%280 = load i32, i32* %14
%281 = trunc i32 %280 to i8
store i8 %281, i8* %279
%282 = getelementptr inbounds i8, i8* %279, i64 1
%283 = load i32, i32* %14
%284 = ashr i32 %283, 8
%285 = trunc i32 %284 to i8
store i8 %285, i8* %282
%286 = getelementptr inbounds i8, i8* %282, i64 1
%287 = load i32, i32* %14
%288 = ashr i32 %287, 16
%289 = trunc i32 %288 to i8
store i8 %289, i8* %286
%290 = getelementptr inbounds i8, i8* %286, i64 1
%291 = load i32, i32* %14
%292 = ashr i32 %291, 24
%293 = trunc i32 %292 to i8
store i8 %293, i8* %290
%294 = getelementptr inbounds i8, i8* %290, i64 1
%295 = load i32, i32* %15
%296 = trunc i32 %295 to i8
store i8 %296, i8* %294
%297 = getelementptr inbounds i8, i8* %294, i64 1
%298 = load i32, i32* %15
%299 = ashr i32 %298, 8
%300 = trunc i32 %299 to i8
store i8 %300, i8* %297
%301 = getelementptr inbounds i8, i8* %297, i64 1
%302 = load i32, i32* %15
%303 = ashr i32 %302, 16
%304 = trunc i32 %303 to i8
store i8 %304, i8* %301
%305 = getelementptr inbounds i8, i8* %301, i64 1
%306 = load i32, i32* %15
%307 = ashr i32 %306, 24
%308 = trunc i32 %307 to i8
store i8 %308, i8* %305
%309 = getelementptr inbounds i8, i8* %305, i64 1
store i8 1, i8* %309
%310 = getelementptr inbounds i8, i8* %309, i64 1
store i8 0, i8* %310
%311 = getelementptr inbounds i8, i8* %310, i64 1
store i8 24, i8* %311
%312 = getelementptr inbounds i8, i8* %311, i64 1
store i8 0, i8* %312
%313 = getelementptr inbounds i8, i8* %312, i64 1
%314 = getelementptr inbounds i8, i8* %248, i64 54
br label %315
315: ; preds = %315, %247
%316 = phi i8* [ %313, %247 ], [ %317, %315 ]
store i8 0, i8* %316
%317 = getelementptr inbounds i8, i8* %316, i64 1
%318 = icmp eq i8* %317, %314
br i1 %318, label %319, label %315
319: ; preds = %315
%320 = bitcast [3 x i8]* %24 to i8*
%321 = getelementptr inbounds [54 x i8], [54 x i8]* %23, i64 0, i64 0
%322 = load i32*, i32** %7
%323 = call i32 @fwrite(i8* %321, i32 1, i32 54, i32* %322)
store i32 0, i32* %16
br label %324
324: ; preds = %350, %319
%325 = load i32, i32* %16
%326 = load i32, i32* %15
%327 = icmp slt i32 %325, %326
br i1 %327, label %328, label %353
328: ; preds = %324
%329 = load i8*, i8** %13
%330 = load i32, i32* %14
%331 = load i32, i32* %15
%332 = load i32, i32* %16
%333 = sub nsw i32 %331, %332
%334 = sub nsw i32 %333, 1
%335 = mul nsw i32 %330, %334
%336 = mul nsw i32 %335, 3
%337 = sext i32 %336 to i64
%338 = getelementptr inbounds i8, i8* %329, i64 %337
%339 = load i32, i32* %14
%340 = load i32*, i32** %7
%341 = call i32 @fwrite(i8* %338, i32 3, i32 %339, i32* %340)
%342 = getelementptr inbounds [3 x i8], [3 x i8]* %24, i64 0, i64 0
%343 = load i32, i32* %14
%344 = mul nsw i32 %343, 3
%345 = srem i32 %344, 4
%346 = sub nsw i32 4, %345
%347 = srem i32 %346, 4
%348 = load i32*, i32** %7
%349 = call i32 @fwrite(i8* %342, i32 1, i32 %347, i32* %348)
br label %350
350: ; preds = %328
%351 = load i32, i32* %16
%352 = add nsw i32 %351, 1
store i32 %352, i32* %16
br label %324
353: ; preds = %324
%354 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%355 = load i32*, i32** %6
%356 = call i32 @fclose(i32* %355)
%357 = load i32*, i32** %7
%358 = call i32 @fclose(i32* %357)
%359 = load double**, double*** %9
%360 = load i32, i32* %8
%361 = call i32 @destroyNodeArrays(double** %359, i32 %360)
%362 = load double**, double*** %10
%363 = load i32, i32* %14
%364 = load i32, i32* %15
%365 = call i32 @destroyColorArrays(double** %362, i32 %363, i32 %364)
%366 = load double**, double*** %11
%367 = load i32, i32* %14
%368 = load i32, i32* %15
%369 = call i32 @destroyColorArrays(double** %366, i32 %367, i32 %368)
%370 = load double**, double*** %12
%371 = load i32, i32* %14
%372 = load i32, i32* %15
%373 = call i32 @destroyColorArrays(double** %370, i32 %371, i32 %372)
%374 = load i8*, i8** %13
%375 = call i32 @free(i8* %374)
ret i32 0
}

LLVM IR (-O2):
@.str = [64 x i8] c"Incorrect number of arguments. \0A Usage:%s inputfile outputfile\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [48 x i8] c"Error: %s cannot be opened, or may not exist. \0A\00"
@.str.4 = [80 x i8] c"Size is: %d. Bottom layer will have %d nodes, and layer above it will have %d.\0A\00"
@.str.5 = [10 x i8] c"width: %d\00"
@.str.6 = [29 x i8] c"(%d,%d) = R:%lf/G:%lf/B:%lf\0A\00"
@str = [6 x i8] c"Done.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [54 x i8]
%4 = alloca [3 x i8]
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32* %13, null
br i1 %17, label %18, label %22
18: ; preds = %10
%19 = load i8*, i8** %11
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %10
%23 = icmp eq i32* %16, null
br i1 %23, label %24, label %29
24: ; preds = %22
%25 = load i8*, i8** %14
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = tail call i32 @fclose(i32* %13)
%28 = tail call i32 @exit(i32 -1)
unreachable
29: ; preds = %22
%30 = tail call i32 @getSize(i32* %13)
%31 = add nsw i32 %30, -1
%32 = tail call i64 @pow(i32 4, i32 %31)
%33 = trunc i64 %32 to i32
%34 = add nsw i32 %30, -2
%35 = tail call i64 @pow(i32 4, i32 %34)
%36 = trunc i64 %35 to i32
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @.str.4, i64 0, i64 0), i32 %30, i32 %33, i32 %36)
%38 = tail call double** @constructNodeArray(i32 %30)
%39 = tail call i32 @getBeliefs(i32* %13, double** %38, i32 %30)
%40 = tail call i32 @calculateImagePixels(i32 %30)
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %40)
%42 = mul nsw i32 %40, %30
%43 = add nsw i32 %42, %31
%44 = tail call double** @constructColorArray(i32 %40, i32 %43)
%45 = tail call double** @constructColorArray(i32 %40, i32 %43)
%46 = tail call double** @constructColorArray(i32 %40, i32 %43)
%47 = mul i32 %40, 3
%48 = mul i32 %47, %43
%49 = tail call i64 @malloc(i32 %48)
%50 = inttoptr i64 %49 to i8*
%51 = tail call i32 @fillColorArrays(i8* %50, double** %38, i32 %30, double** %44, double** %45, double** %46)
%52 = trunc i32 %48 to i8
%53 = add i8 %52, 54
%54 = icmp sgt i32 %40, 0
br i1 %54, label %55, label %117
55: ; preds = %29
%56 = icmp sgt i32 %43, 0
%57 = add nuw nsw i32 %40, 1
%58 = zext i32 %40 to i64
%59 = zext i32 %40 to i64
%60 = zext i32 %43 to i64
br label %61
61: ; preds = %55, %114
%62 = phi i64 [ 0, %55 ], [ %115, %114 ]
br i1 %56, label %63, label %114
63: ; preds = %61
%64 = getelementptr inbounds double*, double** %44, i64 %62
%65 = getelementptr inbounds double*, double** %45, i64 %62
%66 = getelementptr inbounds double*, double** %46, i64 %62
%67 = trunc i64 %62 to i32
br label %68
68: ; preds = %63, %68
%69 = phi i64 [ 0, %63 ], [ %91, %68 ]
%70 = load double*, double** %64
%71 = getelementptr inbounds double, double* %70, i64 %69
%72 = load double, double* %71
%73 = fmul double %72, 2.550000e+02
%74 = fptosi double %73 to i32
%75 = load double*, double** %65
%76 = getelementptr inbounds double, double* %75, i64 %69
%77 = load double, double* %76
%78 = fmul double %77, 2.550000e+02
%79 = fptosi double %78 to i32
%80 = load double*, double** %66
%81 = getelementptr inbounds double, double* %80, i64 %69
%82 = load double, double* %81
%83 = fmul double %82, 2.550000e+02
%84 = fptosi double %83 to i32
%85 = icmp slt i32 %74, 255
%86 = select i1 %85, i32 %74, i32 255
%87 = icmp slt i32 %79, 255
%88 = select i1 %87, i32 %79, i32 255
%89 = icmp slt i32 %84, 255
%90 = select i1 %89, i32 %84, i32 255
%91 = add nuw nsw i64 %69, 1
%92 = trunc i64 %91 to i32
%93 = srem i32 %92, %57
%94 = icmp eq i32 %93, 0
%95 = icmp ugt i64 %69, 1
%96 = and i1 %95, %94
%97 = trunc i64 %69 to i32
%98 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %67, i32 %97, double %72, double %77, double %82)
%99 = mul nsw i64 %69, %58
%100 = add nuw nsw i64 %99, %62
%101 = mul nsw i64 %100, 3
%102 = trunc i32 %90 to i8
%103 = select i1 %96, i8 10, i8 %102
%104 = getelementptr inbounds i8, i8* %50, i64 %101
store i8 %103, i8* %104
%105 = trunc i32 %88 to i8
%106 = select i1 %96, i8 20, i8 %105
%107 = add nuw nsw i64 %101, 1
%108 = getelementptr inbounds i8, i8* %50, i64 %107
store i8 %106, i8* %108
%109 = trunc i32 %86 to i8
%110 = select i1 %96, i8 -56, i8 %109
%111 = add nuw nsw i64 %101, 2
%112 = getelementptr inbounds i8, i8* %50, i64 %111
store i8 %110, i8* %112
%113 = icmp eq i64 %91, %60
br i1 %113, label %114, label %68
114: ; preds = %68, %61
%115 = add nuw nsw i64 %62, 1
%116 = icmp eq i64 %115, %59
br i1 %116, label %117, label %61
117: ; preds = %114, %29
%118 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 0
store i8 66, i8* %118
%119 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 1
store i8 77, i8* %119
%120 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 2
store i8 %53, i8* %120
%121 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 3
%122 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 10
store i8 54, i8* %122
%123 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 11
store i8 0, i8* %123
%124 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 12
store i8 0, i8* %124
%125 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 13
store i8 0, i8* %125
%126 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 14
store i8 40, i8* %126
%127 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 15
store i8 0, i8* %127
%128 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 16
store i8 0, i8* %128
%129 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 17
store i8 0, i8* %129
%130 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 18
%131 = trunc i32 %40 to i8
store i8 %131, i8* %130
%132 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 19
%133 = lshr i32 %40, 8
%134 = trunc i32 %133 to i8
store i8 %134, i8* %132
%135 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 20
%136 = lshr i32 %40, 16
%137 = trunc i32 %136 to i8
store i8 %137, i8* %135
%138 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 21
%139 = lshr i32 %40, 24
%140 = trunc i32 %139 to i8
store i8 %140, i8* %138
%141 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 22
%142 = trunc i32 %43 to i8
store i8 %142, i8* %141
%143 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 23
%144 = lshr i32 %43, 8
%145 = trunc i32 %144 to i8
store i8 %145, i8* %143
%146 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 24
%147 = lshr i32 %43, 16
%148 = trunc i32 %147 to i8
store i8 %148, i8* %146
%149 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 25
%150 = lshr i32 %43, 24
%151 = trunc i32 %150 to i8
store i8 %151, i8* %149
%152 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 26
store i8 1, i8* %152
%153 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 27
store i8 0, i8* %153
%154 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 28
store i8 24, i8* %154
%155 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 29
%156 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%157 = call i32 @fwrite(i8* %118, i32 1, i32 54, i32* %16)
%158 = icmp sgt i32 %43, 0
br i1 %158, label %159, label %175
159: ; preds = %117
%160 = sub i32 0, %47
%161 = and i32 %160, 3
%162 = zext i32 %43 to i64
br label %163
163: ; preds = %159, %163
%164 = phi i64 [ 0, %159 ], [ %173, %163 ]
%165 = trunc i64 %164 to i32
%166 = xor i32 %165, -1
%167 = add i32 %43, %166
%168 = mul i32 %47, %167
%169 = sext i32 %168 to i64
%170 = getelementptr inbounds i8, i8* %50, i64 %169
%171 = call i32 @fwrite(i8* %170, i32 3, i32 %40, i32* %16)
%172 = call i32 @fwrite(i8* %156, i32 1, i32 %161, i32* %16)
%173 = add nuw nsw i64 %164, 1
%174 = icmp eq i64 %173, %162
br i1 %174, label %175, label %163
175: ; preds = %163, %117
%176 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%177 = call i32 @fclose(i32* %13)
%178 = call i32 @fclose(i32* %16)
%179 = call i32 @destroyNodeArrays(double** %38, i32 %30)
%180 = call i32 @destroyColorArrays(double** %44, i32 %40, i32 %43)
%181 = call i32 @destroyColorArrays(double** %45, i32 %40, i32 %43)
%182 = call i32 @destroyColorArrays(double** %46, i32 %40, i32 %43)
%183 = call i32 @free(i8* %50)
ret i32 0
}