#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 scalar_t__ off_t;
typedef int /*<<< orphan*/ color;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ lseek(int, scalar_t__, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int fd;
  unsigned char color;
  char colors[4] = {'.', 'r', 'g', 'b'};
  off_t pos;
  int w;
  int h;
  int y;
  int x;
  int i;
  if (argc < 5) {
    fprintf(stderr,
            "Usage: %s\n"
            "    <bin file> <offset> <w> <h>\n",
            argv[0]);
    return 1;
  }
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "Can not open file %s\n", argv[1]);
    return 1;
  }
  pos = strtol(argv[2], NULL, 0);
  fprintf(stderr, "%s @ %lx\n", argv[1], (unsigned long)pos);
  if (lseek(fd, pos, SEEK_SET) < 0) {
    fprintf(stderr, "Can not seek file %s\n", argv[1]);
    return 1;
  }
  w = atoi(argv[3]);
  h = atoi(argv[4]);
  fprintf(stderr, "%d x %d\n", w, h);
  w = (w & 0xfc) + ((w & 3) ? 4 : 0);
  fprintf(stderr, "%d x %d\n", w, h);
  fprintf(stdout,
          "/* XPM */\n"
          "static char *xpm_%lx[] = {\n"
          "/* width height num_colors chars_per_pixel */\n"
          "\" %d %d 4 1\",\n"
          "/* colors */\n"
          "\". c #000000\",\n"
          "\"r c #ff0000\",\n"
          "\"g c #00ff00\",\n"
          "\"b c #0000ff\",\n"
          "/* pixels */\n",
          (unsigned long)pos, w, h);
  for (y = 0; y < h; y++) {
    fprintf(stdout, "\"");
    for (x = 0; x < w / 4; x++) {
      if (read(fd, &color, sizeof(color)) != sizeof(color)) {
        fprintf(stderr, "Can not read file %s\n", argv[1]);
        return 1;
      }
      for (i = 0; i < 4; i++) {
        fprintf(stdout, "%c", colors[color & 3]);
        color >>= 2;
      }
    }
    fprintf(stdout, "\",\n");
  }
  fprintf(stdout, "};\n");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe74(%rip),%eax
