#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_CUR;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, unsigned char,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int byte_read;
  int first_found;
  FILE *file_pes;
  unsigned char pes_header[4];
  unsigned char byte;
  if (argc > 1) {
    file_pes = fopen(argv[1], "rb");
  } else {
    fprintf(stderr, "Usage: 'pes2txt filename.pes > txt_units'\n");
    return 2;
  }
  if (file_pes == 0) {
    fprintf(stderr, "Can't find file %s\n", argv[1]);
    return 2;
  }
  first_found = 0;
  byte_read = fread(pes_header, 1, 4, file_pes);
  while (byte_read) {
    if ((pes_header[0] == 0x00) && (pes_header[1] == 0x00) &&
        (pes_header[2] == 0x01) && (pes_header[3] == 0xBD)) {
      first_found = 1;
      fseek(file_pes, 4, SEEK_CUR);
      fread(&byte, 1, 1, file_pes);
      fseek(file_pes, byte + 1, SEEK_CUR);
      byte_read = fread(pes_header, 1, 4, file_pes);
    } else {
      if (first_found) {
        fwrite(pes_header, 1, 1, stdout);
      }
      pes_header[0] = pes_header[1];
      pes_header[1] = pes_header[2];
      pes_header[2] = pes_header[3];
      byte_read = fread(pes_header + 3, 1, 1, file_pes);
    }
  }
  fwrite(pes_header, 1, 3, stdout);
  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   $0x1,-0x8(%rbp)
