#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*/ dump(int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char *);
char *strerror(int);
int main(int argc, char *argv[]) {
  FILE *f;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <avi>\n", argv[0]);
    exit(1);
  }
  if (strcmp(argv[argc - 1], "-") == 0) {
    dump(stdin);
    return 0;
  }
  f = fopen(argv[argc - 1], "rb");
  if (!f) {
    fprintf(stderr, "Could not open '%s': %s\n", argv[argc - 1],
            strerror(errno));
    exit(-errno);
  }
  dump(f);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b8 <main+0x48>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe41(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11fa <main+0x8a>
mov    0x2e02(%rip),%rax
mov    (%rax),%rdi
call   1040 <dump@plt>
movl   $0x0,-0x4(%rbp)
jmp    1296 <main+0x126>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe01(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    127d <main+0x10d>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
mov    0x2d5a(%rip),%rax
sub    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <dump@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11da <main+0x6a>
mov    0x8(%r14),%rdi
lea    0xe87(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11be <main+0x4e>
mov    0x8(%r14),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11fe <main+0x8e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <dump@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11cd <main+0x5d>
mov    0x2e23(%rip),%rax
mov    (%rax),%rdi
call   1040 <dump@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe13(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r14),%r14
mov    0x2dbe(%rip),%r15
mov    (%r15),%edi
call   1090 <strerror@plt>
lea    0xdf5(%rip),%rsi
xor    %ebp,%ebp
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
sub    (%r15),%ebp
mov    %ebp,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"Usage: %s <avi>\0A\00"
@.str.1 = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [25 x i8] c"Could not open '%s': %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %17, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = load i32*, i32** @stdin
%27 = call i32 @dump(i32* %26)
store i32 0, i32* %3
br label %57
28: ; preds = %16
%29 = load i8**, i8*** %5
%30 = load i32, i32* %4
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %29, i64 %32
%34 = load i8*, i8** %33
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %35, i32** %6
%36 = load i32*, i32** %6
%37 = icmp ne i32* %36, null
br i1 %37, label %52, label %38
38: ; preds = %28
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = load i32, i32* %4
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %40, i64 %43
%45 = load i8*, i8** %44
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %45, i8* %47)
%49 = load i32, i32* @errno
%50 = sub nsw i32 0, %49
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %28
%53 = load i32*, i32** %6
%54 = call i32 @dump(i32* %53)
%55 = load i32*, i32** %6
%56 = call i32 @fclose(i32* %55)
store i32 0, i32* %3
br label %57
57: ; preds = %52, %25
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"Usage: %s <avi>\0A\00"
@.str.1 = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [25 x i8] c"Could not open '%s': %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32*, i32** @stdin
%16 = tail call i32 @dump(i32* %15)
br label %33
17: ; preds = %9
%18 = load i8*, i8** %10
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %10
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %23, i8* %25)
%27 = load i32, i32* @errno
%28 = sub nsw i32 0, %27
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %17
%31 = tail call i32 @dump(i32* %19)
%32 = tail call i32 @fclose(i32* %19)
br label %33
33: ; preds = %30, %14
ret i32 0
}