#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ mp2_920_decode_mpeg(unsigned char *, size_t);
int /*<<< orphan*/ mp2_920_init();
int /*<<< orphan*/ mp2_920_shutdown();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc == 2) {
    FILE *F = fopen(argv[1], "rb");
    if (F) {
      unsigned char buf[4096];
      mp2_920_init();
      for (;;) {
        size_t uBytesRead = fread(buf, 1, sizeof(buf), F);
        mp2_920_decode_mpeg(buf, uBytesRead);
        if (uBytesRead < sizeof(buf)) {
          break;
        }
      }
      fclose(F);
      mp2_920_shutdown();
    } else {
      printf("File %s could not be opened\n", argv[1]);
    }
  } else {
    printf("usage: %s <mpeg stream name>\n", argv[0]);
  }
  printf("Main returning\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    123c <main+0xcc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1221 <main+0xb1>
mov    $0x0,%al
call   1040 <mp2_920_init@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,-0x1028(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x1028(%rbp),%rsi
call   1080 <mp2_920_decode_mpeg@plt>
cmpq   $0x1000,-0x1028(%rbp)
jae    1207 <main+0x97>
jmp    120c <main+0x9c>
jmp    11bd <main+0x4d>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x0,%al
call   1070 <mp2_920_shutdown@plt>
jmp    1237 <main+0xc7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1251 <main+0xe1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11fd <main+0x7d>
mov    0x8(%rbx),%rdi
lea    0xe61(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1209 <main+0x89>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <mp2_920_init@plt>
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1090 <mp2_920_decode_mpeg@plt>
cmp    $0xfff,%rbx
ja     11c0 <main+0x40>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
call   1080 <mp2_920_shutdown@plt>
jmp    121b <main+0x9b>
mov    (%rbx),%rsi
lea    0xe19(%rip),%rdi
jmp    1214 <main+0x94>
mov    0x8(%rbx),%rsi
lea    0xdef(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe1c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [29 x i8] c"File %s could not be opened\0A\00"
@.str.2 = [30 x i8] c"usage: %s <mpeg stream name>\0A\00"
@.str.3 = [16 x i8] c"Main returning\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [4096 x i8]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %41
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %35
18: ; preds = %11
%19 = call i32 (...) @mp2_920_init()
br label %20
20: ; preds = %30, %18
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i64 @fread(i8* %21, i32 1, i32 4096, i32* %22)
store i64 %23, i64* %8
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%25 = load i64, i64* %8
%26 = call i32 @mp2_920_decode_mpeg(i8* %24, i64 %25)
%27 = load i64, i64* %8
%28 = icmp ult i64 %27, 4096
br i1 %28, label %29, label %30
29: ; preds = %20
br label %31
30: ; preds = %20
br label %20
31: ; preds = %29
%32 = load i32*, i32** %6
%33 = call i32 @fclose(i32* %32)
%34 = call i32 (...) @mp2_920_shutdown()
br label %40
35: ; preds = %11
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %35, %31
br label %46
41: ; preds = %2
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %41, %40
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [29 x i8] c"File %s could not be opened\0A\00"
@.str.2 = [30 x i8] c"usage: %s <mpeg stream name>\0A\00"
@str = [15 x i8] c"Main returning\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %23
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %20, label %10
10: ; preds = %5
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%12 = tail call i32 (...) @mp2_920_init()
br label %13
13: ; preds = %13, %10
%14 = call i64 @fread(i8* %11, i32 1, i32 4096, i32* %8)
%15 = call i32 @mp2_920_decode_mpeg(i8* %11, i64 %14)
%16 = icmp ult i64 %14, 4096
br i1 %16, label %17, label %13
17: ; preds = %13
%18 = call i32 @fclose(i32* %8)
%19 = call i32 (...) @mp2_920_shutdown()
br label %26
20: ; preds = %5
%21 = load i8*, i8** %6
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %26
23: ; preds = %2
%24 = load i8*, i8** %1
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %17, %20, %23
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
ret i32 0
}