jle    118d <main+0x3d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    11b0 <main+0x60>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    132c <main+0x1dc>
cmpq   $0x0,-0x20(%rbp)
jne    11e6 <main+0x96>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    132c <main+0x1dc>
movl   $0x0,-0x18(%rbp)
lea    -0x24(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1309 <main+0x1b9>
movzbl -0x24(%rbp),%eax
cmp    $0x0,%eax
jne    12b4 <main+0x164>
movzbl -0x23(%rbp),%eax
cmp    $0x0,%eax
jne    12b4 <main+0x164>
movzbl -0x22(%rbp),%eax
cmp    $0x1,%eax
jne    12b4 <main+0x164>
movzbl -0x21(%rbp),%eax
cmp    $0xbd,%eax
jne    12b4 <main+0x164>
movl   $0x1,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d8f(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1050 <fseek@plt>
mov    -0x20(%rbp),%rcx
lea    -0x25(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
movzbl -0x25(%rbp),%eax
add    $0x1,%eax
mov    0x2d5d(%rip),%rcx
mov    (%rcx),%edx
movzbl %al,%esi
call   1050 <fseek@plt>
lea    -0x24(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
jmp    1304 <main+0x1b4>
cmpl   $0x0,-0x18(%rbp)
je     12d7 <main+0x187>
lea    -0x24(%rbp),%rdi
mov    0x2d07(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x23(%rbp),%al
mov    %al,-0x24(%rbp)
mov    -0x22(%rbp),%al
mov    %al,-0x23(%rbp)
mov    -0x21(%rbp),%al
mov    %al,-0x22(%rbp)
lea    -0x24(%rbp),%rdi
add    $0x3,%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
jmp    1207 <main+0xb7>
lea    -0x24(%rbp),%rdi
mov    0x2cbc(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x3,%edx
call   1070 <fwrite@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   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%edi
jl     1292 <main+0x142>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12cc <main+0x17c>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     12ab <main+0x15b>
xor    %ebp,%ebp
lea    0xb(%rsp),%r14
mov    0x2e35(%rip),%r13
lea    0xf(%rsp),%r15
lea    0x8(%rsp),%r12
jmp    121e <main+0xce>
nop
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1050 <fseek@plt>
mov    $0x1,%ebp
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
movzbl 0xf(%rsp),%eax
add    $0x1,%al
mov    0x0(%r13),%edx
movzbl %al,%esi
mov    %rbx,%rdi
call   1050 <fseek@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     12ab <main+0x15b>
movd   0x8(%rsp),%xmm0
movd   %xmm0,%eax
cmp    $0xbd010000,%eax
je     11c0 <main+0x70>
movdqa %xmm0,0x10(%rsp)
test   %ebp,%ebp
je     1265 <main+0x115>
mov    0x2d90(%rip),%rax
mov    (%rax),%ecx
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
movzbl 0x9(%rsp),%eax
movzbl 0xa(%rsp),%ecx
movzbl 0xb(%rsp),%edx
jmp    1274 <main+0x124>
movzbl 0x11(%rsp),%eax
movzbl 0x12(%rsp),%ecx
movzbl 0x13(%rsp),%edx
mov    %al,0x8(%rsp)
mov    %cl,0x9(%rsp)
mov    %dl,0xa(%rsp)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
jmp    120e <main+0xbe>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0xd61(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    12e7 <main+0x197>
mov    0x2d1e(%rip),%rax
mov    (%rax),%ecx
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
call   1070 <fwrite@plt>
xor    %eax,%eax
jmp    12ec <main+0x19c>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xd4e(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x2,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"Usage: 'pes2txt filename.pes > txt_units'\0A\00"
@.str.2 = [20 x i8] c"Can't find file %s\0A\00"
@SEEK_CUR = global i32 0
@stdout = global i32 0
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 [4 x i8]
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %8
br label %21
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %99
21: ; preds = %13
%22 = load i32*, i32** %8
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %28)
store i32 2, i32* %3
br label %99
30: ; preds = %21
store i32 0, i32* %7
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%32 = load i32*, i32** %8
%33 = call i32 @fread(i8* %31, i32 1, i32 4, i32* %32)
store i32 %33, i32* %6
br label %34
34: ; preds = %94, %30
%35 = load i32, i32* %6
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %95
37: ; preds = %34
%38 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %73
42: ; preds = %37
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 1
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %73
47: ; preds = %42
%48 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 2
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = icmp eq i32 %50, 1
br i1 %51, label %52, label %73
52: ; preds = %47
%53 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = icmp eq i32 %55, 189
br i1 %56, label %57, label %73
57: ; preds = %52
store i32 1, i32* %7
%58 = load i32*, i32** %8
%59 = load i32, i32* @SEEK_CUR
%60 = call i32 @fseek(i32* %58, i8 zeroext 4, i32 %59)
%61 = load i32*, i32** %8
%62 = call i32 @fread(i8* %10, i32 1, i32 1, i32* %61)
%63 = load i32*, i32** %8
%64 = load i8, i8* %10
%65 = zext i8 %64 to i32
%66 = add nsw i32 %65, 1
%67 = trunc i32 %66 to i8
%68 = load i32, i32* @SEEK_CUR
%69 = call i32 @fseek(i32* %63, i8 zeroext %67, i32 %68)
%70 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%71 = load i32*, i32** %8
%72 = call i32 @fread(i8* %70, i32 1, i32 4, i32* %71)
store i32 %72, i32* %6
br label %94
73: ; preds = %52, %47, %42, %37
%74 = load i32, i32* %7
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %80
76: ; preds = %73
%77 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%78 = load i32, i32* @stdout
%79 = call i32 @fwrite(i8* %77, i32 1, i32 1, i32 %78)
br label %80
80: ; preds = %76, %73
%81 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 1
%82 = load i8, i8* %81
%83 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
store i8 %82, i8* %83
%84 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 2
%85 = load i8, i8* %84
%86 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 1
store i8 %85, i8* %86
%87 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
%88 = load i8, i8* %87
%89 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 2
store i8 %88, i8* %89
%90 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%91 = getelementptr inbounds i8, i8* %90, i64 3
%92 = load i32*, i32** %8
%93 = call i32 @fread(i8* %91, i32 1, i32 1, i32* %92)
store i32 %93, i32* %6
br label %94
94: ; preds = %80, %57
br label %34
95: ; preds = %34
%96 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%97 = load i32, i32* @stdout
%98 = call i32 @fwrite(i8* %96, i32 1, i32 3, i32 %97)
store i32 0, i32* %3
br label %99
99: ; preds = %95, %24, %18
%100 = load i32, i32* %3
ret i32 %100
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"Usage: 'pes2txt filename.pes > txt_units'\0A\00"
@.str.2 = [20 x i8] c"Can't find file %s\0A\00"
@SEEK_CUR = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca <4 x i8>
%4 = alloca i8
%5 = getelementptr inbounds <4 x i8>, <4 x i8>* %3, i64 0, i64 0
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %64
15: ; preds = %7
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %8
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %64
19: ; preds = %7
%20 = call i32 @fread(i8* %5, i32 1, i32 4, i32* %10)
%21 = icmp eq i32 %20, 0
br i1 %21, label %61, label %22
22: ; preds = %19
%23 = getelementptr inbounds <4 x i8>, <4 x i8>* %3, i64 0, i64 1
%24 = getelementptr inbounds <4 x i8>, <4 x i8>* %3, i64 0, i64 2
%25 = getelementptr inbounds <4 x i8>, <4 x i8>* %3, i64 0, i64 3
br label %26
26: ; preds = %22, %57
%27 = phi i32 [ 0, %22 ], [ %59, %57 ]
%28 = load <4 x i8>, <4 x i8>* %3
%29 = freeze <4 x i8> %28
%30 = bitcast <4 x i8> %29 to i32
%31 = icmp eq i32 %30, -1124007936
br i1 %31, label %32, label %41
32: ; preds = %26
%33 = load i32, i32* @SEEK_CUR
%34 = call i32 @fseek(i32* %10, i8 zeroext 4, i32 %33)
%35 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %10)
%36 = load i8, i8* %4
%37 = add i8 %36, 1
%38 = load i32, i32* @SEEK_CUR
%39 = call i32 @fseek(i32* %10, i8 zeroext %37, i32 %38)
%40 = call i32 @fread(i8* %5, i32 1, i32 4, i32* %10)
br label %57
41: ; preds = %26
%42 = icmp eq i32 %27, 0
%43 = extractelement <4 x i8> %29, i64 1
%44 = extractelement <4 x i8> %29, i64 2
%45 = extractelement <4 x i8> %29, i64 3
br i1 %42, label %52, label %46
46: ; preds = %41
%47 = load i32, i32* @stdout
%48 = call i32 @fwrite(i8* %5, i32 1, i32 1, i32 %47)
%49 = load i8, i8* %23
%50 = load i8, i8* %24
%51 = load i8, i8* %25
br label %52
52: ; preds = %46, %41
%53 = phi i8 [ %51, %46 ], [ %45, %41 ]
%54 = phi i8 [ %50, %46 ], [ %44, %41 ]
%55 = phi i8 [ %49, %46 ], [ %43, %41 ]
store i8 %55, i8* %5
store i8 %54, i8* %23
store i8 %53, i8* %24
%56 = call i32 @fread(i8* %25, i32 1, i32 1, i32* %10)
br label %57
57: ; preds = %52, %32
%58 = phi i32 [ %40, %32 ], [ %56, %52 ]
%59 = phi i32 [ 1, %32 ], [ %27, %52 ]
%60 = icmp eq i32 %58, 0
br i1 %60, label %61, label %26
61: ; preds = %57, %19
%62 = load i32, i32* @stdout
%63 = call i32 @fwrite(i8* %5, i32 1, i32 3, i32 %62)
br label %64
64: ; preds = %61, %15, %12
%65 = phi i32 [ 2, %15 ], [ 0, %61 ], [ 2, %12 ]
ret i32 %65
}