#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*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strdup(char *);
char *strstr(char *, char *);
int main(int argc, char **argv) {
  char c;
  int views = 0;
  long length;
  size_t amount;
  char *buffer;
  char *fnm;
  char *fnmbase;
  if (argc != 2) {
    fprintf(stdout, "Usage: %s [filename]\n", argv[0]);
    return 0;
  } else {
    fnm = argv[1];
    fnmbase = strdup(argv[1]);
    char *ext = strstr(fnmbase, ".mpo");
    if (ext != NULL) {
      ext[0] = '\0';
    }
  }
  FILE *f = fopen(fnm, "rb");
  if (f == NULL) {
    fprintf(stderr, "error opening file \"%s\"\n", fnm);
    return 1;
  }
  fseek(f, 0, SEEK_END);
  length = ftell(f);
  rewind(f);
  buffer = (char *)malloc(sizeof(char) * length);
  if (buffer == NULL) {
    fprintf(stderr, "failed to allocate memory\n");
    return 2;
  } else {
    fprintf(stdout, "Allocated %ld chars of memory.\n", length);
  }
  amount = fread(buffer, 1, length, f);
  if (amount != length) {
    fprintf(stderr, "error loading file\n");
    return 3;
  }
  fclose(f);
  char *view = buffer;
  char *last = NULL;
  char *wnm = (char *)malloc(256);
  while (view < buffer + length - 4) {
    if (((char)view[0] % 255) == (char)0xff) {
      if (((char)view[1] % 255) == (char)0xd8) {
        if (((char)view[2] % 255) == (char)0xff) {
          if (((char)view[3] % 255) == (char)0xe1) {
            fprintf(stdout, "View found at offset %d\n", view - buffer);
            views++;
            if (last != NULL) {
              sprintf(wnm, "%s.v%d.jpg", fnmbase, views - 1);
              FILE *w = fopen(wnm, "wb");
              fwrite(last, 1, view - last, w);
              fclose(w);
              fprintf(stdout, "Created %s\n", wnm);
            }
            last = view;
            view += 4;
          } else {
            view += 2;
          }
        } else {
          view += 3;
        }
      } else {
        view += 1;
      }
    } else {
      view += 1;
    }
  }
  if (views > 1) {
    sprintf(wnm, "%s.v%d.jpg", fnmbase, views);
    FILE *w = fopen(wnm, "wb");
    fwrite(last, 1, buffer + length - last, w);
    fclose(w);
    fprintf(stdout, "Created %s\n", wnm);
  } else if (views == 0) {
    fprintf(stdout, "No views found.\n");
  }
  free(wnm);
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1224 <main+0x54>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15ea <main+0x41a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xdca(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1267 <main+0x97>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
jmp    126c <main+0x9c>
mov    -0x38(%rbp),%rdi
lea    0xda4(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12b2 <main+0xe2>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ea <main+0x41a>
mov    -0x50(%rbp),%rdi
mov    0x2d2b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x50(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x50(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    131d <main+0x14d>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
lea    0xd2d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    15ea <main+0x41a>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd21(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1383 <main+0x1b3>
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
lea    0xd02(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    15ea <main+0x41a>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x58(%rbp),%rax
mov    -0x30(%rbp),%rcx
add    -0x20(%rbp),%rcx
add    $0xfffffffffffffffc,%rcx
cmp    %rcx,%rax
jae    152a <main+0x35a>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
cmp    $0xffffffff,%edx
jne    1519 <main+0x349>
mov    -0x58(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
cmp    $0xffffffd8,%edx
jne    1508 <main+0x338>
mov    -0x58(%rbp),%rax
movsbl 0x2(%rax),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
cmp    $0xffffffff,%edx
jne    14f7 <main+0x327>
mov    -0x58(%rbp),%rax
movsbl 0x3(%rax),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
cmp    $0xffffffe1,%edx
jne    14e6 <main+0x316>
mov    0x2ba3(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rdx
mov    -0x30(%rbp),%rax
sub    %rax,%rdx
lea    0xc45(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     14cd <main+0x2fd>
mov    -0x68(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
lea    0xc2e(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x68(%rbp),%rdi
lea    0xc29(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x70(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    -0x60(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    -0x70(%rbp),%rcx
mov    $0x1,%esi
call   10d0 <fwrite@plt>
mov    -0x70(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2b17(%rip),%rax
mov    (%rax),%edi
mov    -0x68(%rbp),%rdx
lea    0xbe7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x58(%rbp)
jmp    14f2 <main+0x322>
mov    -0x58(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x58(%rbp)
jmp    1503 <main+0x333>
mov    -0x58(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x58(%rbp)
jmp    1514 <main+0x344>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1525 <main+0x355>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    13aa <main+0x1da>
cmpl   $0x1,-0x18(%rbp)
jle    15ab <main+0x3db>
mov    -0x68(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x18(%rbp),%ecx
lea    0xb59(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x68(%rbp),%rdi
lea    0xb54(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
mov    -0x60(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    -0x78(%rbp),%rcx
mov    $0x1,%esi
call   10d0 <fwrite@plt>
mov    -0x78(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2a3e(%rip),%rax
mov    (%rax),%edi
mov    -0x68(%rbp),%rdx
lea    0xb0e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    15d1 <main+0x401>
cmpl   $0x0,-0x18(%rbp)
jne    15cc <main+0x3fc>
mov    0x2a14(%rip),%rax
mov    (%rax),%edi
lea    0xaf4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    15d1 <main+0x401>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    12d2 <main+0x102>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   10e0 <strdup@plt>
mov    %rax,%r14
lea    0xe19(%rip),%rsi
mov    %rax,%rdi
call   10f0 <strstr@plt>
test   %rax,%rax
je     120d <main+0x3d>
movb   $0x0,(%rax)
lea    0xe07(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12f3 <main+0x123>
mov    %rax,%rbp
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbp,%rdi
call   1080 <ftell@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1060 <rewind@plt>
mov    %ebx,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1317 <main+0x147>
mov    %rax,%r15
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1040 <fread@plt>
cmp    %rbx,%rax
jne    1338 <main+0x168>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,%r13
lea    (%r15,%rbx,1),%rbp
add    $0xfffffffffffffffc,%rbp
cmp    %r15,%rbp
jbe    14a2 <main+0x2d2>
mov    %r13,0x8(%rsp)
add    %r15,%rbx
xor    %ecx,%ecx
xor    %r12d,%r12d
mov    %r15,%r13
jmp    136c <main+0x19c>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd1b(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    14cb <main+0x2fb>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
lea    0xd1b(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebx
jmp    14cb <main+0x2fb>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
lea    0xd10(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x2,%ebx
jmp    14cb <main+0x2fb>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
lea    0xd2a(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x3,%ebx
jmp    14cb <main+0x2fb>
add    $0x2,%r13
mov    %r13,%rax
mov    %rax,%r13
cmp    %rbp,%rax
jae    1437 <main+0x267>
lea    0x1(%r13),%rax
cmpb   $0xff,0x0(%r13)
jne    1360 <main+0x190>
cmpb   $0xd8,(%rax)
jne    1360 <main+0x190>
lea    0x3(%r13),%rax
cmpb   $0xff,0x2(%r13)
jne    1360 <main+0x190>
cmpb   $0xe1,(%rax)
jne    1359 <main+0x189>
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rdx
sub    %r15,%rdx
lea    0xce4(%rip),%rsi
xor    %eax,%eax
mov    %ecx,0x4(%rsp)
call   1070 <fprintf@plt>
test   %r12,%r12
je     1424 <main+0x254>
mov    0x8(%rsp),%rax
mov    %r12,0x10(%rsp)
mov    %rax,%r12
mov    %rax,%rdi
lea    0xcd6(%rip),%rsi
mov    %r14,%rdx
mov    0x4(%rsp),%ecx
call   10c0 <sprintf@plt>
mov    %r12,%rdi
lea    0xccb(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r12
mov    %r13d,%edx
mov    0x10(%rsp),%rdi
sub    %edi,%edx
mov    $0x1,%esi
mov    %rax,%rcx
call   10d0 <fwrite@plt>
mov    %r12,%rdi
mov    0x2bc8(%rip),%r12
call   1050 <fclose@plt>
mov    (%r12),%edi
lea    0xc95(%rip),%rsi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x4(%rsp),%ecx
add    $0x1,%ecx
lea    0x4(%r13),%rax
mov    %r13,%r12
jmp    1360 <main+0x190>
cmp    $0x2,%ecx
mov    0x8(%rsp),%r13
jl     149e <main+0x2ce>
lea    0xc57(%rip),%rsi
mov    %r13,%rdi
mov    %r14,%rdx
call   10c0 <sprintf@plt>
lea    0xc50(%rip),%rsi
mov    %r13,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbp
sub    %r12d,%ebx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %rax,%rcx
call   10d0 <fwrite@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    0x2b47(%rip),%rax
mov    (%rax),%edi
lea    0xc1b(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    14b9 <main+0x2e9>
test   %ecx,%ecx
jne    14b9 <main+0x2e9>
mov    0x2b27(%rip),%rax
mov    (%rax),%edi
lea    0xc07(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [22 x i8] c"Usage: %s [filename]\0A\00"
@.str.1 = [5 x i8] c".mpo\00"
@.str.2 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.3 = [25 x i8] c"error opening file \22%s\22\0A\00"
@SEEK_END = global i32 0
@.str.4 = [27 x i8] c"failed to allocate memory\0A\00"
@.str.5 = [32 x i8] c"Allocated %ld chars of memory.\0A\00"
@.str.6 = [20 x i8] c"error loading file\0A\00"
@.str.7 = [25 x i8] c"View found at offset %d\0A\00"
@.str.8 = [11 x i8] c"%s.v%d.jpg\00"
@.str.9 = [3 x i8] c"wb\00"
@.str.10 = [12 x i8] c"Created %s\0A\00"
@.str.11 = [17 x i8] c"No views found.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i32*
%19 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 2
br i1 %21, label %22, label %28
22: ; preds = %2
%23 = load i32, i32* @stdout
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %26)
store i32 0, i32* %3
br label %219
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
store i8* %31, i8** %11
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i8* @strdup(i8* %34)
store i8* %35, i8** %12
%36 = load i8*, i8** %12
%37 = call i8* @strstr(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %37, i8** %13
%38 = load i8*, i8** %13
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %43
40: ; preds = %28
%41 = load i8*, i8** %13
%42 = getelementptr inbounds i8, i8* %41, i64 0
store i8 0, i8* %42
br label %43
43: ; preds = %40, %28
br label %44
44: ; preds = %43
%45 = load i8*, i8** %11
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %46, i32** %14
%47 = load i32*, i32** %14
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %11
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %51)
store i32 1, i32* %3
br label %219
53: ; preds = %44
%54 = load i32*, i32** %14
%55 = load i32, i32* @SEEK_END
%56 = call i32 @fseek(i32* %54, i32 0, i32 %55)
%57 = load i32*, i32** %14
%58 = call i64 @ftell(i32* %57)
store i64 %58, i64* %8
%59 = load i32*, i32** %14
%60 = call i32 @rewind(i32* %59)
%61 = load i64, i64* %8
%62 = mul i64 1, %61
%63 = trunc i64 %62 to i32
%64 = call i64 @malloc(i32 %63)
%65 = inttoptr i64 %64 to i8*
store i8* %65, i8** %10
%66 = load i8*, i8** %10
%67 = icmp eq i8* %66, null
br i1 %67, label %68, label %71
68: ; preds = %53
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %219
71: ; preds = %53
%72 = load i32, i32* @stdout
%73 = load i64, i64* %8
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i64 %73)
br label %75
75: ; preds = %71
%76 = load i8*, i8** %10
%77 = load i64, i64* %8
%78 = load i32*, i32** %14
%79 = call i64 @fread(i8* %76, i32 1, i64 %77, i32* %78)
store i64 %79, i64* %9
%80 = load i64, i64* %9
%81 = load i64, i64* %8
%82 = icmp ne i64 %80, %81
br i1 %82, label %83, label %86
83: ; preds = %75
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
store i32 3, i32* %3
br label %219
86: ; preds = %75
%87 = load i32*, i32** %14
%88 = call i32 @fclose(i32* %87)
%89 = load i8*, i8** %10
store i8* %89, i8** %15
store i8* null, i8** %16
%90 = call i64 @malloc(i32 256)
%91 = inttoptr i64 %90 to i8*
store i8* %91, i8** %17
br label %92
92: ; preds = %180, %86
%93 = load i8*, i8** %15
%94 = load i8*, i8** %10
%95 = load i64, i64* %8
%96 = getelementptr inbounds i8, i8* %94, i64 %95
%97 = getelementptr inbounds i8, i8* %96, i64 -4
%98 = icmp ult i8* %93, %97
br i1 %98, label %99, label %181
99: ; preds = %92
%100 = load i8*, i8** %15
%101 = getelementptr inbounds i8, i8* %100, i64 0
%102 = load i8, i8* %101
%103 = sext i8 %102 to i32
%104 = srem i32 %103, 255
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %177
106: ; preds = %99
%107 = load i8*, i8** %15
%108 = getelementptr inbounds i8, i8* %107, i64 1
%109 = load i8, i8* %108
%110 = sext i8 %109 to i32
%111 = srem i32 %110, 255
%112 = icmp eq i32 %111, -40
br i1 %112, label %113, label %173
113: ; preds = %106
%114 = load i8*, i8** %15
%115 = getelementptr inbounds i8, i8* %114, i64 2
%116 = load i8, i8* %115
%117 = sext i8 %116 to i32
%118 = srem i32 %117, 255
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %169
120: ; preds = %113
%121 = load i8*, i8** %15
%122 = getelementptr inbounds i8, i8* %121, i64 3
%123 = load i8, i8* %122
%124 = sext i8 %123 to i32
%125 = srem i32 %124, 255
%126 = icmp eq i32 %125, -31
br i1 %126, label %127, label %165
127: ; preds = %120
%128 = load i32, i32* @stdout
%129 = load i8*, i8** %15
%130 = load i8*, i8** %10
%131 = ptrtoint i8* %129 to i64
%132 = ptrtoint i8* %130 to i64
%133 = sub i64 %131, %132
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i64 %133)
%135 = load i32, i32* %7
%136 = add nsw i32 %135, 1
store i32 %136, i32* %7
%137 = load i8*, i8** %16
%138 = icmp ne i8* %137, null
br i1 %138, label %139, label %161
139: ; preds = %127
%140 = load i8*, i8** %17
%141 = load i8*, i8** %12
%142 = load i32, i32* %7
%143 = sub nsw i32 %142, 1
%144 = call i32 @sprintf(i8* %140, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %141, i32 %143)
%145 = load i8*, i8** %17
%146 = call i32* @fopen(i8* %145, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
store i32* %146, i32** %18
%147 = load i8*, i8** %16
%148 = load i8*, i8** %15
%149 = load i8*, i8** %16
%150 = ptrtoint i8* %148 to i64
%151 = ptrtoint i8* %149 to i64
%152 = sub i64 %150, %151
%153 = trunc i64 %152 to i32
%154 = load i32*, i32** %18
%155 = call i32 @fwrite(i8* %147, i32 1, i32 %153, i32* %154)
%156 = load i32*, i32** %18
%157 = call i32 @fclose(i32* %156)
%158 = load i32, i32* @stdout
%159 = load i8*, i8** %17
%160 = call i32 (i32, i8*, ...) @fprintf(i32 %158, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %159)
br label %161
161: ; preds = %139, %127
%162 = load i8*, i8** %15
store i8* %162, i8** %16
%163 = load i8*, i8** %15
%164 = getelementptr inbounds i8, i8* %163, i64 4
store i8* %164, i8** %15
br label %168
165: ; preds = %120
%166 = load i8*, i8** %15
%167 = getelementptr inbounds i8, i8* %166, i64 2
store i8* %167, i8** %15
br label %168
168: ; preds = %165, %161
br label %172
169: ; preds = %113
%170 = load i8*, i8** %15
%171 = getelementptr inbounds i8, i8* %170, i64 3
store i8* %171, i8** %15
br label %172
172: ; preds = %169, %168
br label %176
173: ; preds = %106
%174 = load i8*, i8** %15
%175 = getelementptr inbounds i8, i8* %174, i64 1
store i8* %175, i8** %15
br label %176
176: ; preds = %173, %172
br label %180
177: ; preds = %99
%178 = load i8*, i8** %15
%179 = getelementptr inbounds i8, i8* %178, i64 1
store i8* %179, i8** %15
br label %180
180: ; preds = %177, %176
br label %92
181: ; preds = %92
%182 = load i32, i32* %7
%183 = icmp sgt i32 %182, 1
br i1 %183, label %184, label %207
184: ; preds = %181
%185 = load i8*, i8** %17
%186 = load i8*, i8** %12
%187 = load i32, i32* %7
%188 = call i32 @sprintf(i8* %185, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %186, i32 %187)
%189 = load i8*, i8** %17
%190 = call i32* @fopen(i8* %189, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
store i32* %190, i32** %19
%191 = load i8*, i8** %16
%192 = load i8*, i8** %10
%193 = load i64, i64* %8
%194 = getelementptr inbounds i8, i8* %192, i64 %193
%195 = load i8*, i8** %16
%196 = ptrtoint i8* %194 to i64
%197 = ptrtoint i8* %195 to i64
%198 = sub i64 %196, %197
%199 = trunc i64 %198 to i32
%200 = load i32*, i32** %19
%201 = call i32 @fwrite(i8* %191, i32 1, i32 %199, i32* %200)
%202 = load i32*, i32** %19
%203 = call i32 @fclose(i32* %202)
%204 = load i32, i32* @stdout
%205 = load i8*, i8** %17
%206 = call i32 (i32, i8*, ...) @fprintf(i32 %204, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %205)
br label %214
207: ; preds = %181
%208 = load i32, i32* %7
%209 = icmp eq i32 %208, 0
br i1 %209, label %210, label %213
210: ; preds = %207
%211 = load i32, i32* @stdout
%212 = call i32 (i32, i8*, ...) @fprintf(i32 %211, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %213
213: ; preds = %210, %207
br label %214
214: ; preds = %213, %184
%215 = load i8*, i8** %17
%216 = call i32 @free(i8* %215)
%217 = load i8*, i8** %10
%218 = call i32 @free(i8* %217)
store i32 0, i32* %3
br label %219
219: ; preds = %214, %83, %68, %49, %22
%220 = load i32, i32* %3
ret i32 %220
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [22 x i8] c"Usage: %s [filename]\0A\00"
@.str.1 = [5 x i8] c".mpo\00"
@.str.2 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.3 = [25 x i8] c"error opening file \22%s\22\0A\00"
@SEEK_END = global i32 0
@.str.4 = [27 x i8] c"failed to allocate memory\0A\00"
@.str.5 = [32 x i8] c"Allocated %ld chars of memory.\0A\00"
@.str.6 = [20 x i8] c"error loading file\0A\00"
@.str.7 = [25 x i8] c"View found at offset %d\0A\00"
@.str.8 = [11 x i8] c"%s.v%d.jpg\00"
@.str.9 = [3 x i8] c"wb\00"
@.str.10 = [12 x i8] c"Created %s\0A\00"
@.str.11 = [17 x i8] c"No views found.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stdout
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %111
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i8* @strdup(i8* %10)
%12 = tail call i8* @strstr(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %8
store i8 0, i8* %12
br label %15
15: ; preds = %14, %8
%16 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %10)
br label %111
21: ; preds = %15
%22 = load i32, i32* @SEEK_END
%23 = tail call i32 @fseek(i32* %16, i32 0, i32 %22)
%24 = tail call i64 @ftell(i32* %16)
%25 = tail call i32 @rewind(i32* %16)
%26 = trunc i64 %24 to i32
%27 = tail call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
%29 = icmp eq i64 %27, 0
br i1 %29, label %30, label %33
30: ; preds = %21
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %111
33: ; preds = %21
%34 = load i32, i32* @stdout
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i64 %24)
%36 = tail call i64 @fread(i8* %28, i32 1, i64 %24, i32* %16)
%37 = icmp eq i64 %36, %24
br i1 %37, label %41, label %38
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %111
41: ; preds = %33
%42 = tail call i32 @fclose(i32* %16)
%43 = tail call i64 @malloc(i32 256)
%44 = inttoptr i64 %43 to i8*
%45 = getelementptr inbounds i8, i8* %28, i64 %24
%46 = getelementptr inbounds i8, i8* %45, i64 -4
%47 = icmp ugt i8* %46, %28
br i1 %47, label %48, label %105
48: ; preds = %41, %85
%49 = phi i32 [ %88, %85 ], [ 0, %41 ]
%50 = phi i8* [ %87, %85 ], [ null, %41 ]
%51 = phi i8* [ %86, %85 ], [ %28, %41 ]
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, -1
%54 = getelementptr inbounds i8, i8* %51, i64 1
br i1 %53, label %55, label %85
55: ; preds = %48
%56 = load i8, i8* %54
%57 = icmp eq i8 %56, -40
br i1 %57, label %58, label %85
58: ; preds = %55
%59 = getelementptr inbounds i8, i8* %51, i64 2
%60 = load i8, i8* %59
%61 = icmp eq i8 %60, -1
%62 = getelementptr inbounds i8, i8* %51, i64 3
br i1 %61, label %63, label %85
63: ; preds = %58
%64 = load i8, i8* %62
%65 = icmp eq i8 %64, -31
br i1 %65, label %66, label %85
66: ; preds = %63
%67 = load i32, i32* @stdout
%68 = ptrtoint i8* %51 to i64
%69 = sub i64 %68, %27
%70 = tail call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i64 %69)
%71 = add nsw i32 %49, 1
%72 = icmp eq i8* %50, null
br i1 %72, label %83, label %73
73: ; preds = %66
%74 = tail call i32 @sprintf(i8* dereferenceable(1) %44, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %11, i32 %49)
%75 = tail call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%76 = ptrtoint i8* %50 to i64
%77 = sub i64 %68, %76
%78 = trunc i64 %77 to i32
%79 = tail call i32 @fwrite(i8* %50, i32 1, i32 %78, i32* %75)
%80 = tail call i32 @fclose(i32* %75)
%81 = load i32, i32* @stdout
%82 = tail call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %44)
br label %83
83: ; preds = %73, %66
%84 = getelementptr inbounds i8, i8* %51, i64 4
br label %85
85: ; preds = %48, %58, %55, %63, %83
%86 = phi i8* [ %84, %83 ], [ %59, %63 ], [ %54, %55 ], [ %62, %58 ], [ %54, %48 ]
%87 = phi i8* [ %51, %83 ], [ %50, %63 ], [ %50, %55 ], [ %50, %58 ], [ %50, %48 ]
%88 = phi i32 [ %71, %83 ], [ %49, %63 ], [ %49, %55 ], [ %49, %58 ], [ %49, %48 ]
%89 = icmp ult i8* %86, %46
br i1 %89, label %48, label %90
90: ; preds = %85
%91 = icmp sgt i32 %88, 1
br i1 %91, label %92, label %103
92: ; preds = %90
%93 = tail call i32 @sprintf(i8* dereferenceable(1) %44, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %11, i32 %88)
%94 = tail call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%95 = ptrtoint i8* %45 to i64
%96 = ptrtoint i8* %87 to i64
%97 = sub i64 %95, %96
%98 = trunc i64 %97 to i32
%99 = tail call i32 @fwrite(i8* %87, i32 1, i32 %98, i32* %94)
%100 = tail call i32 @fclose(i32* %94)
%101 = load i32, i32* @stdout
%102 = tail call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %44)
br label %108
103: ; preds = %90
%104 = icmp eq i32 %88, 0
br i1 %104, label %105, label %108
105: ; preds = %41, %103
%106 = load i32, i32* @stdout
%107 = tail call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %108
108: ; preds = %103, %105, %92
%109 = tail call i32 @free(i8* %44)
%110 = tail call i32 @free(i8* %28)
br label %111
111: ; preds = %18, %30, %38, %108, %4
%112 = phi i32 [ 0, %4 ], [ 1, %18 ], [ 2, %30 ], [ 3, %38 ], [ 0, %108 ]
ret i32 %112
}