#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*/ _IONBF;
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned char *malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ sscanf(char *, char *, int *);
int /*<<< orphan*/ stdout;
void main(int argc, char **argv) {
  unsigned char *b;
  int i, j, sizex, sizey, padd;
  FILE *out, *in;
  setvbuf(stdout, NULL, _IONBF, 0);
  if (argc < 6)
    error("use: PIC2BMP <picture> <palette> <size_x> <size_y> <outpicture>\n");
  if (sscanf(argv[3], "%d", &sizex) == 0)
    error("Invalid x resolution.\n");
  if (sscanf(argv[4], "%d", &sizey) == 0)
    error("Invalid y resolution.\n");
  if ((out = fopen(argv[5], "wb")) == NULL)
    error("Unable to open output file.\n");
  b = malloc(1000000);
  memset(b, 0, 54);
  b[0] = 'B';
  b[1] = 'M';
  b[10] = 54;
  b[11] = 4;
  b[14] = 40;
  b[18] = sizex & 0xff;
  b[19] = sizex >> 8;
  b[22] = sizey & 0xff;
  b[23] = sizey >> 8;
  b[26] = 1;
  b[28] = 8;
  b[47] = 0;
  b[51] = 0;
  fwrite(b, 54, 1, out);
  if ((in = fopen(argv[2], "rb")) == NULL)
    error("Palette file does not exist.\n");
  fread(b, 3 * 256, 1, in);
  fclose(in);
  for (i = 0; i < 256; i++) {
    for (j = 2; j >= 0; j--)
      fputc(b[i * 3 + j] << 2, out);
    fputc(0, out);
  }
  if ((in = fopen(argv[1], "rb")) == NULL)
    error("Picture file does not exist.\n");
  fread(b, 1000000, 1, in);
  fclose(in);
  padd = (4 - (sizex & 3)) & 3;
  for (i = sizey - 1; i >= 0; i--) {
    for (j = 0; j < sizex; j++)
      fputc(b[i * sizex + j], out);
    for (j = padd; j > 0; j--)
      fputc(0, out);
  }
  fclose(out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1090 <setvbuf@plt>
cmpl   $0x6,-0x4(%rbp)
jge    11e2 <main+0x42>
lea    0xe23(%rip),%rdi
call   10a0 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe50(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x0,%rax
jne    1210 <main+0x70>
lea    0xe39(%rip),%rdi
call   10a0 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xe22(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x0,%rax
jne    123e <main+0x9e>
lea    0xe22(%rip),%rdi
call   10a0 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
lea    0xe25(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    126c <main+0xcc>
lea    0xe0e(%rip),%rdi
call   10a0 <error@plt>
mov    $0xf4240,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x36,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rax
movb   $0x42,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x4d,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x36,0xa(%rax)
mov    -0x18(%rbp),%rax
movb   $0x4,0xb(%rax)
mov    -0x18(%rbp),%rax
movb   $0x28,0xe(%rax)
mov    -0x24(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x12(%rax)
mov    -0x24(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x13(%rax)
mov    -0x28(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x16(%rax)
mov    -0x28(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x17(%rax)
mov    -0x18(%rbp),%rax
movb   $0x1,0x1a(%rax)
mov    -0x18(%rbp),%rax
movb   $0x8,0x1c(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x2f(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x33(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0x36,%esi
mov    $0x1,%edx
call   10c0 <fwrite@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd5b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1356 <main+0x1b6>
lea    0xd44(%rip),%rdi
call   10a0 <error@plt>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rcx
mov    $0x300,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jge    13e3 <main+0x243>
movl   $0x2,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     13ca <main+0x22a>
mov    -0x18(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
shl    $0x2,%eax
mov    -0x38(%rbp),%rsi
movzbl %al,%edi
call   1060 <fputc@plt>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1391 <main+0x1f1>
mov    -0x38(%rbp),%rsi
xor    %edi,%edi
call   1060 <fputc@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    137d <main+0x1dd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xca0(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1411 <main+0x271>
lea    0xca7(%rip),%rdi
call   10a0 <error@plt>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rcx
mov    $0xf4240,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%ecx
and    $0x3,%ecx
mov    $0x4,%eax
sub    %ecx,%eax
and    $0x3,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     14d4 <main+0x334>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1498 <main+0x2f8>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x24(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    -0x38(%rbp),%rsi
movzbl %al,%edi
call   1060 <fputc@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    145e <main+0x2be>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    14c1 <main+0x321>
mov    -0x38(%rbp),%rsi
xor    %edi,%edi
call   1060 <fputc@plt>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    149e <main+0x2fe>
jmp    14c6 <main+0x326>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    144d <main+0x2ad>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1090 <setvbuf@plt>
cmp    $0x5,%ebx
jg     11df <main+0x3f>
lea    0xe26(%rip),%rdi
call   10a0 <error@plt>
mov    0x18(%r14),%rdi
lea    0xe57(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1080 <sscanf@plt>
test   %rax,%rax
jne    1205 <main+0x65>
lea    0xe44(%rip),%rdi
call   10a0 <error@plt>
mov    0x20(%r14),%rdi
lea    0xe31(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1080 <sscanf@plt>
test   %rax,%rax
jne    122b <main+0x8b>
lea    0xe35(%rip),%rdi
call   10a0 <error@plt>
mov    0x28(%r14),%rdi
lea    0xe3c(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    124f <main+0xaf>
lea    0xe2b(%rip),%rdi
call   10a0 <error@plt>
mov    $0xf4240,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x36,%edx
call   1050 <memset@plt>
movw   $0x4d42,(%rbx)
movw   $0x436,0xa(%rbx)
movb   $0x28,0xe(%rbx)
movzwl 0x4(%rsp),%eax
mov    %ax,0x12(%rbx)
mov    0x8(%rsp),%eax
mov    %al,0x16(%rbx)
mov    %ah,0x17(%rbx)
movb   $0x1,0x1a(%rbx)
movb   $0x8,0x1c(%rbx)
movb   $0x0,0x2f(%rbx)
movb   $0x0,0x33(%rbx)
mov    %rbx,%rdi
mov    $0x36,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   10c0 <fwrite@plt>
mov    0x10(%r14),%rdi
lea    0xdd5(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    12d6 <main+0x136>
lea    0xdc4(%rip),%rdi
call   10a0 <error@plt>
mov    %rbx,%rdi
mov    $0x300,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x2,%ebp
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%eax
shl    $0x2,%al
movzbl %al,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
movzbl -0x1(%rbx,%rbp,1),%eax
shl    $0x2,%al
movzbl %al,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
movzbl -0x2(%rbx,%rbp,1),%eax
shl    $0x2,%al
movzbl %al,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
add    $0x3,%rbp
cmp    $0x302,%rbp
jne    1300 <main+0x160>
mov    0x8(%r14),%rdi
lea    0xd38(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1373 <main+0x1d3>
lea    0xd45(%rip),%rdi
call   10a0 <error@plt>
mov    %rbx,0x10(%rsp)
mov    %rbx,%rdi
mov    $0xf4240,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%r14d
test   %r14d,%r14d
jle    1439 <main+0x299>
mov    0x4(%rsp),%eax
mov    %eax,%r15d
neg    %r15d
and    $0x3,%r15d
lea    -0x1(%r14),%ebp
lea    0x1(%r15),%ecx
mov    %ecx,0xc(%rsp)
mov    0x10(%rsp),%r12
test   %eax,%eax
jle    1400 <main+0x260>
cs nopw 0x0(%rax,%rax,1)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
imul   %ebp,%eax
cltq
add    %r12,%rax
movzbl (%rbx,%rax,1),%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
mov    0x4(%rsp),%eax
add    $0x1,%rbx
cmp    %eax,%ebx
jl     13e0 <main+0x240>
mov    0xc(%rsp),%ebx
test   %r15d,%r15d
je     1422 <main+0x282>
nopl   0x0(%rax)
xor    %edi,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jg     1410 <main+0x270>
cmp    $0x2,%r14d
jl     1439 <main+0x299>
add    $0xffffffff,%r14d
mov    0x4(%rsp),%eax
add    $0xffffffff,%ebp
test   %eax,%eax
jg     13d0 <main+0x230>
jmp    1400 <main+0x260>
mov    %r13,%rdi
call   1040 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [65 x i8] c"use: PIC2BMP <picture> <palette> <size_x> <size_y> <outpicture>\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Invalid x resolution.\0A\00"
@.str.3 = [23 x i8] c"Invalid y resolution.\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [29 x i8] c"Unable to open output file.\0A\00"
@.str.6 = [3 x i8] c"rb\00"
@.str.7 = [30 x i8] c"Palette file does not exist.\0A\00"
@.str.8 = [30 x i8] c"Picture file does not exist.\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%13 = load i32, i32* @stdout
%14 = load i32, i32* @_IONBF
%15 = call i32 @setvbuf(i32 %13, i32* null, i32 %14, i32 0)
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 6
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @error(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %2
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 3
%23 = load i8*, i8** %22
%24 = call i64 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %20
%29 = load i8**, i8*** %4
%30 = getelementptr inbounds i8*, i8** %29, i64 4
%31 = load i8*, i8** %30
%32 = call i64 @sscanf(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %28
%37 = load i8**, i8*** %4
%38 = getelementptr inbounds i8*, i8** %37, i64 5
%39 = load i8*, i8** %38
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %40, i32** %11
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 @error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %44
44: ; preds = %42, %36
%45 = call i8* @malloc(i32 1000000)
store i8* %45, i8** %5
%46 = load i8*, i8** %5
%47 = call i32 @memset(i8* %46, i32 0, i32 54)
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 0
store i8 66, i8* %49
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i64 1
store i8 77, i8* %51
%52 = load i8*, i8** %5
%53 = getelementptr inbounds i8, i8* %52, i64 10
store i8 54, i8* %53
%54 = load i8*, i8** %5
%55 = getelementptr inbounds i8, i8* %54, i64 11
store i8 4, i8* %55
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i64 14
store i8 40, i8* %57
%58 = load i32, i32* %8
%59 = and i32 %58, 255
%60 = trunc i32 %59 to i8
%61 = load i8*, i8** %5
%62 = getelementptr inbounds i8, i8* %61, i64 18
store i8 %60, i8* %62
%63 = load i32, i32* %8
%64 = ashr i32 %63, 8
%65 = trunc i32 %64 to i8
%66 = load i8*, i8** %5
%67 = getelementptr inbounds i8, i8* %66, i64 19
store i8 %65, i8* %67
%68 = load i32, i32* %9
%69 = and i32 %68, 255
%70 = trunc i32 %69 to i8
%71 = load i8*, i8** %5
%72 = getelementptr inbounds i8, i8* %71, i64 22
store i8 %70, i8* %72
%73 = load i32, i32* %9
%74 = ashr i32 %73, 8
%75 = trunc i32 %74 to i8
%76 = load i8*, i8** %5
%77 = getelementptr inbounds i8, i8* %76, i64 23
store i8 %75, i8* %77
%78 = load i8*, i8** %5
%79 = getelementptr inbounds i8, i8* %78, i64 26
store i8 1, i8* %79
%80 = load i8*, i8** %5
%81 = getelementptr inbounds i8, i8* %80, i64 28
store i8 8, i8* %81
%82 = load i8*, i8** %5
%83 = getelementptr inbounds i8, i8* %82, i64 47
store i8 0, i8* %83
%84 = load i8*, i8** %5
%85 = getelementptr inbounds i8, i8* %84, i64 51
store i8 0, i8* %85
%86 = load i8*, i8** %5
%87 = load i32*, i32** %11
%88 = call i32 @fwrite(i8* %86, i32 54, i32 1, i32* %87)
%89 = load i8**, i8*** %4
%90 = getelementptr inbounds i8*, i8** %89, i64 2
%91 = load i8*, i8** %90
%92 = call i32* @fopen(i8* %91, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %92, i32** %12
%93 = icmp eq i32* %92, null
br i1 %93, label %94, label %96
94: ; preds = %44
%95 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
br label %96
96: ; preds = %94, %44
%97 = load i8*, i8** %5
%98 = load i32*, i32** %12
%99 = call i32 @fread(i8* %97, i32 768, i32 1, i32* %98)
%100 = load i32*, i32** %12
%101 = call i32 @fclose(i32* %100)
store i32 0, i32* %6
br label %102
102: ; preds = %129, %96
%103 = load i32, i32* %6
%104 = icmp slt i32 %103, 256
br i1 %104, label %105, label %132
105: ; preds = %102
store i32 2, i32* %7
br label %106
106: ; preds = %123, %105
%107 = load i32, i32* %7
%108 = icmp sge i32 %107, 0
br i1 %108, label %109, label %126
109: ; preds = %106
%110 = load i8*, i8** %5
%111 = load i32, i32* %6
%112 = mul nsw i32 %111, 3
%113 = load i32, i32* %7
%114 = add nsw i32 %112, %113
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i8, i8* %110, i64 %115
%117 = load i8, i8* %116
%118 = zext i8 %117 to i32
%119 = shl i32 %118, 2
%120 = trunc i32 %119 to i8
%121 = load i32*, i32** %11
%122 = call i32 @fputc(i8 zeroext %120, i32* %121)
br label %123
123: ; preds = %109
%124 = load i32, i32* %7
%125 = add nsw i32 %124, -1
store i32 %125, i32* %7
br label %106
126: ; preds = %106
%127 = load i32*, i32** %11
%128 = call i32 @fputc(i8 zeroext 0, i32* %127)
br label %129
129: ; preds = %126
%130 = load i32, i32* %6
%131 = add nsw i32 %130, 1
store i32 %131, i32* %6
br label %102
132: ; preds = %102
%133 = load i8**, i8*** %4
%134 = getelementptr inbounds i8*, i8** %133, i64 1
%135 = load i8*, i8** %134
%136 = call i32* @fopen(i8* %135, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %136, i32** %12
%137 = icmp eq i32* %136, null
br i1 %137, label %138, label %140
138: ; preds = %132
%139 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
br label %140
140: ; preds = %138, %132
%141 = load i8*, i8** %5
%142 = load i32*, i32** %12
%143 = call i32 @fread(i8* %141, i32 1000000, i32 1, i32* %142)
%144 = load i32*, i32** %12
%145 = call i32 @fclose(i32* %144)
%146 = load i32, i32* %8
%147 = and i32 %146, 3
%148 = sub nsw i32 4, %147
%149 = and i32 %148, 3
store i32 %149, i32* %10
%150 = load i32, i32* %9
%151 = sub nsw i32 %150, 1
store i32 %151, i32* %6
br label %152
152: ; preds = %187, %140
%153 = load i32, i32* %6
%154 = icmp sge i32 %153, 0
br i1 %154, label %155, label %190
155: ; preds = %152
store i32 0, i32* %7
br label %156
156: ; preds = %172, %155
%157 = load i32, i32* %7
%158 = load i32, i32* %8
%159 = icmp slt i32 %157, %158
br i1 %159, label %160, label %175
160: ; preds = %156
%161 = load i8*, i8** %5
%162 = load i32, i32* %6
%163 = load i32, i32* %8
%164 = mul nsw i32 %162, %163
%165 = load i32, i32* %7
%166 = add nsw i32 %164, %165
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds i8, i8* %161, i64 %167
%169 = load i8, i8* %168
%170 = load i32*, i32** %11
%171 = call i32 @fputc(i8 zeroext %169, i32* %170)
br label %172
172: ; preds = %160
%173 = load i32, i32* %7
%174 = add nsw i32 %173, 1
store i32 %174, i32* %7
br label %156
175: ; preds = %156
%176 = load i32, i32* %10
store i32 %176, i32* %7
br label %177
177: ; preds = %183, %175
%178 = load i32, i32* %7
%179 = icmp sgt i32 %178, 0
br i1 %179, label %180, label %186
180: ; preds = %177
%181 = load i32*, i32** %11
%182 = call i32 @fputc(i8 zeroext 0, i32* %181)
br label %183
183: ; preds = %180
%184 = load i32, i32* %7
%185 = add nsw i32 %184, -1
store i32 %185, i32* %7
br label %177
186: ; preds = %177
br label %187
187: ; preds = %186
%188 = load i32, i32* %6
%189 = add nsw i32 %188, -1
store i32 %189, i32* %6
br label %152
190: ; preds = %152
%191 = load i32*, i32** %11
%192 = call i32 @fclose(i32* %191)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [65 x i8] c"use: PIC2BMP <picture> <palette> <size_x> <size_y> <outpicture>\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Invalid x resolution.\0A\00"
@.str.3 = [23 x i8] c"Invalid y resolution.\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [29 x i8] c"Unable to open output file.\0A\00"
@.str.6 = [3 x i8] c"rb\00"
@.str.7 = [30 x i8] c"Palette file does not exist.\0A\00"
@.str.8 = [30 x i8] c"Picture file does not exist.\0A\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @stdout
%8 = load i32, i32* @_IONBF
%9 = tail call i32 @setvbuf(i32 %7, i32* null, i32 %8, i32 0)
%10 = icmp slt i32 %0, 6
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @error(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = call i64 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = getelementptr inbounds i8*, i8** %1, i64 4
%22 = load i8*, i8** %21
%23 = call i64 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %20
%28 = getelementptr inbounds i8*, i8** %1, i64 5
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = call dereferenceable_or_null(1000000) i8* @malloc(i32 1000000)
%36 = call i32 @memset(i8* %35, i32 0, i32 54)
store i8 66, i8* %35
%37 = getelementptr inbounds i8, i8* %35, i64 1
store i8 77, i8* %37
%38 = getelementptr inbounds i8, i8* %35, i64 10
store i8 54, i8* %38
%39 = getelementptr inbounds i8, i8* %35, i64 11
store i8 4, i8* %39
%40 = getelementptr inbounds i8, i8* %35, i64 14
store i8 40, i8* %40
%41 = load i32, i32* %3
%42 = trunc i32 %41 to i8
%43 = getelementptr inbounds i8, i8* %35, i64 18
store i8 %42, i8* %43
%44 = lshr i32 %41, 8
%45 = trunc i32 %44 to i8
%46 = getelementptr inbounds i8, i8* %35, i64 19
store i8 %45, i8* %46
%47 = load i32, i32* %4
%48 = trunc i32 %47 to i8
%49 = getelementptr inbounds i8, i8* %35, i64 22
store i8 %48, i8* %49
%50 = lshr i32 %47, 8
%51 = trunc i32 %50 to i8
%52 = getelementptr inbounds i8, i8* %35, i64 23
store i8 %51, i8* %52
%53 = getelementptr inbounds i8, i8* %35, i64 26
store i8 1, i8* %53
%54 = getelementptr inbounds i8, i8* %35, i64 28
store i8 8, i8* %54
%55 = getelementptr inbounds i8, i8* %35, i64 47
store i8 0, i8* %55
%56 = getelementptr inbounds i8, i8* %35, i64 51
store i8 0, i8* %56
%57 = call i32 @fwrite(i8* %35, i32 54, i32 1, i32* %30)
%58 = getelementptr inbounds i8*, i8** %1, i64 2
%59 = load i8*, i8** %58
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%61 = icmp eq i32* %60, null
br i1 %61, label %62, label %64
62: ; preds = %34
%63 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
br label %64
64: ; preds = %62, %34
%65 = call i32 @fread(i8* %35, i32 768, i32 1, i32* %60)
%66 = call i32 @fclose(i32* %60)
br label %67
67: ; preds = %64, %67
%68 = phi i64 [ 0, %64 ], [ %85, %67 ]
%69 = mul nuw nsw i64 %68, 3
%70 = add nuw nsw i64 %69, 2
%71 = getelementptr inbounds i8, i8* %35, i64 %70
%72 = load i8, i8* %71
%73 = shl i8 %72, 2
%74 = call i32 @fputc(i8 zeroext %73, i32* %30)
%75 = add nuw nsw i64 %69, 1
%76 = getelementptr inbounds i8, i8* %35, i64 %75
%77 = load i8, i8* %76
%78 = shl i8 %77, 2
%79 = call i32 @fputc(i8 zeroext %78, i32* %30)
%80 = getelementptr inbounds i8, i8* %35, i64 %69
%81 = load i8, i8* %80
%82 = shl i8 %81, 2
%83 = call i32 @fputc(i8 zeroext %82, i32* %30)
%84 = call i32 @fputc(i8 zeroext 0, i32* %30)
%85 = add nuw nsw i64 %68, 1
%86 = icmp eq i64 %85, 256
br i1 %86, label %87, label %67
87: ; preds = %67
%88 = getelementptr inbounds i8*, i8** %1, i64 1
%89 = load i8*, i8** %88
%90 = call i32* @fopen(i8* %89, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%91 = icmp eq i32* %90, null
br i1 %91, label %92, label %94
92: ; preds = %87
%93 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
br label %94
94: ; preds = %92, %87
%95 = call i32 @fread(i8* %35, i32 1000000, i32 1, i32* %90)
%96 = call i32 @fclose(i32* %90)
%97 = load i32, i32* %3
%98 = sub i32 0, %97
%99 = and i32 %98, 3
%100 = load i32, i32* %4
%101 = icmp sgt i32 %100, 0
br i1 %101, label %102, label %131
102: ; preds = %94
%103 = icmp eq i32 %99, 0
br label %108
104: ; preds = %126, %113
%105 = icmp sgt i32 %110, 1
br i1 %105, label %106, label %131
106: ; preds = %104
%107 = load i32, i32* %3
br label %108
108: ; preds = %106, %102
%109 = phi i32 [ %97, %102 ], [ %107, %106 ]
%110 = phi i32 [ %100, %102 ], [ %111, %106 ]
%111 = add nsw i32 %110, -1
%112 = icmp sgt i32 %109, 0
br i1 %112, label %114, label %113
113: ; preds = %114, %108
br i1 %103, label %104, label %126
114: ; preds = %108, %114
%115 = phi i32 [ %124, %114 ], [ %109, %108 ]
%116 = phi i32 [ %123, %114 ], [ 0, %108 ]
%117 = mul nsw i32 %115, %111
%118 = add nsw i32 %117, %116
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i8, i8* %35, i64 %119
%121 = load i8, i8* %120
%122 = call i32 @fputc(i8 zeroext %121, i32* %30)
%123 = add nuw nsw i32 %116, 1
%124 = load i32, i32* %3
%125 = icmp slt i32 %123, %124
br i1 %125, label %114, label %113
126: ; preds = %113, %126
%127 = phi i32 [ %129, %126 ], [ %99, %113 ]
%128 = call i32 @fputc(i8 zeroext 0, i32* %30)
%129 = add nsw i32 %127, -1
%130 = icmp sgt i32 %127, 1
br i1 %130, label %126, label %104
131: ; preds = %104, %94
%132 = call i32 @fclose(i32* %30)
ret void
}