#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 */

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int asprintf(char **, char *, int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned char, ...);
int /*<<< orphan*/ free(char *);
int jpeg_decode(unsigned char *, unsigned char *, unsigned int, unsigned int,
                unsigned int, unsigned int, unsigned int);
unsigned int jpeg_get_size(unsigned char *);
unsigned char *malloc(int);
int open(char *, int, ...);
int read(int, unsigned char *, int);
unsigned char *realloc(unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ write(int, ...);
int main(int argc, char **argv) {
  int fd, i, width, height;
  unsigned char *jpg = malloc(1 << 20);
  unsigned char *img, *p;
  unsigned char pixel[3];
  unsigned x, z;
  unsigned x0, x1, y0, y1;
  unsigned bits = 0;
  if (argc < 4)
    return 1;
  if (!strcmp(argv[1], "--8")) {
    bits = 8;
  }
  if (!strcmp(argv[1], "--16")) {
    bits = 16;
  }
  if (!strcmp(argv[1], "--24")) {
    bits = 24;
  }
  if (!strcmp(argv[1], "--32")) {
    bits = 32;
  }
  if (!bits)
    return 10;
  fd = open(argv[2], O_RDONLY);
  if (fd == -1)
    return 2;
  i = read(fd, jpg, 1 << 20);
  if (i < 0)
    return 3;
  close(fd);
  jpg = realloc(jpg, i);
  x = jpeg_get_size(jpg);
  width = x & 0xffff;
  height = x >> 16;
  fprintf(stderr, "size = %d bytes, width = %d, height = %d\n", i, width,
          height);
  img = malloc(width * height * 4);
  x0 = 0;
  x1 = width;
  y0 = 0;
  y1 = height;
  i = jpeg_decode(jpg, img, x0, x1, y0, y1, bits);
  width = x1 - x0;
  height = y1 - y0;
  fprintf(stderr, "decode = %d\n", i);
  fprintf(stderr, "%02x %02x %02x %02x %02x %02x %02x %02x\n", img[0], img[1],
          img[2], img[3], img[4], img[5], img[6], img[7]);
  if (argc >= 3) {
    fd = open(argv[3], O_WRONLY | O_CREAT | O_TRUNC, 0644);
    if (fd >= 0) {
      char *s = NULL;
      i = asprintf(&s, "P6\n%d %d\n255\n", width, height);
      if (i > 0)
        write(fd, s, i);
      free(s);
      switch (bits) {
      case 8:
        for (i = 0, p = img; i < width * height; i++) {
          x = *p++;
          z = x >> (4 + 2);
          pixel[0] = z * 0x55;
          z = (x >> 3) & 0x07;
          pixel[1] = z * 0x24 + (z >> 1);
          z = x & 0x7;
          pixel[2] = z * 0x24 + (z >> 1);
          write(fd, &pixel, 3);
        }
        break;
      case 16:
        for (i = 0, p = img; i < width * height; i++) {
          x = p[0] + (p[1] << 8);
          p += 2;
          pixel[0] = ((x >> 11) & 0x1f) << 3;
          pixel[0] += pixel[0] >> 5;
          pixel[1] = ((x >> 5) & 0x3f) << 2;
          pixel[1] += pixel[1] >> 6;
          pixel[2] = (x & 0x1f) << 3;
          pixel[2] += pixel[2] >> 5;
          write(fd, &pixel, 3);
        }
        break;
      case 24:
        for (i = 0, p = img; i < width * height; i++) {
          pixel[2] = *p++;
          pixel[1] = *p++;
          pixel[0] = *p++;
          write(fd, &pixel, 3);
        }
        break;
      case 32:
        for (i = 0, p = img; i < width * height; i++) {
          pixel[2] = *p++;
          pixel[1] = *p++;
          pixel[0] = *p++;
          p++;
          write(fd, &pixel, 3);
        }
        break;
      }
      close(fd);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x88,%rsp
movl   $0x0,-0xc(%rbp)
mov    %edi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x100000,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x60(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    1205 <main+0x45>
movl   $0x1,-0xc(%rbp)
jmp    178c <main+0x5cc>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe50(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1229 <main+0x69>
movl   $0x8,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe30(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    124d <main+0x8d>
movl   $0x10,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe11(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1271 <main+0xb1>
movl   $0x18,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf2(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1295 <main+0xd5>
movl   $0x20,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
jne    12ab <main+0xeb>
movl   $0xa,-0xc(%rbp)
jmp    178c <main+0x5cc>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12dc <main+0x11c>
movl   $0x2,-0xc(%rbp)
jmp    178c <main+0x5cc>
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    $0x100000,%edx
call   1070 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1306 <main+0x146>
movl   $0x3,-0xc(%rbp)
jmp    178c <main+0x5cc>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   10b0 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   10e0 <jpeg_get_size@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x48(%rbp),%eax
shr    $0x10,%eax
mov    %eax,-0x28(%rbp)
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
lea    0xd1f(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x24(%rbp),%edi
imul   -0x28(%rbp),%edi
shl    $0x2,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x50(%rbp),%edx
mov    -0x54(%rbp),%ecx
mov    -0x58(%rbp),%r8d
mov    -0x5c(%rbp),%r9d
mov    -0x60(%rbp),%eax
mov    %eax,(%rsp)
call   1050 <jpeg_decode@plt>
mov    %eax,-0x20(%rbp)
mov    -0x54(%rbp),%eax
sub    -0x50(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x5c(%rbp),%eax
sub    -0x58(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2bfc(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%eax
lea    0xcc9(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2bdf(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rax
mov    (%rax),%dl
mov    -0x38(%rbp),%rax
movzbl 0x1(%rax),%ecx
mov    -0x38(%rbp),%rax
movzbl 0x2(%rax),%r8d
mov    -0x38(%rbp),%rax
movzbl 0x3(%rax),%r9d
mov    -0x38(%rbp),%rax
movzbl 0x4(%rax),%ebx
mov    -0x38(%rbp),%rax
movzbl 0x5(%rax),%r11d
mov    -0x38(%rbp),%rax
movzbl 0x6(%rax),%r10d
mov    -0x38(%rbp),%rax
movzbl 0x7(%rax),%eax
lea    0xc7a(%rip),%rsi
movzbl %dl,%edx
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
mov    $0x0,%al
call   1090 <fprintf@plt>
cmpl   $0x3,-0x10(%rbp)
jl     1785 <main+0x5c5>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2b50(%rip),%rax
mov    (%rax),%esi
mov    0x2b87(%rip),%rax
or     (%rax),%esi
mov    0x2b76(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1780 <main+0x5c0>
movq   $0x0,-0x68(%rbp)
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    -0x68(%rbp),%rdi
lea    0xc29(%rip),%rsi
call   10c0 <asprintf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    14d1 <main+0x311>
mov    -0x1c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x60(%rbp),%eax
add    $0xfffffff8,%eax
mov    %eax,%ecx
mov    %rcx,-0x70(%rbp)
sub    $0x18,%eax
ja     1778 <main+0x5b8>
mov    -0x70(%rbp),%rax
lea    0xb06(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x20(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
imul   -0x28(%rbp),%ecx
cmp    %ecx,%eax
jge    159d <main+0x3dd>
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
movzbl (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
shr    $0x6,%eax
mov    %eax,-0x4c(%rbp)
imul   $0x55,-0x4c(%rbp),%eax
mov    %al,-0x43(%rbp)
mov    -0x48(%rbp),%eax
shr    $0x3,%eax
and    $0x7,%eax
mov    %eax,-0x4c(%rbp)
imul   $0x24,-0x4c(%rbp),%eax
mov    -0x4c(%rbp),%ecx
shr    $0x1,%ecx
add    %ecx,%eax
mov    %al,-0x42(%rbp)
mov    -0x48(%rbp),%eax
and    $0x7,%eax
mov    %eax,-0x4c(%rbp)
imul   $0x24,-0x4c(%rbp),%eax
mov    -0x4c(%rbp),%ecx
shr    $0x1,%ecx
add    %ecx,%eax
mov    %al,-0x41(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x43(%rbp),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1512 <main+0x352>
jmp    1778 <main+0x5b8>
movl   $0x0,-0x20(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
imul   -0x28(%rbp),%ecx
cmp    %ecx,%eax
jge    1661 <main+0x4a1>
mov    -0x40(%rbp),%rax
movzbl (%rax),%eax
mov    -0x40(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%eax
shr    $0xb,%eax
and    $0x1f,%eax
shl    $0x3,%eax
mov    %al,-0x43(%rbp)
movzbl -0x43(%rbp),%ecx
sar    $0x5,%ecx
movzbl -0x43(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x43(%rbp)
mov    -0x48(%rbp),%eax
shr    $0x5,%eax
and    $0x3f,%eax
shl    $0x2,%eax
mov    %al,-0x42(%rbp)
movzbl -0x42(%rbp),%ecx
sar    $0x6,%ecx
movzbl -0x42(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x42(%rbp)
mov    -0x48(%rbp),%eax
and    $0x1f,%eax
shl    $0x3,%eax
mov    %al,-0x41(%rbp)
movzbl -0x41(%rbp),%ecx
sar    $0x5,%ecx
movzbl -0x41(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x41(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x43(%rbp),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    15b1 <main+0x3f1>
jmp    1778 <main+0x5b8>
movl   $0x0,-0x20(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
imul   -0x28(%rbp),%ecx
cmp    %ecx,%eax
jge    16e4 <main+0x524>
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
mov    (%rax),%al
mov    %al,-0x41(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
mov    (%rax),%al
mov    %al,-0x42(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
mov    (%rax),%al
mov    %al,-0x43(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x43(%rbp),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1675 <main+0x4b5>
jmp    1778 <main+0x5b8>
movl   $0x0,-0x20(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
imul   -0x28(%rbp),%ecx
cmp    %ecx,%eax
jge    1773 <main+0x5b3>
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
mov    (%rax),%al
mov    %al,-0x41(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
mov    (%rax),%al
mov    %al,-0x42(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
mov    (%rax),%al
mov    %al,-0x43(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x43(%rbp),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    16f8 <main+0x538>
jmp    1778 <main+0x5b8>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
jmp    1785 <main+0x5c5>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x88,%rsp
pop    %rbx
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,%r14
mov    %edi,%ebx
mov    $0x100000,%edi
call   10a0 <malloc@plt>
mov    %rax,%r12
mov    $0x1,%eax
cmp    $0x4,%ebx
jl     15e2 <main+0x422>
mov    0x8(%r14),%r15
lea    0xe17(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
shl    $0x3,%ebx
lea    0xe02(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
mov    $0x10,%ebp
cmovne %ebx,%ebp
lea    0xdee(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
mov    $0x18,%ebx
cmovne %ebp,%ebx
lea    0xdda(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
mov    $0x20,%r13d
cmovne %ebx,%r13d
test   %r13d,%r13d
je     1493 <main+0x2d3>
mov    0x10(%r14),%rdi
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     149d <main+0x2dd>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r12,%rsi
mov    $0x100000,%edx
call   1070 <read@plt>
test   %eax,%eax
js     14a7 <main+0x2e7>
mov    %eax,%ebp
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r12,%rdi
mov    %ebp,%esi
call   10b0 <realloc@plt>
mov    %rax,0x10(%rsp)
mov    %rax,%rdi
call   10e0 <jpeg_get_size@plt>
mov    %eax,%r12d
movzwl %r12w,%ebx
shr    $0x10,%r12d
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
movzbl %bpl,%edx
lea    0xd4d(%rip),%rsi
mov    %ebx,%ecx
mov    %r12d,%r8d
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %ebx,%ebp
imul   %r12d,%ebp
lea    0x0(,%rbp,4),%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
sub    $0x8,%rsp
mov    0x18(%rsp),%rdi
mov    %rax,%rsi
xor    %edx,%edx
mov    %ebx,0x2c(%rsp)
mov    %ebx,%ecx
xor    %r8d,%r8d
mov    %r12d,%r9d
push   %r13
call   1050 <jpeg_decode@plt>
add    $0x10,%rsp
mov    0x2ca5(%rip),%rbx
mov    (%rbx),%edi
movzbl %al,%edx
lea    0xd1e(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
movzbl (%r15),%edx
movzbl 0x1(%r15),%ecx
movzbl 0x2(%r15),%r8d
movzbl 0x3(%r15),%r9d
movzbl 0x4(%r15),%ebx
movzbl 0x5(%r15),%eax
mov    %rax,0x10(%rsp)
movzbl 0x6(%r15),%r10d
movzbl 0x7(%r15),%r11d
lea    0xcef(%rip),%rsi
xor    %eax,%eax
push   %r11
push   %r10
push   0x20(%rsp)
push   %rbx
call   1090 <fprintf@plt>
add    $0x20,%rsp
mov    0x2c32(%rip),%rax
mov    0x2c6b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x18(%r14),%rdi
mov    0x2c54(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10d0 <open@plt>
test   %eax,%eax
js     15e0 <main+0x420>
mov    %eax,%r14d
movq   $0x0,0x18(%rsp)
lea    0xcbe(%rip),%rsi
lea    0x18(%rsp),%rdi
mov    0x24(%rsp),%edx
mov    %r12d,%ecx
call   10c0 <asprintf@plt>
test   %eax,%eax
jle    13eb <main+0x22b>
mov    0x18(%rsp),%rsi
mov    %r14d,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
add    $0xfffffff8,%r13d
shr    $0x3,%r13d
cmp    $0x3,%r13d
ja     15d8 <main+0x418>
lea    0xbf2(%rip),%rax
movslq (%rax,%r13,4),%rcx
add    %rax,%rcx
jmp    *%rcx
test   %ebp,%ebp
je     15d8 <main+0x418>
mov    %ebp,%r13d
lea    0xd(%rsp),%r12
xor    %ebp,%ebp
nopl   0x0(%rax)
movzbl (%r15,%rbp,1),%eax
mov    %eax,%ecx
shr    $0x6,%cl
movzbl %cl,%ecx
imul   $0x55,%ecx,%ecx
mov    %cl,0xd(%rsp)
mov    %eax,%ecx
shr    $0x3,%ecx
and    $0x7,%ecx
lea    0x0(,%rcx,4),%edx
lea    (%rdx,%rdx,8),%edx
shr    %ecx
or     %edx,%ecx
mov    %cl,0xe(%rsp)
and    $0x7,%eax
lea    0x0(,%rax,4),%ecx
lea    (%rcx,%rcx,8),%ecx
shr    %eax
or     %ecx,%eax
mov    %al,0xf(%rsp)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <write@plt>
add    $0x1,%rbp
cmp    %ebp,%r13d
jne    1430 <main+0x270>
jmp    15d8 <main+0x418>
mov    $0xa,%eax
jmp    15e2 <main+0x422>
mov    $0x2,%eax
jmp    15e2 <main+0x422>
mov    $0x3,%eax
jmp    15e2 <main+0x422>
test   %ebp,%ebp
je     15d8 <main+0x418>
mov    %ebp,%r13d
lea    0xd(%rsp),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r15,%rbp,2),%eax
movzbl 0x1(%r15,%rbp,2),%ecx
mov    %ecx,%edx
shl    $0x8,%edx
or     %eax,%edx
mov    %ecx,%ebx
and    $0xf8,%bl
shr    $0x5,%cl
or     %bl,%cl
mov    %cl,0xd(%rsp)
shr    $0x3,%edx
and    $0xfc,%edx
mov    %edx,%ecx
shr    $0x6,%ecx
or     %edx,%ecx
mov    %cl,0xe(%rsp)
lea    0x0(,%rax,8),%eax
mov    %eax,%ecx
shr    $0x5,%cl
or     %al,%cl
mov    %cl,0xf(%rsp)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <write@plt>
add    $0x1,%rbp
cmp    %ebp,%r13d
jne    14d0 <main+0x310>
jmp    15d8 <main+0x418>
test   %ebp,%ebp
je     15d8 <main+0x418>
lea    0xd(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r15),%eax
mov    %al,0xf(%rsp)
movzbl 0x1(%r15),%eax
mov    %al,0xe(%rsp)
movzbl 0x2(%r15),%eax
mov    %al,0xd(%rsp)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <write@plt>
add    $0x3,%r15
add    $0xffffffff,%ebp
jne    1550 <main+0x390>
jmp    15d8 <main+0x418>
test   %ebp,%ebp
je     15d8 <main+0x418>
mov    %ebp,%r13d
lea    0xd(%rsp),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15,%rbp,4),%eax
mov    %al,0xf(%rsp)
movzbl 0x1(%r15,%rbp,4),%eax
mov    %al,0xe(%rsp)
movzbl 0x2(%r15,%rbp,4),%eax
mov    %al,0xd(%rsp)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <write@plt>
add    $0x1,%rbp
cmp    %ebp,%r13d
jne    15a0 <main+0x3e0>
mov    %r14d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"--8\00"
@.str.1 = [5 x i8] c"--16\00"
@.str.2 = [5 x i8] c"--24\00"
@.str.3 = [5 x i8] c"--32\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.4 = [42 x i8] c"size = %d bytes, width = %d, height = %d\0A\00"
@.str.5 = [13 x i8] c"decode = %d\0A\00"
@.str.6 = [41 x i8] c"%02x %02x %02x %02x %02x %02x %02x %02x\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.7 = [14 x i8] c"P6\0A%d %d\0A255\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [3 x i8]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = call i8* @malloc(i32 1048576)
store i8* %22, i8** %10
store i32 0, i32* %20
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 4
br i1 %24, label %25, label %26
25: ; preds = %2
store i32 1, i32* %3
br label %355
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %26
store i32 8, i32* %20
br label %33
33: ; preds = %32, %26
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @strcmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %33
store i32 16, i32* %20
br label %40
40: ; preds = %39, %33
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @strcmp(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %40
store i32 24, i32* %20
br label %47
47: ; preds = %46, %40
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %47
store i32 32, i32* %20
br label %54
54: ; preds = %53, %47
%55 = load i32, i32* %20
%56 = icmp ne i32 %55, 0
br i1 %56, label %58, label %57
57: ; preds = %54
store i32 10, i32* %3
br label %355
58: ; preds = %54
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 2
%61 = load i8*, i8** %60
%62 = load i32, i32* @O_RDONLY
%63 = call i32 (i8*, i32, ...) @open(i8* %61, i32 %62)
store i32 %63, i32* %6
%64 = load i32, i32* %6
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %67
66: ; preds = %58
store i32 2, i32* %3
br label %355
67: ; preds = %58
%68 = load i32, i32* %6
%69 = load i8*, i8** %10
%70 = call i32 @read(i32 %68, i8* %69, i32 1048576)
store i32 %70, i32* %7
%71 = load i32, i32* %7
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %67
store i32 3, i32* %3
br label %355
74: ; preds = %67
%75 = load i32, i32* %6
%76 = call i32 @close(i32 %75)
%77 = load i8*, i8** %10
%78 = load i32, i32* %7
%79 = call i8* @realloc(i8* %77, i32 %78)
store i8* %79, i8** %10
%80 = load i8*, i8** %10
%81 = call i32 @jpeg_get_size(i8* %80)
store i32 %81, i32* %14
%82 = load i32, i32* %14
%83 = and i32 %82, 65535
store i32 %83, i32* %8
%84 = load i32, i32* %14
%85 = lshr i32 %84, 16
store i32 %85, i32* %9
%86 = load i32, i32* @stderr
%87 = load i32, i32* %7
%88 = trunc i32 %87 to i8
%89 = load i32, i32* %8
%90 = load i32, i32* %9
%91 = call i32 (i32, i8*, i8, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %88, i32 %89, i32 %90)
%92 = load i32, i32* %8
%93 = load i32, i32* %9
%94 = mul nsw i32 %92, %93
%95 = mul nsw i32 %94, 4
%96 = call i8* @malloc(i32 %95)
store i8* %96, i8** %11
store i32 0, i32* %16
%97 = load i32, i32* %8
store i32 %97, i32* %17
store i32 0, i32* %18
%98 = load i32, i32* %9
store i32 %98, i32* %19
%99 = load i8*, i8** %10
%100 = load i8*, i8** %11
%101 = load i32, i32* %16
%102 = load i32, i32* %17
%103 = load i32, i32* %18
%104 = load i32, i32* %19
%105 = load i32, i32* %20
%106 = call i32 @jpeg_decode(i8* %99, i8* %100, i32 %101, i32 %102, i32 %103, i32 %104, i32 %105)
store i32 %106, i32* %7
%107 = load i32, i32* %17
%108 = load i32, i32* %16
%109 = sub i32 %107, %108
store i32 %109, i32* %8
%110 = load i32, i32* %19
%111 = load i32, i32* %18
%112 = sub i32 %110, %111
store i32 %112, i32* %9
%113 = load i32, i32* @stderr
%114 = load i32, i32* %7
%115 = trunc i32 %114 to i8
%116 = call i32 (i32, i8*, i8, ...) @fprintf(i32 %113, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %115)
%117 = load i32, i32* @stderr
%118 = load i8*, i8** %11
%119 = getelementptr inbounds i8, i8* %118, i64 0
%120 = load i8, i8* %119
%121 = load i8*, i8** %11
%122 = getelementptr inbounds i8, i8* %121, i64 1
%123 = load i8, i8* %122
%124 = zext i8 %123 to i32
%125 = load i8*, i8** %11
%126 = getelementptr inbounds i8, i8* %125, i64 2
%127 = load i8, i8* %126
%128 = zext i8 %127 to i32
%129 = load i8*, i8** %11
%130 = getelementptr inbounds i8, i8* %129, i64 3
%131 = load i8, i8* %130
%132 = zext i8 %131 to i32
%133 = load i8*, i8** %11
%134 = getelementptr inbounds i8, i8* %133, i64 4
%135 = load i8, i8* %134
%136 = zext i8 %135 to i32
%137 = load i8*, i8** %11
%138 = getelementptr inbounds i8, i8* %137, i64 5
%139 = load i8, i8* %138
%140 = zext i8 %139 to i32
%141 = load i8*, i8** %11
%142 = getelementptr inbounds i8, i8* %141, i64 6
%143 = load i8, i8* %142
%144 = zext i8 %143 to i32
%145 = load i8*, i8** %11
%146 = getelementptr inbounds i8, i8* %145, i64 7
%147 = load i8, i8* %146
%148 = zext i8 %147 to i32
%149 = call i32 (i32, i8*, i8, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i8 zeroext %120, i32 %124, i32 %128, i32 %132, i32 %136, i32 %140, i32 %144, i32 %148)
%150 = load i32, i32* %4
%151 = icmp sge i32 %150, 3
br i1 %151, label %152, label %354
152: ; preds = %74
%153 = load i8**, i8*** %5
%154 = getelementptr inbounds i8*, i8** %153, i64 3
%155 = load i8*, i8** %154
%156 = load i32, i32* @O_WRONLY
%157 = load i32, i32* @O_CREAT
%158 = or i32 %156, %157
%159 = load i32, i32* @O_TRUNC
%160 = or i32 %158, %159
%161 = call i32 (i8*, i32, ...) @open(i8* %155, i32 %160, i32 420)
store i32 %161, i32* %6
%162 = load i32, i32* %6
%163 = icmp sge i32 %162, 0
br i1 %163, label %164, label %353
164: ; preds = %152
store i8* null, i8** %21
%165 = load i32, i32* %8
%166 = load i32, i32* %9
%167 = call i32 @asprintf(i8** %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %165, i32 %166)
store i32 %167, i32* %7
%168 = load i32, i32* %7
%169 = icmp sgt i32 %168, 0
br i1 %169, label %170, label %175
170: ; preds = %164
%171 = load i32, i32* %6
%172 = load i8*, i8** %21
%173 = load i32, i32* %7
%174 = call i32 (i32, ...) @write(i32 %171, i8* %172, i32 %173)
br label %175
175: ; preds = %170, %164
%176 = load i8*, i8** %21
%177 = call i32 @free(i8* %176)
%178 = load i32, i32* %20
switch i32 %178, label %350 [
i32 8, label %179
i32 16, label %223
i32 24, label %294
i32 32, label %321
]
179: ; preds = %175
store i32 0, i32* %7
%180 = load i8*, i8** %11
store i8* %180, i8** %12
br label %181
181: ; preds = %219, %179
%182 = load i32, i32* %7
%183 = load i32, i32* %8
%184 = load i32, i32* %9
%185 = mul nsw i32 %183, %184
%186 = icmp slt i32 %182, %185
br i1 %186, label %187, label %222
187: ; preds = %181
%188 = load i8*, i8** %12
%189 = getelementptr inbounds i8, i8* %188, i32 1
store i8* %189, i8** %12
%190 = load i8, i8* %188
%191 = zext i8 %190 to i32
store i32 %191, i32* %14
%192 = load i32, i32* %14
%193 = lshr i32 %192, 6
store i32 %193, i32* %15
%194 = load i32, i32* %15
%195 = mul i32 %194, 85
%196 = trunc i32 %195 to i8
%197 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 0
store i8 %196, i8* %197
%198 = load i32, i32* %14
%199 = lshr i32 %198, 3
%200 = and i32 %199, 7
store i32 %200, i32* %15
%201 = load i32, i32* %15
%202 = mul i32 %201, 36
%203 = load i32, i32* %15
%204 = lshr i32 %203, 1
%205 = add i32 %202, %204
%206 = trunc i32 %205 to i8
%207 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 1
store i8 %206, i8* %207
%208 = load i32, i32* %14
%209 = and i32 %208, 7
store i32 %209, i32* %15
%210 = load i32, i32* %15
%211 = mul i32 %210, 36
%212 = load i32, i32* %15
%213 = lshr i32 %212, 1
%214 = add i32 %211, %213
%215 = trunc i32 %214 to i8
%216 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 2
store i8 %215, i8* %216
%217 = load i32, i32* %6
%218 = call i32 (i32, ...) @write(i32 %217, [3 x i8]* %13, i32 3)
br label %219
219: ; preds = %187
%220 = load i32, i32* %7
%221 = add nsw i32 %220, 1
store i32 %221, i32* %7
br label %181
222: ; preds = %181
br label %350
223: ; preds = %175
store i32 0, i32* %7
%224 = load i8*, i8** %11
store i8* %224, i8** %12
br label %225
225: ; preds = %290, %223
%226 = load i32, i32* %7
%227 = load i32, i32* %8
%228 = load i32, i32* %9
%229 = mul nsw i32 %227, %228
%230 = icmp slt i32 %226, %229
br i1 %230, label %231, label %293
231: ; preds = %225
%232 = load i8*, i8** %12
%233 = getelementptr inbounds i8, i8* %232, i64 0
%234 = load i8, i8* %233
%235 = zext i8 %234 to i32
%236 = load i8*, i8** %12
%237 = getelementptr inbounds i8, i8* %236, i64 1
%238 = load i8, i8* %237
%239 = zext i8 %238 to i32
%240 = shl i32 %239, 8
%241 = add nsw i32 %235, %240
store i32 %241, i32* %14
%242 = load i8*, i8** %12
%243 = getelementptr inbounds i8, i8* %242, i64 2
store i8* %243, i8** %12
%244 = load i32, i32* %14
%245 = lshr i32 %244, 11
%246 = and i32 %245, 31
%247 = shl i32 %246, 3
%248 = trunc i32 %247 to i8
%249 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 0
store i8 %248, i8* %249
%250 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 0
%251 = load i8, i8* %250
%252 = zext i8 %251 to i32
%253 = ashr i32 %252, 5
%254 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 0
%255 = load i8, i8* %254
%256 = zext i8 %255 to i32
%257 = add nsw i32 %256, %253
%258 = trunc i32 %257 to i8
store i8 %258, i8* %254
%259 = load i32, i32* %14
%260 = lshr i32 %259, 5
%261 = and i32 %260, 63
%262 = shl i32 %261, 2
%263 = trunc i32 %262 to i8
%264 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 1
store i8 %263, i8* %264
%265 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 1
%266 = load i8, i8* %265
%267 = zext i8 %266 to i32
%268 = ashr i32 %267, 6
%269 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 1
%270 = load i8, i8* %269
%271 = zext i8 %270 to i32
%272 = add nsw i32 %271, %268
%273 = trunc i32 %272 to i8
store i8 %273, i8* %269
%274 = load i32, i32* %14
%275 = and i32 %274, 31
%276 = shl i32 %275, 3
%277 = trunc i32 %276 to i8
%278 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 2
store i8 %277, i8* %278
%279 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 2
%280 = load i8, i8* %279
%281 = zext i8 %280 to i32
%282 = ashr i32 %281, 5
%283 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 2
%284 = load i8, i8* %283
%285 = zext i8 %284 to i32
%286 = add nsw i32 %285, %282
%287 = trunc i32 %286 to i8
store i8 %287, i8* %283
%288 = load i32, i32* %6
%289 = call i32 (i32, ...) @write(i32 %288, [3 x i8]* %13, i32 3)
br label %290
290: ; preds = %231
%291 = load i32, i32* %7
%292 = add nsw i32 %291, 1
store i32 %292, i32* %7
br label %225
293: ; preds = %225
br label %350
294: ; preds = %175
store i32 0, i32* %7
%295 = load i8*, i8** %11
store i8* %295, i8** %12
br label %296
296: ; preds = %317, %294
%297 = load i32, i32* %7
%298 = load i32, i32* %8
%299 = load i32, i32* %9
%300 = mul nsw i32 %298, %299
%301 = icmp slt i32 %297, %300
br i1 %301, label %302, label %320
302: ; preds = %296
%303 = load i8*, i8** %12
%304 = getelementptr inbounds i8, i8* %303, i32 1
store i8* %304, i8** %12
%305 = load i8, i8* %303
%306 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 2
store i8 %305, i8* %306
%307 = load i8*, i8** %12
%308 = getelementptr inbounds i8, i8* %307, i32 1
store i8* %308, i8** %12
%309 = load i8, i8* %307
%310 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 1
store i8 %309, i8* %310
%311 = load i8*, i8** %12
%312 = getelementptr inbounds i8, i8* %311, i32 1
store i8* %312, i8** %12
%313 = load i8, i8* %311
%314 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 0
store i8 %313, i8* %314
%315 = load i32, i32* %6
%316 = call i32 (i32, ...) @write(i32 %315, [3 x i8]* %13, i32 3)
br label %317
317: ; preds = %302
%318 = load i32, i32* %7
%319 = add nsw i32 %318, 1
store i32 %319, i32* %7
br label %296
320: ; preds = %296
br label %350
321: ; preds = %175
store i32 0, i32* %7
%322 = load i8*, i8** %11
store i8* %322, i8** %12
br label %323
323: ; preds = %346, %321
%324 = load i32, i32* %7
%325 = load i32, i32* %8
%326 = load i32, i32* %9
%327 = mul nsw i32 %325, %326
%328 = icmp slt i32 %324, %327
br i1 %328, label %329, label %349
329: ; preds = %323
%330 = load i8*, i8** %12
%331 = getelementptr inbounds i8, i8* %330, i32 1
store i8* %331, i8** %12
%332 = load i8, i8* %330
%333 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 2
store i8 %332, i8* %333
%334 = load i8*, i8** %12
%335 = getelementptr inbounds i8, i8* %334, i32 1
store i8* %335, i8** %12
%336 = load i8, i8* %334
%337 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 1
store i8 %336, i8* %337
%338 = load i8*, i8** %12
%339 = getelementptr inbounds i8, i8* %338, i32 1
store i8* %339, i8** %12
%340 = load i8, i8* %338
%341 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 0
store i8 %340, i8* %341
%342 = load i8*, i8** %12
%343 = getelementptr inbounds i8, i8* %342, i32 1
store i8* %343, i8** %12
%344 = load i32, i32* %6
%345 = call i32 (i32, ...) @write(i32 %344, [3 x i8]* %13, i32 3)
br label %346
346: ; preds = %329
%347 = load i32, i32* %7
%348 = add nsw i32 %347, 1
store i32 %348, i32* %7
br label %323
349: ; preds = %323
br label %350
350: ; preds = %175, %349, %320, %293, %222
%351 = load i32, i32* %6
%352 = call i32 @close(i32 %351)
br label %353
353: ; preds = %350, %152
br label %354
354: ; preds = %353, %74
store i32 0, i32* %3
br label %355
355: ; preds = %354, %73, %66, %57, %25
%356 = load i32, i32* %3
ret i32 %356
}

LLVM IR (-O2):
@.str = [4 x i8] c"--8\00"
@.str.1 = [5 x i8] c"--16\00"
@.str.2 = [5 x i8] c"--24\00"
@.str.3 = [5 x i8] c"--32\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.4 = [42 x i8] c"size = %d bytes, width = %d, height = %d\0A\00"
@.str.5 = [13 x i8] c"decode = %d\0A\00"
@.str.6 = [41 x i8] c"%02x %02x %02x %02x %02x %02x %02x %02x\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.7 = [14 x i8] c"P6\0A%d %d\0A255\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [3 x i8]
%4 = alloca i8*
%5 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%7 = icmp slt i32 %0, 4
br i1 %7, label %187, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 8, i32 0
%14 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i32 16, i32 %13
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i32 24, i32 %16
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i32 32, i32 %19
%23 = icmp eq i32 %22, 0
br i1 %23, label %187, label %24
24: ; preds = %8
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDONLY
%28 = tail call i32 (i8*, i32, ...) @open(i8* %26, i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %187, label %30
30: ; preds = %24
%31 = tail call i32 @read(i32 %28, i8* %5, i32 1048576)
%32 = icmp slt i32 %31, 0
br i1 %32, label %187, label %33
33: ; preds = %30
%34 = tail call i32 @close(i32 %28)
%35 = tail call i8* @realloc(i8* %5, i32 %31)
%36 = tail call i32 @jpeg_get_size(i8* %35)
%37 = and i32 %36, 65535
%38 = lshr i32 %36, 16
%39 = load i32, i32* @stderr
%40 = trunc i32 %31 to i8
%41 = tail call i32 (i32, i8*, i8, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %40, i32 %37, i32 %38)
%42 = mul nuw nsw i32 %37, %38
%43 = shl nsw i32 %42, 2
%44 = tail call i8* @malloc(i32 %43)
%45 = tail call i32 @jpeg_decode(i8* %35, i8* %44, i32 0, i32 %37, i32 0, i32 %38, i32 %22)
%46 = load i32, i32* @stderr
%47 = trunc i32 %45 to i8
%48 = tail call i32 (i32, i8*, i8, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %47)
%49 = load i32, i32* @stderr
%50 = load i8, i8* %44
%51 = getelementptr inbounds i8, i8* %44, i64 1
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = getelementptr inbounds i8, i8* %44, i64 2
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = getelementptr inbounds i8, i8* %44, i64 3
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = getelementptr inbounds i8, i8* %44, i64 4
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = getelementptr inbounds i8, i8* %44, i64 5
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = getelementptr inbounds i8, i8* %44, i64 6
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = getelementptr inbounds i8, i8* %44, i64 7
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = tail call i32 (i32, i8*, i8, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i8 zeroext %50, i32 %53, i32 %56, i32 %59, i32 %62, i32 %65, i32 %68, i32 %71)
%73 = getelementptr inbounds i8*, i8** %1, i64 3
%74 = load i8*, i8** %73
%75 = load i32, i32* @O_WRONLY
%76 = load i32, i32* @O_CREAT
%77 = or i32 %76, %75
%78 = load i32, i32* @O_TRUNC
%79 = or i32 %77, %78
%80 = tail call i32 (i8*, i32, ...) @open(i8* %74, i32 %79, i32 420)
%81 = icmp sgt i32 %80, -1
br i1 %81, label %82, label %187
82: ; preds = %33
%83 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%84 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %37, i32 %38)
%85 = icmp sgt i32 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %82
%87 = load i8*, i8** %4
%88 = call i32 (i32, ...) @write(i32 %80, i8* %87, i32 %84)
br label %89
89: ; preds = %86, %82
%90 = load i8*, i8** %4
%91 = call i32 @free(i8* %90)
%92 = add nsw i32 %22, -8
%93 = lshr exact i32 %92, 3
switch i32 %93, label %185 [
i32 0, label %109
i32 1, label %104
i32 2, label %99
i32 3, label %94
]
94: ; preds = %89
%95 = icmp eq i32 %42, 0
br i1 %95, label %185, label %96
96: ; preds = %94
%97 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
%98 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
br label %173
99: ; preds = %89
%100 = icmp eq i32 %42, 0
br i1 %100, label %185, label %101
101: ; preds = %99
%102 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
%103 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
br label %161
104: ; preds = %89
%105 = icmp eq i32 %42, 0
br i1 %105, label %185, label %106
106: ; preds = %104
%107 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%108 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
br label %136
109: ; preds = %89
%110 = icmp eq i32 %42, 0
br i1 %110, label %185, label %111
111: ; preds = %109
%112 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%113 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
br label %114
114: ; preds = %111, %114
%115 = phi i32 [ 0, %111 ], [ %134, %114 ]
%116 = phi i8* [ %44, %111 ], [ %117, %114 ]
%117 = getelementptr inbounds i8, i8* %116, i64 1
%118 = load i8, i8* %116
%119 = zext i8 %118 to i32
%120 = lshr i8 %118, 6
%121 = mul nuw i8 %120, 85
store i8 %121, i8* %6
%122 = lshr i32 %119, 3
%123 = and i32 %122, 7
%124 = mul nuw nsw i32 %123, 36
%125 = lshr i32 %123, 1
%126 = or i32 %124, %125
%127 = trunc i32 %126 to i8
store i8 %127, i8* %112
%128 = and i32 %119, 7
%129 = mul nuw nsw i32 %128, 36
%130 = lshr i32 %128, 1
%131 = or i32 %129, %130
%132 = trunc i32 %131 to i8
store i8 %132, i8* %113
%133 = call i32 (i32, ...) @write(i32 %80, [3 x i8]* %3, i32 3)
%134 = add nuw i32 %115, 1
%135 = icmp eq i32 %134, %42
br i1 %135, label %185, label %114
136: ; preds = %106, %136
%137 = phi i32 [ 0, %106 ], [ %159, %136 ]
%138 = phi i8* [ %44, %106 ], [ %146, %136 ]
%139 = load i8, i8* %138
%140 = zext i8 %139 to i32
%141 = getelementptr inbounds i8, i8* %138, i64 1
%142 = load i8, i8* %141
%143 = zext i8 %142 to i32
%144 = shl nuw nsw i32 %143, 8
%145 = or i32 %144, %140
%146 = getelementptr inbounds i8, i8* %138, i64 2
%147 = and i8 %142, -8
%148 = lshr i8 %142, 5
%149 = or i8 %148, %147
store i8 %149, i8* %6
%150 = lshr i32 %145, 3
%151 = and i32 %150, 252
%152 = lshr i32 %151, 6
%153 = or i32 %152, %151
%154 = trunc i32 %153 to i8
store i8 %154, i8* %107
%155 = shl i8 %139, 3
%156 = lshr i8 %155, 5
%157 = or i8 %156, %155
store i8 %157, i8* %108
%158 = call i32 (i32, ...) @write(i32 %80, [3 x i8]* %3, i32 3)
%159 = add nuw i32 %137, 1
%160 = icmp eq i32 %159, %42
br i1 %160, label %185, label %136
161: ; preds = %101, %161
%162 = phi i32 [ 0, %101 ], [ %171, %161 ]
%163 = phi i8* [ %44, %101 ], [ %168, %161 ]
%164 = getelementptr inbounds i8, i8* %163, i64 1
%165 = load i8, i8* %163
store i8 %165, i8* %102
%166 = getelementptr inbounds i8, i8* %163, i64 2
%167 = load i8, i8* %164
store i8 %167, i8* %103
%168 = getelementptr inbounds i8, i8* %163, i64 3
%169 = load i8, i8* %166
store i8 %169, i8* %6
%170 = call i32 (i32, ...) @write(i32 %80, [3 x i8]* %3, i32 3)
%171 = add nuw i32 %162, 1
%172 = icmp eq i32 %171, %42
br i1 %172, label %185, label %161
173: ; preds = %96, %173
%174 = phi i32 [ 0, %96 ], [ %183, %173 ]
%175 = phi i8* [ %44, %96 ], [ %181, %173 ]
%176 = getelementptr inbounds i8, i8* %175, i64 1
%177 = load i8, i8* %175
store i8 %177, i8* %97
%178 = getelementptr inbounds i8, i8* %175, i64 2
%179 = load i8, i8* %176
store i8 %179, i8* %98
%180 = load i8, i8* %178
store i8 %180, i8* %6
%181 = getelementptr inbounds i8, i8* %175, i64 4
%182 = call i32 (i32, ...) @write(i32 %80, [3 x i8]* %3, i32 3)
%183 = add nuw i32 %174, 1
%184 = icmp eq i32 %183, %42
br i1 %184, label %185, label %173
185: ; preds = %173, %161, %136, %114, %94, %99, %104, %109, %89
%186 = call i32 @close(i32 %80)
br label %187
187: ; preds = %185, %33, %30, %24, %8, %2
%188 = phi i32 [ 1, %2 ], [ 10, %8 ], [ 2, %24 ], [ 3, %30 ], [ 0, %33 ], [ 0, %185 ]
ret i32 %188
}