mov    %eax,-0x19(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    11c3 <main+0x53>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1474 <main+0x304>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1211 <main+0xa1>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1474 <main+0x304>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0x0,%rax
jge    1295 <main+0x125>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1474 <main+0x304>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%eax
and    $0xfc,%eax
mov    -0x2c(%rbp),%esi
and    $0x3,%esi
xor    %ecx,%ecx
mov    $0x4,%edx
cmp    $0x0,%esi
cmovne %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
lea    0xd44(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    144e <main+0x2de>
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
cmp    %ecx,%eax
jge    1429 <main+0x2b9>
mov    -0x14(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cltq
cmp    $0x1,%rax
je     13c8 <main+0x258>
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1474 <main+0x304>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x4,-0x3c(%rbp)
jge    1416 <main+0x2a6>
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
movzbl -0x15(%rbp),%eax
and    $0x3,%eax
cltq
movsbl -0x19(%rbp,%rax,1),%edx
lea    0xd47(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movzbl -0x15(%rbp),%eax
sar    $0x2,%eax
mov    %al,-0x15(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    13cf <main+0x25f>
jmp    141b <main+0x2ab>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1362 <main+0x1f2>
mov    0x2b98(%rip),%rax
mov    (%rax),%edi
lea    0xd08(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1338 <main+0x1c8>
mov    0x2b73(%rip),%rax
mov    (%rax),%edi
lea    0xce7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbp
cmp    $0x4,%edi
jg     119f <main+0x2f>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe6a(%rip),%rsi
jmp    13f7 <main+0x287>
mov    0x8(%rbp),%rdi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     13b8 <main+0x248>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %rax,%r12
mov    0x2e06(%rip),%r15
mov    (%r15),%edi
mov    0x8(%rbp),%rdx
lea    0xe65(%rip),%rsi
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r12,%rsi
call   1030 <lseek@plt>
test   %rax,%rax
js     13ce <main+0x25e>
mov    0x18(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
mov    %rbp,0x20(%rsp)
mov    0x20(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%r13d
mov    (%r15),%edi
mov    %ebx,0xc(%rsp)
lea    0xe34(%rip),%rbx
mov    %rbx,%rsi
mov    %r14d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%eax
and    $0xfc,%eax
xor    %ecx,%ecx
test   $0x3,%r14b
setne  %cl
lea    (%rax,%rcx,4),%eax
mov    (%r15),%edi
mov    %eax,%r15d
mov    %rbx,%rsi
mov    0xc(%rsp),%ebp
mov    %eax,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d54(%rip),%rbx
mov    (%rbx),%edi
lea    0xdf1(%rip),%rsi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %r13d,%r8d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r13d,0x18(%rsp)
test   %r13d,%r13d
jle    1412 <main+0x2a2>
mov    %r15d,%ecx
shr    $0x2,%ecx
cmp    $0x2,%ecx
mov    $0x1,%eax
cmovb  %eax,%ecx
mov    %ecx,0x10(%rsp)
lea    0xd49(%rip),%r14
lea    0xe80(%rip),%r12
xor    %eax,%eax
mov    %r15d,0x14(%rsp)
jmp    12f6 <main+0x186>
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%edi
lea    0xe68(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x1c(%rsp),%eax
add    $0x1,%eax
cmp    0x18(%rsp),%eax
mov    0x14(%rsp),%r15d
je     1412 <main+0x2a2>
mov    %eax,0x1c(%rsp)
mov    (%rbx),%edi
lea    0xe23(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %r15d,%r15d
je     12d0 <main+0x160>
mov    0x10(%rsp),%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
lea    0xb(%rsp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    13de <main+0x26e>
movzbl 0xb(%rsp),%ebp
movzbl %bpl,%r13d
mov    (%rbx),%edi
mov    %ebp,%eax
and    $0x3,%eax
movsbl (%rax,%r14,1),%edx
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%eax
shr    $0x2,%eax
and    $0x3,%eax
mov    (%rbx),%edi
movsbl (%rax,%r14,1),%edx
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
shr    $0x4,%ebp
and    $0x3,%ebp
mov    (%rbx),%edi
movsbl 0x0(%rbp,%r14,1),%edx
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
shr    $0x6,%r13
mov    (%rbx),%edi
movsbl 0x0(%r13,%r14,1),%edx
mov    0xc(%rsp),%ebp
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
movb   $0x0,0xb(%rsp)
add    $0xffffffff,%r15d
jne    1320 <main+0x1b0>
jmp    12d0 <main+0x160>
mov    0x2c19(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xc63(%rip),%rsi
jmp    13f7 <main+0x287>
mov    (%r15),%edi
mov    0x8(%rbp),%rdx
lea    0xc73(%rip),%rsi
jmp    13f7 <main+0x287>
mov    0x2bf3(%rip),%rax
mov    (%rax),%edi
mov    0x20(%rsp),%rax
mov    0x8(%rax),%rdx
lea    0xd31(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%edi
lea    0xd2a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
jmp    1403 <main+0x293>

LLVM IR (-O0):
@__const.main.colors = [4 x i8] c".rgb"
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s\0A <bin file> <offset> <w> <h>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"Can not open file %s\0A\00"
@.str.2 = [10 x i8] c"%s @ %lx\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [22 x i8] c"Can not seek file %s\0A\00"
@.str.4 = [9 x i8] c"%d x %d\0A\00"
@stdout = global i32 0
@.str.5 = [184 x i8] c"/* XPM */\0Astatic char *xpm_%lx[] = {\0A/* width height num_colors chars_per_pixel */\0A\22 %d %d 4 1\22,\0A/* colors */\0A\22. c\22,\0A\22r c #ff0000\22,\0A\22g cff00\22,\0A\22b cff\22,\0A/* pixels */\0A\00"
@.str.6 = [2 x i8] c"\22\00"
@.str.7 = [22 x i8] c"Can not read file %s\0A\00"
@.str.8 = [3 x i8] c"%c\00"
@.str.9 = [4 x i8] c"\22,\0A\00"
@.str.10 = [4 x i8] c"};\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
%8 = alloca [4 x i8]
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = bitcast [4 x i8]* %8 to i8*
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 5
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 1, i32* %3
br label %149
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_RDONLY
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %24
%33 = load i32, i32* @stderr
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %36)
store i32 1, i32* %3
br label %149
38: ; preds = %24
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i64 @strtol(i8* %41, i32* null, i32 0)
store i64 %42, i64* %9
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = load i64, i64* %9
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %46, i64 %47)
%49 = load i32, i32* %6
%50 = load i64, i64* %9
%51 = load i32, i32* @SEEK_SET
%52 = call i64 @lseek(i32 %49, i64 %50, i32 %51)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %38
%55 = load i32, i32* @stderr
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %58)
store i32 1, i32* %3
br label %149
60: ; preds = %38
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 3
%63 = load i8*, i8** %62
%64 = call i32 @atoi(i8* %63)
store i32 %64, i32* %10
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 4
%67 = load i8*, i8** %66
%68 = call i32 @atoi(i8* %67)
store i32 %68, i32* %11
%69 = load i32, i32* @stderr
%70 = load i32, i32* %10
%71 = load i32, i32* %11
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %70, i32 %71)
%73 = load i32, i32* %10
%74 = and i32 %73, 252
%75 = load i32, i32* %10
%76 = and i32 %75, 3
%77 = icmp ne i32 %76, 0
%78 = zext i1 %77 to i64
%79 = select i1 %77, i32 4, i32 0
%80 = add nsw i32 %74, %79
store i32 %80, i32* %10
%81 = load i32, i32* @stderr
%82 = load i32, i32* %10
%83 = load i32, i32* %11
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %82, i32 %83)
%85 = load i32, i32* @stdout
%86 = load i64, i64* %9
%87 = load i32, i32* %10
%88 = load i32, i32* %11
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([184 x i8], [184 x i8]* @.str.5, i64 0, i64 0), i64 %86, i32 %87, i32 %88)
store i32 0, i32* %12
br label %90
90: ; preds = %141, %60
%91 = load i32, i32* %12
%92 = load i32, i32* %11
%93 = icmp slt i32 %91, %92
br i1 %93, label %94, label %144
94: ; preds = %90
%95 = load i32, i32* @stdout
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %13
br label %97
97: ; preds = %135, %94
%98 = load i32, i32* %13
%99 = load i32, i32* %10
%100 = sdiv i32 %99, 4
%101 = icmp slt i32 %98, %100
br i1 %101, label %102, label %138
102: ; preds = %97
%103 = load i32, i32* %6
%104 = call i32 @read(i32 %103, i8* %7, i32 1)
%105 = sext i32 %104 to i64
%106 = icmp ne i64 %105, 1
br i1 %106, label %107, label %113
107: ; preds = %102
%108 = load i32, i32* @stderr
%109 = load i8**, i8*** %5
%110 = getelementptr inbounds i8*, i8** %109, i64 1
%111 = load i8*, i8** %110
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %111)
store i32 1, i32* %3
br label %149
113: ; preds = %102
store i32 0, i32* %14
br label %114
114: ; preds = %131, %113
%115 = load i32, i32* %14
%116 = icmp slt i32 %115, 4
br i1 %116, label %117, label %134
117: ; preds = %114
%118 = load i32, i32* @stdout
%119 = load i8, i8* %7
%120 = zext i8 %119 to i32
%121 = and i32 %120, 3
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 %122
%124 = load i8, i8* %123
%125 = sext i8 %124 to i32
%126 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %125)
%127 = load i8, i8* %7
%128 = zext i8 %127 to i32
%129 = ashr i32 %128, 2
%130 = trunc i32 %129 to i8
store i8 %130, i8* %7
br label %131
131: ; preds = %117
%132 = load i32, i32* %14
%133 = add nsw i32 %132, 1
store i32 %133, i32* %14
br label %114
134: ; preds = %114
br label %135
135: ; preds = %134
%136 = load i32, i32* %13
%137 = add nsw i32 %136, 1
store i32 %137, i32* %13
br label %97
138: ; preds = %97
%139 = load i32, i32* @stdout
%140 = call i32 (i32, i8*, ...) @fprintf(i32 %139, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
br label %141
141: ; preds = %138
%142 = load i32, i32* %12
%143 = add nsw i32 %142, 1
store i32 %143, i32* %12
br label %90
144: ; preds = %90
%145 = load i32, i32* @stdout
%146 = call i32 (i32, i8*, ...) @fprintf(i32 %145, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%147 = load i32, i32* %6
%148 = call i32 @close(i32 %147)
store i32 0, i32* %3
br label %149
149: ; preds = %144, %107, %54, %32, %18
%150 = load i32, i32* %3
ret i32 %150
}

LLVM IR (-O2):
@__const.main.colors = [4 x i8] c".rgb"
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s\0A <bin file> <offset> <w> <h>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"Can not open file %s\0A\00"
@.str.2 = [10 x i8] c"%s @ %lx\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [22 x i8] c"Can not seek file %s\0A\00"
@.str.4 = [9 x i8] c"%d x %d\0A\00"
@stdout = global i32 0
@.str.5 = [184 x i8] c"/* XPM */\0Astatic char *xpm_%lx[] = {\0A/* width height num_colors chars_per_pixel */\0A\22 %d %d 4 1\22,\0A/* colors */\0A\22. c\22,\0A\22r c #ff0000\22,\0A\22g cff00\22,\0A\22b cff\22,\0A/* pixels */\0A\00"
@.str.6 = [2 x i8] c"\22\00"
@.str.7 = [22 x i8] c"Can not read file %s\0A\00"
@.str.8 = [3 x i8] c"%c\00"
@.str.9 = [4 x i8] c"\22,\0A\00"
@.str.10 = [4 x i8] c"};\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp slt i32 %0, 5
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %111
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %10
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %111
19: ; preds = %9
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i64 @strtol(i8* nocapture %21, i32* null, i32 0)
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %10
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %24, i64 %22)
%26 = load i32, i32* @SEEK_SET
%27 = tail call i64 @lseek(i32 %13, i64 %22, i32 %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %19
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %10
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %31)
br label %111
33: ; preds = %19
%34 = getelementptr inbounds i8*, i8** %1, i64 3
%35 = load i8*, i8** %34
%36 = tail call i32 @atoi(i8* %35)
%37 = getelementptr inbounds i8*, i8** %1, i64 4
%38 = load i8*, i8** %37
%39 = tail call i32 @atoi(i8* %38)
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %36, i32 %39)
%42 = and i32 %36, 252
%43 = and i32 %36, 3
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i32 0, i32 4
%46 = add nuw nsw i32 %45, %42
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %39)
%49 = load i32, i32* @stdout
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([184 x i8], [184 x i8]* @.str.5, i64 0, i64 0), i64 %22, i32 %46, i32 %39)
%51 = icmp sgt i32 %39, 0
br i1 %51, label %52, label %107
52: ; preds = %33
%53 = lshr exact i32 %46, 2
%54 = icmp eq i32 %46, 0
%55 = call i32 @llvm.umax.i32(i32 %53, i32 1)
br label %56
56: ; preds = %52, %102
%57 = phi i32 [ 0, %52 ], [ %105, %102 ]
%58 = load i32, i32* @stdout
%59 = tail call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br i1 %54, label %102, label %60
60: ; preds = %56, %64
%61 = phi i32 [ %96, %64 ], [ 0, %56 ]
%62 = call i32 @read(i32 %13, i8* %3, i32 1)
%63 = icmp eq i32 %62, 1
br i1 %63, label %64, label %98
64: ; preds = %60
%65 = load i8, i8* %3
%66 = load i32, i32* @stdout
%67 = and i8 %65, 3
%68 = zext i8 %67 to i64
%69 = getelementptr inbounds [4 x i8], [4 x i8]* @__const.main.colors, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = tail call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %71)
%73 = lshr i8 %65, 2
%74 = load i32, i32* @stdout
%75 = and i8 %73, 3
%76 = zext i8 %75 to i64
%77 = getelementptr inbounds [4 x i8], [4 x i8]* @__const.main.colors, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = tail call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %79)
%81 = lshr i8 %65, 4
%82 = load i32, i32* @stdout
%83 = and i8 %81, 3
%84 = zext i8 %83 to i64
%85 = getelementptr inbounds [4 x i8], [4 x i8]* @__const.main.colors, i64 0, i64 %84
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = tail call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %87)
%89 = lshr i8 %65, 6
%90 = load i32, i32* @stdout
%91 = zext i8 %89 to i64
%92 = getelementptr inbounds [4 x i8], [4 x i8]* @__const.main.colors, i64 0, i64 %91
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = tail call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %94)
store i8 0, i8* %3
%96 = add nuw nsw i32 %61, 1
%97 = icmp eq i32 %96, %55
br i1 %97, label %102, label %60
98: ; preds = %60
%99 = load i32, i32* @stderr
%100 = load i8*, i8** %10
%101 = tail call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %100)
br label %111
102: ; preds = %64, %56
%103 = load i32, i32* @stdout
%104 = tail call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%105 = add nuw nsw i32 %57, 1
%106 = icmp eq i32 %105, %39
br i1 %106, label %107, label %56
107: ; preds = %102, %33
%108 = load i32, i32* @stdout
%109 = tail call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%110 = tail call i32 @close(i32 %13)
br label %111
111: ; preds = %107, %98, %29, %15, %5
%112 = phi i32 [ 1, %5 ], [ 1, %15 ], [ 1, %29 ], [ 1, %98 ], [ 0, %107 ]
ret i32 %112
}