#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 */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ seq_end;
typedef int /*<<< orphan*/ pes_header;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ VIDEO_CLEAR_BUFFER;
int /*<<< orphan*/ VIDEO_CONTINUE;
int /*<<< orphan*/ VIDEO_PLAY;
int /*<<< orphan*/ VIDEO_SELECT_SOURCE;
int /*<<< orphan*/ VIDEO_SET_STREAMTYPE;
int VIDEO_SOURCE_DEMUX;
int VIDEO_SOURCE_MEMORY;
int /*<<< orphan*/ VIDEO_STOP;
int /*<<< orphan*/ c(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fstat(int, struct stat *);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, unsigned char *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write_all(int, unsigned char *, int);
int main(int argc, char **argv) {
  struct stat s;
  if (argc != 2) {
    printf("usage: %s <iframe>\n", *argv);
    return 3;
  }
  int f = open(argv[1], O_RDONLY);
  if (f < 0) {
    perror(argv[1]);
    return 4;
  }
  fstat(f, &s);
  int fd = open("/dev/dvb/adapter0/video0", O_WRONLY);
  if (fd <= 0) {
    perror("/dev/dvb/adapter0/video0");
    return 2;
  } else if (fork() != 0)
    return 0;
  else {
    size_t pos = 0;
    int seq_end_avail = 0;
    unsigned char pes_header[] = {0x0,  0x0, 0x1,  0xe0, 0x00, 0x00, 0x80,
                                  0x80, 0x5, 0x21, 0x0,  0x1,  0x0,  0x1};
    unsigned char seq_end[] = {0x00, 0x00, 0x01, 0xB7};
    unsigned char iframe[s.st_size];
    unsigned char stuffing[8192];
    memset(stuffing, 0, 8192);
    read(f, iframe, s.st_size);
    if (iframe[0] == 0x00 && iframe[1] == 0x00 && iframe[2] == 0x00 &&
        iframe[3] == 0x01 && (iframe[4] & 0x0f) == 0x07)
      ioctl(fd, VIDEO_SET_STREAMTYPE, 1);
    else
      ioctl(fd, VIDEO_SET_STREAMTYPE, 0);
    c(ioctl(fd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY));
    c(ioctl(fd, VIDEO_PLAY));
    c(ioctl(fd, VIDEO_CONTINUE));
    c(ioctl(fd, VIDEO_CLEAR_BUFFER));
    while (pos <= (s.st_size - 4) &&
           !(seq_end_avail = (!iframe[pos] && !iframe[pos + 1] &&
                              iframe[pos + 2] == 1 && iframe[pos + 3] == 0xB7)))
      ++pos;
    if ((iframe[3] >> 4) != 0xE) {
      write_all(fd, pes_header, sizeof(pes_header));
    } else {
      iframe[4] = iframe[5] = 0x00;
    }
    write_all(fd, iframe, s.st_size);
    if (!seq_end_avail)
      write_all(fd, seq_end, sizeof(seq_end));
    write_all(fd, stuffing, 8192);
    usleep(150000);
    c(ioctl(fd, VIDEO_STOP, 0));
    c(ioctl(fd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_DEMUX));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2070,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    15c8 <main+0x418>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    122e <main+0x7e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <perror@plt>
movl   $0x4,-0x4(%rbp)
jmp    15c8 <main+0x418>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10b0 <fstat@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
lea    0xdca(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     1274 <main+0xc4>
lea    0xdb1(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    15c8 <main+0x418>
mov    $0x0,%al
call   10c0 <fork@plt>
cmp    $0x0,%rax
je     1291 <main+0xe1>
movl   $0x0,-0x4(%rbp)
jmp    15c8 <main+0x418>
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movabs $0x100010021058080,%rax
mov    %rax,-0x3a(%rbp)
movabs $0x80800000e0010000,%rax
mov    %rax,-0x40(%rbp)
movl   $0xb7010000,-0x44(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x2068(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
lea    -0x2060(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
mov    -0x2068(%rbp),%rsi
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
call   1060 <read@plt>
mov    -0x2068(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    1394 <main+0x1e4>
mov    -0x2068(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1394 <main+0x1e4>
mov    -0x2068(%rbp),%rax
movzbl 0x2(%rax),%eax
cmp    $0x0,%eax
jne    1394 <main+0x1e4>
mov    -0x2068(%rbp),%rax
movzbl 0x3(%rax),%eax
cmp    $0x1,%eax
jne    1394 <main+0x1e4>
mov    -0x2068(%rbp),%rax
movzbl 0x4(%rax),%eax
and    $0xf,%eax
cmp    $0x7,%eax
jne    1394 <main+0x1e4>
mov    -0x20(%rbp),%edi
mov    0x2c77(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
mov    $0x0,%al
call   1050 <ioctl@plt>
jmp    13a9 <main+0x1f9>
mov    -0x20(%rbp),%edi
mov    0x2c5a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    -0x20(%rbp),%edi
mov    0x2bdd(%rip),%rax
mov    (%rax),%esi
mov    0x2bec(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x20(%rbp),%edi
mov    0x2c0a(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x20(%rbp),%edi
mov    0x2bc0(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x20(%rbp),%edi
mov    0x2bb6(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%eax
sub    $0x4,%eax
movslq %eax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x2069(%rbp)
ja     14cb <main+0x31b>
mov    -0x2068(%rbp),%rcx
mov    -0x28(%rbp),%rdx
xor    %eax,%eax
cmpb   $0x0,(%rcx,%rdx,1)
mov    %al,-0x206a(%rbp)
jne    14b2 <main+0x302>
mov    -0x2068(%rbp),%rcx
mov    -0x28(%rbp),%rdx
xor    %eax,%eax
cmpb   $0x0,0x1(%rcx,%rdx,1)
mov    %al,-0x206a(%rbp)
jne    14b2 <main+0x302>
mov    -0x2068(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl 0x2(%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x206a(%rbp)
jne    14b2 <main+0x302>
mov    -0x2068(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl 0x3(%rax,%rcx,1),%eax
cmp    $0xb7,%eax
sete   %al
mov    %al,-0x206a(%rbp)
mov    -0x206a(%rbp),%al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x2c(%rbp)
xor    $0xff,%al
mov    %al,-0x2069(%rbp)
mov    -0x2069(%rbp),%al
test   $0x1,%al
jne    14de <main+0x32e>
jmp    14ef <main+0x33f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    141a <main+0x26a>
mov    -0x2068(%rbp),%rax
movzbl 0x3(%rax),%eax
sar    $0x4,%eax
cmp    $0xe,%eax
je     151c <main+0x36c>
mov    -0x20(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xe,%edx
call   1070 <write_all@plt>
jmp    152b <main+0x37b>
mov    -0x2068(%rbp),%rax
movb   $0x0,0x5(%rax)
movb   $0x0,0x4(%rax)
mov    -0x2068(%rbp),%rsi
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%edx
call   1070 <write_all@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    1558 <main+0x3a8>
mov    -0x20(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
call   1070 <write_all@plt>
mov    -0x20(%rbp),%edi
lea    -0x2060(%rbp),%rsi
mov    $0x2000,%edx
call   1070 <write_all@plt>
mov    $0x249f0,%edi
call   10d0 <usleep@plt>
mov    -0x20(%rbp),%edi
mov    0x2a70(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x20(%rbp),%edi
mov    0x29f4(%rip),%rax
mov    (%rax),%esi
mov    0x2a2b(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
jmp    15c1 <main+0x411>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2038,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1395 <main+0x1e5>
mov    0x8(%rbx),%rdi
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     146d <main+0x2bd>
mov    %eax,%r13d
lea    -0x30(%rbp),%rsi
mov    %eax,%edi
call   10b0 <fstat@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
lea    0xe0c(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
jle    147d <main+0x2cd>
mov    %eax,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jne    145c <main+0x2ac>
mov    %r14d,-0x34(%rbp)
mov    %rsp,-0x48(%rbp)
movabs $0x100010021058080,%rax
mov    %rax,-0x52(%rbp)
movabs $0x80800000e0010000,%rax
mov    %rax,-0x58(%rbp)
movl   $0xb7010000,-0x38(%rbp)
mov    -0x30(%rbp),%r15d
movslq %r15d,%r12
mov    %rsp,%r14
mov    %r15,-0x40(%rbp)
add    $0xf,%r15
and    $0xfffffffffffffff0,%r15
mov    %r14,%rbx
sub    %r15,%rbx
mov    %rbx,%rsp
neg    %r15
lea    -0x2060(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1060 <read@plt>
mov    (%r14,%r15,1),%r13b
test   %r13b,%r13b
jne    12c1 <main+0x111>
cmpb   $0x0,0x1(%rbx)
jne    12c1 <main+0x111>
cmpb   $0x0,0x2(%rbx)
jne    12c1 <main+0x111>
cmpb   $0x1,0x3(%rbx)
jne    12c1 <main+0x111>
mov    0x4(%rbx),%al
and    $0xf,%al
mov    $0x1,%edx
cmp    $0x7,%al
je     12c3 <main+0x113>
xor    %edx,%edx
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
mov    -0x34(%rbp),%r14d
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <ioctl@plt>
mov    0x2caf(%rip),%r15
mov    (%r15),%esi
mov    0x2cbd(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    0x2c91(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    0x2c87(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
add    $0xfffffffffffffffc,%r12
mov    $0x1,%eax
test   %r13b,%r13b
jne    1380 <main+0x1d0>
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,(%rbx,%rax,1)
jne    1380 <main+0x1d0>
cmpb   $0x1,0x1(%rbx,%rax,1)
jne    1380 <main+0x1d0>
cmpb   $0xb7,0x2(%rbx,%rax,1)
je     1490 <main+0x2e0>
nopl   0x0(%rax,%rax,1)
cmp    %r12,%rax
ja     13ae <main+0x1fe>
movzbl (%rbx,%rax,1),%r13d
add    $0x1,%rax
test   %r13b,%r13b
jne    1380 <main+0x1d0>
jmp    1360 <main+0x1b0>
mov    (%rbx),%rsi
lea    0xc61(%rip),%rdi
call   1030 <printf@plt>
mov    $0x3,%ebx
jmp    145c <main+0x2ac>
mov    %r15,%r13
mov    $0x1,%r12b
mov    -0x48(%rbp),%r15
mov    0x3(%rbx),%al
and    $0xf0,%al
cmp    $0xe0,%al
jne    13c9 <main+0x219>
movw   $0x0,0x4(%rbx)
jmp    13da <main+0x22a>
lea    -0x58(%rbp),%rsi
mov    %r14d,%edi
mov    $0xe,%edx
call   1070 <write_all@plt>
mov    -0x40(%rbp),%rdx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1070 <write_all@plt>
test   %r12b,%r12b
je     13ff <main+0x24f>
lea    -0x38(%rbp),%rsi
mov    %r14d,%edi
mov    $0x4,%edx
call   1070 <write_all@plt>
lea    -0x2060(%rbp),%rsi
mov    %r14d,%edi
mov    $0x2000,%edx
call   1070 <write_all@plt>
mov    $0x249f0,%edi
call   10d0 <usleep@plt>
mov    0x2bcc(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %r14d,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    0x0(%r13),%esi
mov    0x2b8a(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    %r15,%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rdi
call   10a0 <perror@plt>
mov    $0x4,%ebx
jmp    145c <main+0x2ac>
lea    0xb90(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%ebx
jmp    145c <main+0x2ac>
mov    %r15,%r13
xor    %r12d,%r12d
jmp    13b4 <main+0x204>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [20 x i8] c"usage: %s <iframe>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"/dev/dvb/adapter0/video0\00"
@O_WRONLY = global i32 0
@__const.main.pes_header = [14 x i8] c"\00\00\01\E0\00\00\80\80\05!\00\01\00\01"
@__const.main.seq_end = [4 x i8] c"\00\00\01\B7"
@VIDEO_SET_STREAMTYPE = global i32 0
@VIDEO_SELECT_SOURCE = global i32 0
@VIDEO_SOURCE_MEMORY = global i32 0
@VIDEO_PLAY = global i32 0
@VIDEO_CONTINUE = global i32 0
@VIDEO_CLEAR_BUFFER = global i32 0
@VIDEO_STOP = global i32 0
@VIDEO_SOURCE_DEMUX = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca [14 x i8]
%12 = alloca [4 x i8]
%13 = alloca i8*
%14 = alloca i64
%15 = alloca [8192 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = load i8*, i8** %19
%21 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 3, i32* %3
br label %195
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* %25, i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %22
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @perror(i8* %33)
store i32 4, i32* %3
br label %195
35: ; preds = %22
%36 = load i32, i32* %7
%37 = call i32 @fstat(i32 %36, %struct.stat* %6)
%38 = load i32, i32* @O_WRONLY
%39 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %38)
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = icmp sle i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %35
%43 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %195
44: ; preds = %35
%45 = call i64 (...) @fork()
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %44
store i32 0, i32* %3
br label %195
48: ; preds = %44
store i64 0, i64* %9
store i32 0, i32* %10
%49 = bitcast [14 x i8]* %11 to i8*
%50 = bitcast [4 x i8]* %12 to i8*
%51 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%52 = load i32, i32* %51
%53 = zext i32 %52 to i64
%54 = call i8* @llvm.stacksave()
store i8* %54, i8** %13
%55 = alloca i8, i64 %53
store i64 %53, i64* %14
%56 = getelementptr inbounds [8192 x i8], [8192 x i8]* %15, i64 0, i64 0
%57 = call i32 @memset(i8* %56, i32 0, i32 8192)
%58 = load i32, i32* %7
%59 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i32 @read(i32 %58, i8* %55, i32 %60)
%62 = getelementptr inbounds i8, i8* %55, i64 0
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %91
66: ; preds = %48
%67 = getelementptr inbounds i8, i8* %55, i64 1
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %91
71: ; preds = %66
%72 = getelementptr inbounds i8, i8* %55, i64 2
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %91
76: ; preds = %71
%77 = getelementptr inbounds i8, i8* %55, i64 3
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
%80 = icmp eq i32 %79, 1
br i1 %80, label %81, label %91
81: ; preds = %76
%82 = getelementptr inbounds i8, i8* %55, i64 4
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = and i32 %84, 15
%86 = icmp eq i32 %85, 7
br i1 %86, label %87, label %91
87: ; preds = %81
%88 = load i32, i32* %8
%89 = load i32, i32* @VIDEO_SET_STREAMTYPE
%90 = call i32 (i32, i32, ...) @ioctl(i32 %88, i32 %89, i32 1)
br label %95
91: ; preds = %81, %76, %71, %66, %48
%92 = load i32, i32* %8
%93 = load i32, i32* @VIDEO_SET_STREAMTYPE
%94 = call i32 (i32, i32, ...) @ioctl(i32 %92, i32 %93, i32 0)
br label %95
95: ; preds = %91, %87
%96 = load i32, i32* %8
%97 = load i32, i32* @VIDEO_SELECT_SOURCE
%98 = load i32, i32* @VIDEO_SOURCE_MEMORY
%99 = call i32 (i32, i32, ...) @ioctl(i32 %96, i32 %97, i32 %98)
%100 = call i32 @c(i32 %99)
%101 = load i32, i32* %8
%102 = load i32, i32* @VIDEO_PLAY
%103 = call i32 (i32, i32, ...) @ioctl(i32 %101, i32 %102)
%104 = call i32 @c(i32 %103)
%105 = load i32, i32* %8
%106 = load i32, i32* @VIDEO_CONTINUE
%107 = call i32 (i32, i32, ...) @ioctl(i32 %105, i32 %106)
%108 = call i32 @c(i32 %107)
%109 = load i32, i32* %8
%110 = load i32, i32* @VIDEO_CLEAR_BUFFER
%111 = call i32 (i32, i32, ...) @ioctl(i32 %109, i32 %110)
%112 = call i32 @c(i32 %111)
br label %113
113: ; preds = %151, %95
%114 = load i64, i64* %9
%115 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%116 = load i32, i32* %115
%117 = sub nsw i32 %116, 4
%118 = sext i32 %117 to i64
%119 = icmp ule i64 %114, %118
br i1 %119, label %120, label %149
120: ; preds = %113
%121 = load i64, i64* %9
%122 = getelementptr inbounds i8, i8* %55, i64 %121
%123 = load i8, i8* %122
%124 = icmp ne i8 %123, 0
br i1 %124, label %145, label %125
125: ; preds = %120
%126 = load i64, i64* %9
%127 = add i64 %126, 1
%128 = getelementptr inbounds i8, i8* %55, i64 %127
%129 = load i8, i8* %128
%130 = icmp ne i8 %129, 0
br i1 %130, label %145, label %131
131: ; preds = %125
%132 = load i64, i64* %9
%133 = add i64 %132, 2
%134 = getelementptr inbounds i8, i8* %55, i64 %133
%135 = load i8, i8* %134
%136 = zext i8 %135 to i32
%137 = icmp eq i32 %136, 1
br i1 %137, label %138, label %145
138: ; preds = %131
%139 = load i64, i64* %9
%140 = add i64 %139, 3
%141 = getelementptr inbounds i8, i8* %55, i64 %140
%142 = load i8, i8* %141
%143 = zext i8 %142 to i32
%144 = icmp eq i32 %143, 183
br label %145
145: ; preds = %138, %131, %125, %120
%146 = phi i1 [ false, %131 ], [ false, %125 ], [ false, %120 ], [ %144, %138 ]
%147 = zext i1 %146 to i32
store i32 %147, i32* %10
%148 = xor i1 %146, true
br label %149
149: ; preds = %145, %113
%150 = phi i1 [ false, %113 ], [ %148, %145 ]
br i1 %150, label %151, label %154
151: ; preds = %149
%152 = load i64, i64* %9
%153 = add i64 %152, 1
store i64 %153, i64* %9
br label %113
154: ; preds = %149
%155 = getelementptr inbounds i8, i8* %55, i64 3
%156 = load i8, i8* %155
%157 = zext i8 %156 to i32
%158 = ashr i32 %157, 4
%159 = icmp ne i32 %158, 14
br i1 %159, label %160, label %164
160: ; preds = %154
%161 = load i32, i32* %8
%162 = getelementptr inbounds [14 x i8], [14 x i8]* %11, i64 0, i64 0
%163 = call i32 @write_all(i32 %161, i8* %162, i32 14)
br label %167
164: ; preds = %154
%165 = getelementptr inbounds i8, i8* %55, i64 5
store i8 0, i8* %165
%166 = getelementptr inbounds i8, i8* %55, i64 4
store i8 0, i8* %166
br label %167
167: ; preds = %164, %160
%168 = load i32, i32* %8
%169 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%170 = load i32, i32* %169
%171 = call i32 @write_all(i32 %168, i8* %55, i32 %170)
%172 = load i32, i32* %10
%173 = icmp ne i32 %172, 0
br i1 %173, label %178, label %174
174: ; preds = %167
%175 = load i32, i32* %8
%176 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
%177 = call i32 @write_all(i32 %175, i8* %176, i32 4)
br label %178
178: ; preds = %174, %167
%179 = load i32, i32* %8
%180 = getelementptr inbounds [8192 x i8], [8192 x i8]* %15, i64 0, i64 0
%181 = call i32 @write_all(i32 %179, i8* %180, i32 8192)
%182 = call i32 @usleep(i32 150000)
%183 = load i32, i32* %8
%184 = load i32, i32* @VIDEO_STOP
%185 = call i32 (i32, i32, ...) @ioctl(i32 %183, i32 %184, i32 0)
%186 = call i32 @c(i32 %185)
%187 = load i32, i32* %8
%188 = load i32, i32* @VIDEO_SELECT_SOURCE
%189 = load i32, i32* @VIDEO_SOURCE_DEMUX
%190 = call i32 (i32, i32, ...) @ioctl(i32 %187, i32 %188, i32 %189)
%191 = call i32 @c(i32 %190)
%192 = load i8*, i8** %13
br label %193
193: ; preds = %178
br label %194
194: ; preds = %193
store i32 0, i32* %3
br label %195
195: ; preds = %194, %47, %42, %30, %18
%196 = load i32, i32* %3
ret i32 %196
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [20 x i8] c"usage: %s <iframe>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"/dev/dvb/adapter0/video0\00"
@O_WRONLY = global i32 0
@__const.main.pes_header = [14 x i8] c"\00\00\01\E0\00\00\80\80\05!\00\01\00\01"
@VIDEO_SET_STREAMTYPE = global i32 0
@VIDEO_SELECT_SOURCE = global i32 0
@VIDEO_SOURCE_MEMORY = global i32 0
@VIDEO_PLAY = global i32 0
@VIDEO_CONTINUE = global i32 0
@VIDEO_CLEAR_BUFFER = global i32 0
@VIDEO_STOP = global i32 0
@VIDEO_SOURCE_DEMUX = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca [14 x i8]
%5 = alloca i32
%6 = alloca [8192 x i8]
%7 = bitcast %struct.stat* %3 to i8*
%8 = icmp eq i32 %0, 2
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %130
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i8*, i8** %13
%20 = tail call i32 @perror(i8* %19)
br label %130
21: ; preds = %12
%22 = call i32 @fstat(i32 %16, %struct.stat* %3)
%23 = load i32, i32* @O_WRONLY
%24 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = icmp slt i32 %24, 1
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %130
28: ; preds = %21
%29 = tail call i64 (...) @fork()
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %130
31: ; preds = %28
%32 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%33 = bitcast i32* %5 to i8*
store i32 -1224671232, i32* %5
%34 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%35 = load i32, i32* %34
%36 = zext i32 %35 to i64
%37 = tail call i8* @llvm.stacksave()
%38 = alloca i8, i64 %36
%39 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%40 = call i32 @memset(i8* %39, i32 0, i32 8192)
%41 = call i32 @read(i32 %16, i8* %38, i32 %35)
%42 = load i8, i8* %38
%43 = icmp eq i8 %42, 0
br i1 %43, label %44, label %61
44: ; preds = %31
%45 = getelementptr inbounds i8, i8* %38, i64 1
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 0
br i1 %47, label %48, label %61
48: ; preds = %44
%49 = getelementptr inbounds i8, i8* %38, i64 2
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 0
br i1 %51, label %52, label %61
52: ; preds = %48
%53 = getelementptr inbounds i8, i8* %38, i64 3
%54 = load i8, i8* %53
%55 = icmp eq i8 %54, 1
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = getelementptr inbounds i8, i8* %38, i64 4
%58 = load i8, i8* %57
%59 = and i8 %58, 15
%60 = icmp eq i8 %59, 7
br i1 %60, label %62, label %61
61: ; preds = %56, %52, %48, %44, %31
br label %62
62: ; preds = %56, %61
%63 = phi i32 [ 0, %61 ], [ 1, %56 ]
%64 = load i32, i32* @VIDEO_SET_STREAMTYPE
%65 = call i32 (i32, i32, ...) @ioctl(i32 %24, i32 %64, i32 %63)
%66 = load i32, i32* @VIDEO_SELECT_SOURCE
%67 = load i32, i32* @VIDEO_SOURCE_MEMORY
%68 = call i32 (i32, i32, ...) @ioctl(i32 %24, i32 %66, i32 %67)
%69 = call i32 @c(i32 %68)
%70 = load i32, i32* @VIDEO_PLAY
%71 = call i32 (i32, i32, ...) @ioctl(i32 %24, i32 %70)
%72 = call i32 @c(i32 %71)
%73 = load i32, i32* @VIDEO_CONTINUE
%74 = call i32 (i32, i32, ...) @ioctl(i32 %24, i32 %73)
%75 = call i32 @c(i32 %74)
%76 = load i32, i32* @VIDEO_CLEAR_BUFFER
%77 = call i32 (i32, i32, ...) @ioctl(i32 %24, i32 %76)
%78 = call i32 @c(i32 %77)
%79 = add nsw i32 %35, -4
%80 = sext i32 %79 to i64
br label %81
81: ; preds = %102, %62
%82 = phi i8 [ %42, %62 ], [ %104, %102 ]
%83 = phi i64 [ 0, %62 ], [ %85, %102 ]
%84 = icmp eq i8 %82, 0
%85 = add i64 %83, 1
br i1 %84, label %86, label %100
86: ; preds = %81
%87 = getelementptr inbounds i8, i8* %38, i64 %85
%88 = load i8, i8* %87
%89 = icmp eq i8 %88, 0
br i1 %89, label %90, label %100
90: ; preds = %86
%91 = add i64 %83, 2
%92 = getelementptr inbounds i8, i8* %38, i64 %91
%93 = load i8, i8* %92
%94 = icmp eq i8 %93, 1
br i1 %94, label %95, label %100
95: ; preds = %90
%96 = add i64 %83, 3
%97 = getelementptr inbounds i8, i8* %38, i64 %96
%98 = load i8, i8* %97
%99 = icmp eq i8 %98, -73
br i1 %99, label %105, label %100
100: ; preds = %81, %86, %90, %95
%101 = icmp ugt i64 %85, %80
br i1 %101, label %105, label %102
102: ; preds = %100
%103 = getelementptr inbounds i8, i8* %38, i64 %85
%104 = load i8, i8* %103
br label %81
105: ; preds = %100, %95
%106 = phi i1 [ true, %100 ], [ false, %95 ]
%107 = getelementptr inbounds i8, i8* %38, i64 3
%108 = load i8, i8* %107
%109 = and i8 %108, -16
%110 = icmp eq i8 %109, -32
br i1 %110, label %113, label %111
111: ; preds = %105
%112 = call i32 @write_all(i32 %24, i8* %32, i32 14)
br label %116
113: ; preds = %105
%114 = getelementptr inbounds i8, i8* %38, i64 5
store i8 0, i8* %114
%115 = getelementptr inbounds i8, i8* %38, i64 4
store i8 0, i8* %115
br label %116
116: ; preds = %113, %111
%117 = call i32 @write_all(i32 %24, i8* %38, i32 %35)
br i1 %106, label %118, label %120
118: ; preds = %116
%119 = call i32 @write_all(i32 %24, i8* %33, i32 4)
br label %120
120: ; preds = %118, %116
%121 = call i32 @write_all(i32 %24, i8* %39, i32 8192)
%122 = call i32 @usleep(i32 150000)
%123 = load i32, i32* @VIDEO_STOP
%124 = call i32 (i32, i32, ...) @ioctl(i32 %24, i32 %123, i32 0)
%125 = call i32 @c(i32 %124)
%126 = load i32, i32* @VIDEO_SELECT_SOURCE
%127 = load i32, i32* @VIDEO_SOURCE_DEMUX
%128 = call i32 (i32, i32, ...) @ioctl(i32 %24, i32 %126, i32 %127)
%129 = call i32 @c(i32 %128)
br label %130
130: ; preds = %18, %28, %120, %26, %9
%131 = phi i32 [ 3, %9 ], [ 4, %18 ], [ 2, %26 ], [ 0, %120 ], [ 0, %28 ]
ret i32 %131
}