#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  FILE *arch;
  int r, g, b, h, l, i = 0;
  int byte[2] = {0, 255};
  int four[4] = {0, 85, 170, 255};
  int B[4] = {32, 96, 159, 223};
  int G[8] = {16, 48, 80, 112, 143, 175, 207, 239};
  int R[7] = {18, 55, 91, 128, 164, 200, 237};
  arch = fopen("minimOS.pal", "w");
  if (arch == NULL) {
    printf("*** CANNOT WRITE ***\n");
    return -1;
  }
  for (h = 0; h < 2; h++) {
    for (r = 0; r < 2; r++) {
      for (l = 0; l < 2; l++) {
        for (b = 0; b < 2; b++) {
          i++;
          g = (h << 1) | l;
          fprintf(arch, "%c%c%c", byte[r], four[g], byte[b]);
        }
      }
    }
  }
  printf("Created %d system colours\n", i);
  for (g = 15; g < 255; g += 15) {
    i++;
    fprintf(arch, "%c%c%c", g, g, g);
  }
  printf("Added system greyscale (total %d entries)\n", i);
  for (r = 0; r < 7; r++) {
    for (l = 0; l < 2; l++) {
      for (g = 0; g < 8; g++) {
        for (h = 0; h < 2; h++) {
          i++;
          b = (h << 1) | l;
          fprintf(arch, "%c%c%c", R[r], G[g], B[b]);
        }
      }
    }
  }
  fclose(arch);
  printf("Finished palette with %d entries\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0xea0(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea5(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xea2(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe9f(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe9c(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe99(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0xe96(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe90(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xe8d(%rip),%rax
mov    %rax,-0x90(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x88(%rbp)
mov    0xe81(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    0xe7f(%rip),%eax
mov    %eax,-0x78(%rbp)
lea    0xe79(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1228 <main+0xe8>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1445 <main+0x305>
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
jge    12f1 <main+0x1b1>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    12de <main+0x19e>
movl   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x24(%rbp)
jge    12cb <main+0x18b>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    12b8 <main+0x178>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
movslq -0x18(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%ecx
movslq -0x1c(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%r8d
lea    0xdeb(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1262 <main+0x122>
jmp    12bd <main+0x17d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1251 <main+0x111>
jmp    12d0 <main+0x190>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1240 <main+0x100>
jmp    12e3 <main+0x1a3>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    122f <main+0xef>
mov    -0x28(%rbp),%esi
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xf,-0x18(%rbp)
cmpl   $0xff,-0x18(%rbp)
jge    1347 <main+0x207>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xd5c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0xf,%eax
mov    %eax,-0x18(%rbp)
jmp    1309 <main+0x1c9>
mov    -0x28(%rbp),%esi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x7,-0x14(%rbp)
jge    1424 <main+0x2e4>
movl   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x24(%rbp)
jge    1411 <main+0x2d1>
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    13fe <main+0x2be>
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
jge    13eb <main+0x2ab>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%edx
movslq -0x18(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%ecx
movslq -0x1c(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%r8d
lea    0xcb8(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1392 <main+0x252>
jmp    13f0 <main+0x2b0>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1381 <main+0x241>
jmp    1403 <main+0x2c3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1370 <main+0x230>
jmp    1416 <main+0x2d6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    135f <main+0x21f>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%esi
lea    0xca6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xebd(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1811 <main+0x6c1>
mov    %rax,%rbx
lea    0xeac(%rip),%r14
xor    %r15d,%r15d
mov    %rax,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0xff,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0x55,%ecx
xor    %r8d,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0x55,%ecx
mov    $0xff,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
mov    $0xff,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
mov    $0x55,%ecx
xor    %r8d,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
mov    $0x55,%ecx
mov    $0xff,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0xaa,%ecx
xor    %r8d,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0xaa,%ecx
mov    $0xff,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0xff,%ecx
xor    %r8d,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0xff,%ecx
mov    $0xff,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
mov    $0xaa,%ecx
xor    %r8d,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
mov    $0xaa,%ecx
mov    $0xff,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
mov    $0xff,%ecx
xor    %r8d,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
mov    $0xff,%ecx
mov    $0xff,%r8d
call   1060 <fprintf@plt>
lea    0xd35(%rip),%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xf,%edx
mov    $0xf,%ecx
mov    $0xf,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1e,%edx
mov    $0x1e,%ecx
mov    $0x1e,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2d,%edx
mov    $0x2d,%ecx
mov    $0x2d,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3c,%edx
mov    $0x3c,%ecx
mov    $0x3c,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4b,%edx
mov    $0x4b,%ecx
mov    $0x4b,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5a,%edx
mov    $0x5a,%ecx
mov    $0x5a,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x69,%edx
mov    $0x69,%ecx
mov    $0x69,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x78,%edx
mov    $0x78,%ecx
mov    $0x78,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x87,%edx
mov    $0x87,%ecx
mov    $0x87,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x96,%edx
mov    $0x96,%ecx
mov    $0x96,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa5,%edx
mov    $0xa5,%ecx
mov    $0xa5,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xb4,%edx
mov    $0xb4,%ecx
mov    $0xb4,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xc3,%edx
mov    $0xc3,%ecx
mov    $0xc3,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xd2,%edx
mov    $0xd2,%ecx
mov    $0xd2,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xe1,%edx
mov    $0xe1,%ecx
mov    $0xe1,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xf0,%edx
mov    $0xf0,%ecx
mov    $0xf0,%r8d
call   1060 <fprintf@plt>
lea    0xb8d(%rip),%rdi
mov    $0x20,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xb2e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15,%r12,1),%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x10,%ecx
mov    $0x20,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x10,%ecx
mov    $0x9f,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x30,%ecx
mov    $0x20,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x30,%ecx
mov    $0x9f,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x50,%ecx
mov    $0x20,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x50,%ecx
mov    $0x9f,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x70,%ecx
mov    $0x20,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x70,%ecx
mov    $0x9f,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x8f,%ecx
mov    $0x20,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x8f,%ecx
mov    $0x9f,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xaf,%ecx
mov    $0x20,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xaf,%ecx
mov    $0x9f,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xcf,%ecx
mov    $0x20,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xcf,%ecx
mov    $0x9f,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xef,%ecx
mov    $0x20,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xef,%ecx
mov    $0x9f,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x10,%ecx
mov    $0x60,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x10,%ecx
mov    $0xdf,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x30,%ecx
mov    $0x60,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x30,%ecx
mov    $0xdf,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x50,%ecx
mov    $0x60,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x50,%ecx
mov    $0xdf,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x70,%ecx
mov    $0x60,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x70,%ecx
mov    $0xdf,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x8f,%ecx
mov    $0x60,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x8f,%ecx
mov    $0xdf,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xaf,%ecx
mov    $0x60,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xaf,%ecx
mov    $0xdf,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xcf,%ecx
mov    $0x60,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xcf,%ecx
mov    $0xdf,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xef,%ecx
mov    $0x60,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xef,%ecx
mov    $0xdf,%r8d
call   1060 <fprintf@plt>
add    $0x4,%r15
cmp    $0x1c,%r15
jne    14e0 <main+0x390>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0x876(%rip),%rdi
xor    %ebx,%ebx
mov    $0x100,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1822 <main+0x6d2>
lea    0x881(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.byte = [2 x i32] [i32 0, i32 255]
@__const.main.four = [4 x i32] [i32 0, i32 85, i32 170, i32 255]
@__const.main.B = [4 x i32] [i32 32, i32 96, i32 159, i32 223]
@__const.main.G = [8 x i32] [i32 16, i32 48, i32 80, i32 112, i32 143, i32 175, i32 207, i32 239]
@__const.main.R = [7 x i32] [i32 18, i32 55, i32 91, i32 128, i32 164, i32 200, i32 237]
@.str = [12 x i8] c"minimOS.pal\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [22 x i8] c"*** CANNOT WRITE ***\0A\00"
@.str.3 = [7 x i8] c"%c%c%c\00"
@.str.4 = [27 x i8] c"Created %d system colours\0A\00"
@.str.5 = [43 x i8] c"Added system greyscale (total %d entries)\0A\00"
@.str.6 = [34 x i8] c"Finished palette with %d entries\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i32]
%10 = alloca [4 x i32]
%11 = alloca [4 x i32]
%12 = alloca [8 x i32]
%13 = alloca [7 x i32]
store i32 0, i32* %1
store i32 0, i32* %8
%14 = bitcast [2 x i32]* %9 to i8*
%15 = bitcast [4 x i32]* %10 to i8*
%16 = bitcast [4 x i32]* %11 to i8*
%17 = bitcast [8 x i32]* %12 to i8*
%18 = bitcast [7 x i32]* %13 to i8*
%19 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %2
%20 = load i32*, i32** %2
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %152
24: ; preds = %0
store i32 0, i32* %6
br label %25
25: ; preds = %73, %24
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 2
br i1 %27, label %28, label %76
28: ; preds = %25
store i32 0, i32* %3
br label %29
29: ; preds = %69, %28
%30 = load i32, i32* %3
%31 = icmp slt i32 %30, 2
br i1 %31, label %32, label %72
32: ; preds = %29
store i32 0, i32* %7
br label %33
33: ; preds = %65, %32
%34 = load i32, i32* %7
%35 = icmp slt i32 %34, 2
br i1 %35, label %36, label %68
36: ; preds = %33
store i32 0, i32* %5
br label %37
37: ; preds = %61, %36
%38 = load i32, i32* %5
%39 = icmp slt i32 %38, 2
br i1 %39, label %40, label %64
40: ; preds = %37
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
%43 = load i32, i32* %6
%44 = shl i32 %43, 1
%45 = load i32, i32* %7
%46 = or i32 %44, %45
store i32 %46, i32* %4
%47 = load i32*, i32** %2
%48 = load i32, i32* %3
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = call i32 @fprintf(i32* %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %51, i32 %55, i32 %59)
br label %61
61: ; preds = %40
%62 = load i32, i32* %5
%63 = add nsw i32 %62, 1
store i32 %63, i32* %5
br label %37
64: ; preds = %37
br label %65
65: ; preds = %64
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %33
68: ; preds = %33
br label %69
69: ; preds = %68
%70 = load i32, i32* %3
%71 = add nsw i32 %70, 1
store i32 %71, i32* %3
br label %29
72: ; preds = %29
br label %73
73: ; preds = %72
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %25
76: ; preds = %25
%77 = load i32, i32* %8
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %77)
store i32 15, i32* %4
br label %79
79: ; preds = %90, %76
%80 = load i32, i32* %4
%81 = icmp slt i32 %80, 255
br i1 %81, label %82, label %93
82: ; preds = %79
%83 = load i32, i32* %8
%84 = add nsw i32 %83, 1
store i32 %84, i32* %8
%85 = load i32*, i32** %2
%86 = load i32, i32* %4
%87 = load i32, i32* %4
%88 = load i32, i32* %4
%89 = call i32 @fprintf(i32* %85, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %86, i32 %87, i32 %88)
br label %90
90: ; preds = %82
%91 = load i32, i32* %4
%92 = add nsw i32 %91, 15
store i32 %92, i32* %4
br label %79
93: ; preds = %79
%94 = load i32, i32* %8
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %94)
store i32 0, i32* %3
br label %96
96: ; preds = %144, %93
%97 = load i32, i32* %3
%98 = icmp slt i32 %97, 7
br i1 %98, label %99, label %147
99: ; preds = %96
store i32 0, i32* %7
br label %100
100: ; preds = %140, %99
%101 = load i32, i32* %7
%102 = icmp slt i32 %101, 2
br i1 %102, label %103, label %143
103: ; preds = %100
store i32 0, i32* %4
br label %104
104: ; preds = %136, %103
%105 = load i32, i32* %4
%106 = icmp slt i32 %105, 8
br i1 %106, label %107, label %139
107: ; preds = %104
store i32 0, i32* %6
br label %108
108: ; preds = %132, %107
%109 = load i32, i32* %6
%110 = icmp slt i32 %109, 2
br i1 %110, label %111, label %135
111: ; preds = %108
%112 = load i32, i32* %8
%113 = add nsw i32 %112, 1
store i32 %113, i32* %8
%114 = load i32, i32* %6
%115 = shl i32 %114, 1
%116 = load i32, i32* %7
%117 = or i32 %115, %116
store i32 %117, i32* %5
%118 = load i32*, i32** %2
%119 = load i32, i32* %3
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds [7 x i32], [7 x i32]* %13, i64 0, i64 %120
%122 = load i32, i32* %121
%123 = load i32, i32* %4
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds [8 x i32], [8 x i32]* %12, i64 0, i64 %124
%126 = load i32, i32* %125
%127 = load i32, i32* %5
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 %128
%130 = load i32, i32* %129
%131 = call i32 @fprintf(i32* %118, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %122, i32 %126, i32 %130)
br label %132
132: ; preds = %111
%133 = load i32, i32* %6
%134 = add nsw i32 %133, 1
store i32 %134, i32* %6
br label %108
135: ; preds = %108
br label %136
136: ; preds = %135
%137 = load i32, i32* %4
%138 = add nsw i32 %137, 1
store i32 %138, i32* %4
br label %104
139: ; preds = %104
br label %140
140: ; preds = %139
%141 = load i32, i32* %7
%142 = add nsw i32 %141, 1
store i32 %142, i32* %7
br label %100
143: ; preds = %100
br label %144
144: ; preds = %143
%145 = load i32, i32* %3
%146 = add nsw i32 %145, 1
store i32 %146, i32* %3
br label %96
147: ; preds = %96
%148 = load i32*, i32** %2
%149 = call i32 @fclose(i32* %148)
%150 = load i32, i32* %8
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %150)
store i32 0, i32* %1
br label %152
152: ; preds = %147, %22
%153 = load i32, i32* %1
ret i32 %153
}

LLVM IR (-O2):
@__const.main.R = [7 x i32] [i32 18, i32 55, i32 91, i32 128, i32 164, i32 200, i32 237]
@.str = [12 x i8] c"minimOS.pal\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [7 x i8] c"%c%c%c\00"
@.str.4 = [27 x i8] c"Created %d system colours\0A\00"
@.str.5 = [43 x i8] c"Added system greyscale (total %d entries)\0A\00"
@.str.6 = [34 x i8] c"Finished palette with %d entries\0A\00"
@str = [21 x i8] c"*** CANNOT WRITE ***\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %38, label %3
3: ; preds = %0
%4 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 0, i32 0)
%5 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 0, i32 255)
%6 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 85, i32 0)
%7 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 85, i32 255)
%8 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 255, i32 0, i32 0)
%9 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 255, i32 0, i32 255)
%10 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 255, i32 85, i32 0)
%11 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 255, i32 85, i32 255)
%12 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 170, i32 0)
%13 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 170, i32 255)
%14 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 255, i32 0)
%15 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 255, i32 255)
%16 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 255, i32 170, i32 0)
%17 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 255, i32 170, i32 255)
%18 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 255, i32 255, i32 0)
%19 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 255, i32 255, i32 255)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 16)
%21 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 15, i32 15, i32 15)
%22 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 30, i32 30, i32 30)
%23 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 45, i32 45, i32 45)
%24 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 60, i32 60, i32 60)
%25 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 75, i32 75, i32 75)
%26 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 90, i32 90, i32 90)
%27 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 105, i32 105, i32 105)
%28 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 120, i32 120, i32 120)
%29 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 135, i32 135, i32 135)
%30 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 150, i32 150, i32 150)
%31 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 165, i32 165, i32 165)
%32 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 180, i32 180, i32 180)
%33 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 195, i32 195, i32 195)
%34 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 210, i32 210, i32 210)
%35 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 225, i32 225, i32 225)
%36 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 240, i32 240, i32 240)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 32)
br label %40
38: ; preds = %0
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %81
40: ; preds = %3, %40
%41 = phi i64 [ 0, %3 ], [ %76, %40 ]
%42 = getelementptr inbounds [7 x i32], [7 x i32]* @__const.main.R, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 16, i32 32)
%45 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 16, i32 159)
%46 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 48, i32 32)
%47 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 48, i32 159)
%48 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 80, i32 32)
%49 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 80, i32 159)
%50 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 112, i32 32)
%51 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 112, i32 159)
%52 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 143, i32 32)
%53 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 143, i32 159)
%54 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 175, i32 32)
%55 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 175, i32 159)
%56 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 207, i32 32)
%57 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 207, i32 159)
%58 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 239, i32 32)
%59 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 239, i32 159)
%60 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 16, i32 96)
%61 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 16, i32 223)
%62 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 48, i32 96)
%63 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 48, i32 223)
%64 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 80, i32 96)
%65 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 80, i32 223)
%66 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 112, i32 96)
%67 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 112, i32 223)
%68 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 143, i32 96)
%69 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 143, i32 223)
%70 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 175, i32 96)
%71 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 175, i32 223)
%72 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 207, i32 96)
%73 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 207, i32 223)
%74 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 239, i32 96)
%75 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 239, i32 223)
%76 = add nuw nsw i64 %41, 1
%77 = icmp eq i64 %76, 7
br i1 %77, label %78, label %40
78: ; preds = %40
%79 = tail call i32 @fclose(i32* %1)
%80 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 256)
br label %81
81: ; preds = %78, %38
%82 = phi i32 [ -1, %38 ], [ 0, %78 ]
ret i32 %82
}