#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 RG[4] = {32, 96, 159, 223};
  int B[2] = {64, 192};
  arch = fopen("minimOS64.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 < 4; r++) {
    for (g = 0; g < 4; g++) {
      for (b = 0; b < 2; b++) {
        i++;
        fprintf(arch, "%c%c%c", RG[r], RG[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    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0xea3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea8(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xea5(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xea2(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe9f(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe74(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe91(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d4 <main+0x94>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13be <main+0x27e>
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
jge    129d <main+0x15d>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    128a <main+0x14a>
movl   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x24(%rbp)
jge    1277 <main+0x137>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    1264 <main+0x124>
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    0xe05(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120e <main+0xce>
jmp    1269 <main+0x129>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11fd <main+0xbd>
jmp    127c <main+0x13c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ec <main+0xac>
jmp    128f <main+0x14f>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11db <main+0x9b>
mov    -0x28(%rbp),%esi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xf,-0x18(%rbp)
cmpl   $0xff,-0x18(%rbp)
jge    12f3 <main+0x1b3>
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    0xd76(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0xf,%eax
mov    %eax,-0x18(%rbp)
jmp    12b5 <main+0x175>
mov    -0x28(%rbp),%esi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    139d <main+0x25d>
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    138a <main+0x24a>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    1377 <main+0x237>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%edx
movslq -0x18(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%ecx
movslq -0x1c(%rbp),%rax
mov    -0x58(%rbp,%rax,4),%r8d
lea    0xcf2(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    132d <main+0x1ed>
jmp    137c <main+0x23c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    131c <main+0x1dc>
jmp    138f <main+0x24f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    130b <main+0x1cb>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%esi
lea    0xcf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xeb1(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     15d1 <main+0x481>
mov    %rax,%rbx
lea    0xea2(%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    0xd2b(%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    0xb83(%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    $0x20,%ecx
mov    $0x40,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x20,%ecx
mov    $0xc0,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x60,%ecx
mov    $0x40,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x60,%ecx
mov    $0xc0,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x9f,%ecx
mov    $0x40,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x9f,%ecx
mov    $0xc0,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xdf,%ecx
mov    $0x40,%r8d
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0xdf,%ecx
mov    $0xc0,%r8d
call   1060 <fprintf@plt>
add    $0x4,%r15
cmp    $0x10,%r15
jne    14e0 <main+0x390>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xaac(%rip),%rdi
xor    %ebx,%ebx
mov    $0x40,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    15e2 <main+0x492>
lea    0xab7(%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.RG = [4 x i32] [i32 32, i32 96, i32 159, i32 223]
@__const.main.B = [2 x i32] [i32 64, i32 192]
@.str = [14 x i8] c"minimOS64.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 [2 x i32]
store i32 0, i32* %1
store i32 0, i32* %8
%13 = bitcast [2 x i32]* %9 to i8*
%14 = bitcast [4 x i32]* %10 to i8*
%15 = bitcast [4 x i32]* %11 to i8*
%16 = bitcast [2 x i32]* %12 to i8*
%17 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %2
%18 = load i32*, i32** %2
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = 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 %138
22: ; preds = %0
store i32 0, i32* %6
br label %23
23: ; preds = %71, %22
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 2
br i1 %25, label %26, label %74
26: ; preds = %23
store i32 0, i32* %3
br label %27
27: ; preds = %67, %26
%28 = load i32, i32* %3
%29 = icmp slt i32 %28, 2
br i1 %29, label %30, label %70
30: ; preds = %27
store i32 0, i32* %7
br label %31
31: ; preds = %63, %30
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 2
br i1 %33, label %34, label %66
34: ; preds = %31
store i32 0, i32* %5
br label %35
35: ; preds = %59, %34
%36 = load i32, i32* %5
%37 = icmp slt i32 %36, 2
br i1 %37, label %38, label %62
38: ; preds = %35
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
%41 = load i32, i32* %6
%42 = shl i32 %41, 1
%43 = load i32, i32* %7
%44 = or i32 %42, %43
store i32 %44, i32* %4
%45 = load i32*, i32** %2
%46 = load i32, i32* %3
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = load i32, i32* %4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = load i32, i32* %5
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = call i32 @fprintf(i32* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %49, i32 %53, i32 %57)
br label %59
59: ; preds = %38
%60 = load i32, i32* %5
%61 = add nsw i32 %60, 1
store i32 %61, i32* %5
br label %35
62: ; preds = %35
br label %63
63: ; preds = %62
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %31
66: ; preds = %31
br label %67
67: ; preds = %66
%68 = load i32, i32* %3
%69 = add nsw i32 %68, 1
store i32 %69, i32* %3
br label %27
70: ; preds = %27
br label %71
71: ; preds = %70
%72 = load i32, i32* %6
%73 = add nsw i32 %72, 1
store i32 %73, i32* %6
br label %23
74: ; preds = %23
%75 = load i32, i32* %8
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %75)
store i32 15, i32* %4
br label %77
77: ; preds = %88, %74
%78 = load i32, i32* %4
%79 = icmp slt i32 %78, 255
br i1 %79, label %80, label %91
80: ; preds = %77
%81 = load i32, i32* %8
%82 = add nsw i32 %81, 1
store i32 %82, i32* %8
%83 = load i32*, i32** %2
%84 = load i32, i32* %4
%85 = load i32, i32* %4
%86 = load i32, i32* %4
%87 = call i32 @fprintf(i32* %83, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %84, i32 %85, i32 %86)
br label %88
88: ; preds = %80
%89 = load i32, i32* %4
%90 = add nsw i32 %89, 15
store i32 %90, i32* %4
br label %77
91: ; preds = %77
%92 = load i32, i32* %8
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %92)
store i32 0, i32* %3
br label %94
94: ; preds = %130, %91
%95 = load i32, i32* %3
%96 = icmp slt i32 %95, 4
br i1 %96, label %97, label %133
97: ; preds = %94
store i32 0, i32* %4
br label %98
98: ; preds = %126, %97
%99 = load i32, i32* %4
%100 = icmp slt i32 %99, 4
br i1 %100, label %101, label %129
101: ; preds = %98
store i32 0, i32* %5
br label %102
102: ; preds = %122, %101
%103 = load i32, i32* %5
%104 = icmp slt i32 %103, 2
br i1 %104, label %105, label %125
105: ; preds = %102
%106 = load i32, i32* %8
%107 = add nsw i32 %106, 1
store i32 %107, i32* %8
%108 = load i32*, i32** %2
%109 = load i32, i32* %3
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 %110
%112 = load i32, i32* %111
%113 = load i32, i32* %4
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 %114
%116 = load i32, i32* %115
%117 = load i32, i32* %5
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 %118
%120 = load i32, i32* %119
%121 = call i32 @fprintf(i32* %108, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %112, i32 %116, i32 %120)
br label %122
122: ; preds = %105
%123 = load i32, i32* %5
%124 = add nsw i32 %123, 1
store i32 %124, i32* %5
br label %102
125: ; preds = %102
br label %126
126: ; preds = %125
%127 = load i32, i32* %4
%128 = add nsw i32 %127, 1
store i32 %128, i32* %4
br label %98
129: ; preds = %98
br label %130
130: ; preds = %129
%131 = load i32, i32* %3
%132 = add nsw i32 %131, 1
store i32 %132, i32* %3
br label %94
133: ; preds = %94
%134 = load i32*, i32** %2
%135 = call i32 @fclose(i32* %134)
%136 = load i32, i32* %8
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %136)
store i32 0, i32* %1
br label %138
138: ; preds = %133, %20
%139 = load i32, i32* %1
ret i32 %139
}

LLVM IR (-O2):
@__const.main.RG = [4 x i32] [i32 32, i32 96, i32 159, i32 223]
@.str = [14 x i8] c"minimOS64.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 ([14 x i8], [14 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 %57
40: ; preds = %3, %40
%41 = phi i64 [ 0, %3 ], [ %52, %40 ]
%42 = getelementptr inbounds [4 x i32], [4 x i32]* @__const.main.RG, 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 32, i32 64)
%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 32, i32 192)
%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 96, i32 64)
%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 96, i32 192)
%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 159, i32 64)
%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 159, i32 192)
%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 223, i32 64)
%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 223, i32 192)
%52 = add nuw nsw i64 %41, 1
%53 = icmp eq i64 %52, 4
br i1 %53, label %54, label %40
54: ; preds = %40
%55 = tail call i32 @fclose(i32* %1)
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 64)
br label %57
57: ; preds = %54, %38
%58 = phi i32 [ -1, %38 ], [ 0, %54 ]
ret i32 %58
}