#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int getopt(int, char **, char *);
int optind;
scalar_t__ read_img_frame(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int c;
  char *inname;
  FILE *inf;
  int fnum;
  char rgb[320 * 200 * 3];
  char outname[1000];
  FILE *outf;
  while ((c = getopt(argc, argv, "")) != EOF) {
    switch (c) {
    default:
      usage();
    }
  }
  if (optind >= argc)
    usage();
  inname = argv[optind++];
  if (optind != argc)
    usage();
  if ((inf = fopen(inname, "rb")) == NULL) {
    fprintf(stderr, "can't open %s\n", inname);
    exit(1);
  }
  fnum = 0;
  while (1) {
    fnum++;
    if (read_img_frame(inf, rgb) < 0)
      break;
    sprintf(outname, "c%02d.ppm", fnum);
    if ((outf = fopen(outname, "wb")) == NULL) {
      fprintf(stderr, "can't create %s\n", outname);
      exit(1);
    }
    fprintf(outf, "P6\n320 200\n255\n");
    fwrite(rgb, 1, 3 * 320 * 200, outf);
    fclose(outf);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2f230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe88(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%eax
je     11da <main+0x4a>
mov    $0x0,%al
call   1050 <usage@plt>
jmp    11a9 <main+0x19>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     11f3 <main+0x63>
mov    $0x0,%al
call   1050 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2de2(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2dd4(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
je     1232 <main+0xa2>
mov    $0x0,%al
call   1050 <usage@plt>
mov    -0x20(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1276 <main+0xe6>
mov    0x2d79(%rip),%rax
movslq (%rax),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x2ee30(%rbp),%rsi
call   1080 <read_img_frame@plt>
cmp    $0x0,%rax
jge    12a5 <main+0x115>
jmp    134b <main+0x1bb>
lea    -0x2f220(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xd5c(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x2f220(%rbp),%rdi
lea    0xd53(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x2f228(%rbp)
cmp    $0x0,%rax
jne    1308 <main+0x178>
mov    0x2cea(%rip),%rax
movslq (%rax),%rdi
lea    -0x2f220(%rbp),%rdx
lea    0xd28(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x2f228(%rbp),%rdi
lea    0xd1a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    -0x2ee30(%rbp),%rdi
mov    -0x2f228(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2ee00,%edx
call   10b0 <fwrite@plt>
mov    -0x2f228(%rbp),%rdi
call   1030 <fclose@plt>
jmp    127d <main+0xed>
xor    %eax,%eax
add    $0x2f230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2f1f8,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xe92(%rip),%rdx
call   1070 <getopt@plt>
mov    0x2e2f(%rip),%r15
cmp    (%r15),%eax
je     11e9 <main+0x59>
lea    0xe7a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1050 <usage@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1070 <getopt@plt>
cmp    (%r15),%eax
jne    11d0 <main+0x40>
mov    0x2df0(%rip),%r14
mov    (%r14),%eax
cmp    %ebx,%eax
jl     1201 <main+0x71>
xor    %eax,%eax
call   1050 <usage@plt>
mov    (%r14),%eax
lea    0x1(%rax),%ecx
mov    %ecx,(%r14)
cltq
mov    0x0(%rbp,%rax,8),%rbp
cmp    %ebx,%ecx
je     1219 <main+0x89>
xor    %eax,%eax
call   1050 <usage@plt>
lea    0xde0(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1316 <main+0x186>
mov    %rax,%r15
lea    0x3f0(%rsp),%rsi
mov    %rax,%rdi
call   1080 <read_img_frame@plt>
test   %rax,%rax
js     12dd <main+0x14d>
mov    $0x1,%ebp
mov    %rsp,%rbx
lea    0xdd4(%rip),%r13
lea    0x3f0(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
lea    0xd98(%rip),%rsi
mov    %ebp,%edx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
lea    0xd91(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12f1 <main+0x161>
mov    %rax,%r12
mov    $0xf,%esi
mov    $0x1,%edx
mov    %r13,%rdi
mov    %rax,%rcx
call   10b0 <fwrite@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x2ee00,%edx
mov    %r12,%rcx
call   10b0 <fwrite@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <read_img_frame@plt>
test   %rax,%rax
jns    1270 <main+0xe0>
xor    %eax,%eax
add    $0x2f1f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cd8(%rip),%rax
movslq (%rax),%rdi
lea    0xd1d(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2cb3(%rip),%rax
movslq (%rax),%rdi
lea    0xcdc(%rip),%rsi
mov    %rbp,%rdx
jmp    1305 <main+0x175>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@EOF = global i32 0
@optind = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"can't open %s\0A\00"
@.str.3 = [10 x i8] c"c%02d.ppm\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [17 x i8] c"can't create %s\0A\00"
@.str.6 = [16 x i8] c"P6\0A320 200\0A255\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 i32*
%9 = alloca i32
%10 = alloca [192000 x i8]
%11 = alloca [1000 x i8]
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %13
13: ; preds = %23, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %6
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %13
%20 = load i32, i32* %6
switch i32 %20, label %21 [
]
21: ; preds = %19
%22 = call i32 (...) @usage()
br label %23
23: ; preds = %21
br label %13
24: ; preds = %13
%25 = load i32, i32* @optind
%26 = load i32, i32* %4
%27 = icmp sge i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 (...) @usage()
br label %30
30: ; preds = %28, %24
%31 = load i8**, i8*** %5
%32 = load i32, i32* @optind
%33 = add nsw i32 %32, 1
store i32 %33, i32* @optind
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8*, i8** %31, i64 %34
%36 = load i8*, i8** %35
store i8* %36, i8** %7
%37 = load i32, i32* @optind
%38 = load i32, i32* %4
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %30
%41 = call i32 (...) @usage()
br label %42
42: ; preds = %40, %30
%43 = load i8*, i8** %7
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %44, i32** %8
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %53
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = sext i32 %47 to i64
%49 = inttoptr i64 %48 to i32*
%50 = load i8*, i8** %7
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %42
store i32 0, i32* %9
br label %54
54: ; preds = %53, %76
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
%57 = load i32*, i32** %8
%58 = getelementptr inbounds [192000 x i8], [192000 x i8]* %10, i64 0, i64 0
%59 = call i64 @read_img_frame(i32* %57, i8* %58)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %54
br label %84
62: ; preds = %54
%63 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%64 = load i32, i32* %9
%65 = call i32 @sprintf(i8* %63, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %64)
%66 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%67 = call i32* @fopen(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %67, i32** %12
%68 = icmp eq i32* %67, null
br i1 %68, label %69, label %76
69: ; preds = %62
%70 = load i32, i32* @stderr
%71 = sext i32 %70 to i64
%72 = inttoptr i64 %71 to i32*
%73 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %73)
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %62
%77 = load i32*, i32** %12
%78 = call i32 (i32*, i8*, ...) @fprintf(i32* %77, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%79 = getelementptr inbounds [192000 x i8], [192000 x i8]* %10, i64 0, i64 0
%80 = load i32*, i32** %12
%81 = call i32 @fwrite(i8* %79, i32 1, i32 192000, i32* %80)
%82 = load i32*, i32** %12
%83 = call i32 @fclose(i32* %82)
br label %54
84: ; preds = %61
ret i32 0
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@EOF = global i32 0
@optind = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"can't open %s\0A\00"
@.str.3 = [10 x i8] c"c%02d.ppm\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [17 x i8] c"can't create %s\0A\00"
@.str.6 = [16 x i8] c"P6\0A320 200\0A255\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [192000 x i8]
%4 = alloca [1000 x i8]
%5 = getelementptr inbounds [192000 x i8], [192000 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %15, label %10
10: ; preds = %2, %10
%11 = tail call i32 (...) @usage()
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %10
15: ; preds = %10, %2
%16 = load i32, i32* @optind
%17 = icmp slt i32 %16, %0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = tail call i32 (...) @usage()
%20 = load i32, i32* @optind
br label %21
21: ; preds = %18, %15
%22 = phi i32 [ %20, %18 ], [ %16, %15 ]
%23 = add nsw i32 %22, 1
store i32 %23, i32* @optind
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = icmp eq i32 %23, %0
br i1 %27, label %30, label %28
28: ; preds = %21
%29 = tail call i32 (...) @usage()
br label %30
30: ; preds = %28, %21
%31 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = call i64 @read_img_frame(i32* %31, i8* %5)
%35 = icmp slt i64 %34, 0
br i1 %35, label %60, label %42
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = sext i32 %37 to i64
%39 = inttoptr i64 %38 to i32*
%40 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %33, %53
%43 = phi i32 [ %57, %53 ], [ 1, %33 ]
%44 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %53
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = sext i32 %48 to i64
%50 = inttoptr i64 %49 to i32*
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %42
%54 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i64 15, i64 1, i32* %45)
%55 = call i32 @fwrite(i8* %5, i32 1, i32 192000, i32* %45)
%56 = call i32 @fclose(i32* %45)
%57 = add nuw nsw i32 %43, 1
%58 = call i64 @read_img_frame(i32* %31, i8* %5)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %42
60: ; preds = %53, %33
ret i32 0
}