#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 O_NONBLOCK;
int O_RDONLY;
int 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 /*<<< orphan*/ VIDEO_SOURCE_DEMUX;
int /*<<< orphan*/ 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);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, unsigned char *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(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 | O_NONBLOCK);
  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;
    int count = 7;
    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);
    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;
    while (count--) {
      if ((iframe[3] >> 4) != 0xE) {
        write(fd, pes_header, sizeof(pes_header));
        usleep(8000);
      } else {
        iframe[4] = iframe[5] = 0x00;
      }
      write(fd, iframe, s.st_size);
      usleep(8000);
    }
    if (!seq_end_avail)
      write(fd, seq_end, sizeof(seq_end));
    write(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   1040 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    1587 <main+0x3d7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dbf(%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    1587 <main+0x3d7>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10b0 <fstat@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
mov    0x2d86(%rip),%rax
or     (%rax),%esi
lea    0xdc1(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     127d <main+0xcd>
lea    0xda8(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1587 <main+0x3d7>
mov    $0x0,%al
call   10c0 <fork@plt>
cmp    $0x0,%rax
je     129a <main+0xea>
movl   $0x0,-0x4(%rbp)
jmp    1587 <main+0x3d7>
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x7,-0x30(%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   1050 <memset@plt>
mov    -0x2068(%rbp),%rsi
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
call   1070 <read@plt>
mov    -0x20(%rbp),%edi
mov    0x2ccd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    -0x20(%rbp),%edi
mov    0x2c48(%rip),%rax
mov    (%rax),%esi
mov    0x2c57(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x20(%rbp),%edi
mov    0x2c7d(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x20(%rbp),%edi
mov    0x2c2b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x20(%rbp),%edi
mov    0x2c21(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <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     1458 <main+0x2a8>
mov    -0x2068(%rbp),%rcx
mov    -0x28(%rbp),%rdx
xor    %eax,%eax
cmpb   $0x0,(%rcx,%rdx,1)
mov    %al,-0x206a(%rbp)
jne    143f <main+0x28f>
mov    -0x2068(%rbp),%rcx
mov    -0x28(%rbp),%rdx
xor    %eax,%eax
cmpb   $0x0,0x1(%rcx,%rdx,1)
mov    %al,-0x206a(%rbp)
jne    143f <main+0x28f>
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    143f <main+0x28f>
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    146b <main+0x2bb>
jmp    147c <main+0x2cc>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    13a7 <main+0x1f7>
jmp    1481 <main+0x2d1>
mov    -0x30(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x30(%rbp)
cmp    $0x0,%eax
je     14fc <main+0x34c>
mov    -0x2068(%rbp),%rax
movzbl 0x3(%rax),%eax
sar    $0x4,%eax
cmp    $0xe,%eax
je     14cc <main+0x31c>
mov    -0x20(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
jmp    14db <main+0x32b>
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   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
jmp    1481 <main+0x2d1>
cmpl   $0x0,-0x2c(%rbp)
jne    1517 <main+0x367>
mov    -0x20(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x20(%rbp),%edi
lea    -0x2060(%rbp),%rsi
mov    $0x2000,%edx
call   1030 <write@plt>
mov    $0x249f0,%edi
call   10d0 <usleep@plt>
mov    -0x20(%rbp),%edi
mov    0x2ab1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x20(%rbp),%edi
mov    0x2a2d(%rip),%rax
mov    (%rax),%esi
mov    0x2a64(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
jmp    1580 <main+0x3d0>
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    1364 <main+0x1b4>
mov    0x8(%rbx),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     15f6 <main+0x446>
mov    %eax,%r13d
lea    -0x50(%rbp),%rsi
mov    %eax,%edi
call   10b0 <fstat@plt>
mov    0x2d91(%rip),%rax
mov    0x2dca(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe03(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
jle    1606 <main+0x456>
mov    %eax,%r15d
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jne    15e5 <main+0x435>
mov    %rsp,-0x60(%rbp)
movabs $0x100010021058080,%rax
mov    %rax,-0x42(%rbp)
movabs $0x80800000e0010000,%rax
mov    %rax,-0x48(%rbp)
movl   $0xb7010000,-0x54(%rbp)
mov    -0x50(%rbp),%eax
movslq %eax,%rbx
mov    %rsp,%r12
mov    %rax,-0x30(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x2060(%rbp),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x2000,%edx
call   1050 <memset@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %ebx,%edx
call   1070 <read@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    0x2cd4(%rip),%r13
mov    0x0(%r13),%esi
mov    0x2ce1(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    0x2cb5(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    0x2cab(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
add    $0xfffffffffffffffc,%rbx
jmp    1339 <main+0x189>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %rbx,%r14
ja     137d <main+0x1cd>
cmpb   $0x0,(%r12,%r14,1)
jne    1330 <main+0x180>
cmpb   $0x0,0x1(%r12,%r14,1)
jne    1330 <main+0x180>
cmpb   $0x1,0x2(%r12,%r14,1)
jne    1330 <main+0x180>
cmpb   $0xb7,0x3(%r12,%r14,1)
jne    1330 <main+0x180>
mov    %r13,%r14
movl   $0x0,-0x34(%rbp)
jmp    1385 <main+0x1d5>
mov    (%rbx),%rsi
lea    0xc92(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3,%ebx
jmp    15e5 <main+0x435>
mov    %r13,%r14
mov    $0x1,%al
mov    %eax,-0x34(%rbp)
mov    -0x60(%rbp),%rbx
mov    0x3(%r12),%r13b
and    $0xf0,%r13b
cmp    $0xe0,%r13b
jne    13a2 <main+0x1f2>
movw   $0x0,0x4(%r12)
jmp    13bd <main+0x20d>
lea    -0x48(%rbp),%rsi
mov    %r15d,%edi
mov    $0xe,%edx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    -0x30(%rbp),%rdx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
cmp    $0xe0,%r13b
jne    13e6 <main+0x236>
movw   $0x0,0x4(%r12)
jmp    1401 <main+0x251>
lea    -0x48(%rbp),%rsi
mov    %r15d,%edi
mov    $0xe,%edx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    -0x30(%rbp),%rdx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
cmp    $0xe0,%r13b
jne    142a <main+0x27a>
movw   $0x0,0x4(%r12)
jmp    1445 <main+0x295>
lea    -0x48(%rbp),%rsi
mov    %r15d,%edi
mov    $0xe,%edx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    -0x30(%rbp),%rdx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
cmp    $0xe0,%r13b
jne    146e <main+0x2be>
movw   $0x0,0x4(%r12)
jmp    1489 <main+0x2d9>
lea    -0x48(%rbp),%rsi
mov    %r15d,%edi
mov    $0xe,%edx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    -0x30(%rbp),%rdx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
cmp    $0xe0,%r13b
jne    14b2 <main+0x302>
movw   $0x0,0x4(%r12)
jmp    14cd <main+0x31d>
lea    -0x48(%rbp),%rsi
mov    %r15d,%edi
mov    $0xe,%edx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    -0x30(%rbp),%rdx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
cmp    $0xe0,%r13b
jne    14f6 <main+0x346>
movw   $0x0,0x4(%r12)
jmp    1511 <main+0x361>
lea    -0x48(%rbp),%rsi
mov    %r15d,%edi
mov    $0xe,%edx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    -0x30(%rbp),%rdx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
cmp    $0xe0,%r13b
jne    153a <main+0x38a>
movw   $0x0,0x4(%r12)
jmp    1555 <main+0x3a5>
lea    -0x48(%rbp),%rsi
mov    %r15d,%edi
mov    $0xe,%edx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
mov    %rbx,%r13
mov    -0x34(%rbp),%ebx
mov    %r15d,%edi
mov    %r12,%rsi
mov    -0x30(%rbp),%rdx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
test   %bl,%bl
je     1589 <main+0x3d9>
lea    -0x54(%rbp),%rsi
mov    %r15d,%edi
mov    $0x4,%edx
call   1030 <write@plt>
lea    -0x2060(%rbp),%rsi
mov    %r15d,%edi
mov    $0x2000,%edx
call   1030 <write@plt>
mov    $0x249f0,%edi
call   10d0 <usleep@plt>
mov    0x2a42(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %r15d,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    (%r14),%esi
mov    0x29f9(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    %r13,%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    15e5 <main+0x435>
lea    0xa07(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%ebx
jmp    15e5 <main+0x435>

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

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
@O_NONBLOCK = 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 %152
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 %152
21: ; preds = %12
%22 = call i32 @fstat(i32 %16, %struct.stat* %3)
%23 = load i32, i32* @O_WRONLY
%24 = load i32, i32* @O_NONBLOCK
%25 = or i32 %24, %23
%26 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = icmp slt i32 %26, 1
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %152
30: ; preds = %21
%31 = tail call i64 (...) @fork()
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %152
33: ; preds = %30
%34 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%35 = bitcast i32* %5 to i8*
store i32 -1224671232, i32* %5
%36 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%37 = load i32, i32* %36
%38 = zext i32 %37 to i64
%39 = tail call i8* @llvm.stacksave()
%40 = alloca i8, i64 %38
%41 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 0, i32 8192)
%43 = call i32 @read(i32 %16, i8* %40, i32 %37)
%44 = load i32, i32* @VIDEO_SET_STREAMTYPE
%45 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 %44, i32 0)
%46 = load i32, i32* @VIDEO_SELECT_SOURCE
%47 = load i32, i32* @VIDEO_SOURCE_MEMORY
%48 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 %46, i32 %47)
%49 = call i32 @c(i32 %48)
%50 = load i32, i32* @VIDEO_PLAY
%51 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 %50)
%52 = call i32 @c(i32 %51)
%53 = load i32, i32* @VIDEO_CONTINUE
%54 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 %53)
%55 = call i32 @c(i32 %54)
%56 = load i32, i32* @VIDEO_CLEAR_BUFFER
%57 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 %56)
%58 = call i32 @c(i32 %57)
%59 = add nsw i32 %37, -4
%60 = sext i32 %59 to i64
br label %61
61: ; preds = %33, %81
%62 = phi i64 [ 0, %33 ], [ %66, %81 ]
%63 = getelementptr inbounds i8, i8* %40, i64 %62
%64 = load i8, i8* %63
%65 = icmp eq i8 %64, 0
%66 = add i64 %62, 1
br i1 %65, label %67, label %81
67: ; preds = %61
%68 = getelementptr inbounds i8, i8* %40, i64 %66
%69 = load i8, i8* %68
%70 = icmp eq i8 %69, 0
br i1 %70, label %71, label %81
71: ; preds = %67
%72 = add i64 %62, 2
%73 = getelementptr inbounds i8, i8* %40, i64 %72
%74 = load i8, i8* %73
%75 = icmp eq i8 %74, 1
br i1 %75, label %76, label %81
76: ; preds = %71
%77 = add i64 %62, 3
%78 = getelementptr inbounds i8, i8* %40, i64 %77
%79 = load i8, i8* %78
%80 = icmp eq i8 %79, -73
br i1 %80, label %83, label %81
81: ; preds = %61, %67, %71, %76
%82 = icmp ugt i64 %66, %60
br i1 %82, label %83, label %61
83: ; preds = %81, %76
%84 = phi i1 [ true, %81 ], [ false, %76 ]
%85 = getelementptr inbounds i8, i8* %40, i64 3
%86 = load i8, i8* %85
%87 = and i8 %86, -16
%88 = icmp eq i8 %87, -32
%89 = getelementptr inbounds i8, i8* %40, i64 5
%90 = getelementptr inbounds i8, i8* %40, i64 4
br i1 %88, label %94, label %91
91: ; preds = %83
%92 = call i32 @write(i32 %26, i8* %34, i32 14)
%93 = call i32 @usleep(i32 8000)
br label %95
94: ; preds = %83
store i8 0, i8* %89
store i8 0, i8* %90
br label %95
95: ; preds = %94, %91
%96 = call i32 @write(i32 %26, i8* %40, i32 %37)
%97 = call i32 @usleep(i32 8000)
br i1 %88, label %101, label %98
98: ; preds = %95
%99 = call i32 @write(i32 %26, i8* %34, i32 14)
%100 = call i32 @usleep(i32 8000)
br label %102
101: ; preds = %95
store i8 0, i8* %89
store i8 0, i8* %90
br label %102
102: ; preds = %101, %98
%103 = call i32 @write(i32 %26, i8* %40, i32 %37)
%104 = call i32 @usleep(i32 8000)
br i1 %88, label %108, label %105
105: ; preds = %102
%106 = call i32 @write(i32 %26, i8* %34, i32 14)
%107 = call i32 @usleep(i32 8000)
br label %109
108: ; preds = %102
store i8 0, i8* %89
store i8 0, i8* %90
br label %109
109: ; preds = %108, %105
%110 = call i32 @write(i32 %26, i8* %40, i32 %37)
%111 = call i32 @usleep(i32 8000)
br i1 %88, label %115, label %112
112: ; preds = %109
%113 = call i32 @write(i32 %26, i8* %34, i32 14)
%114 = call i32 @usleep(i32 8000)
br label %116
115: ; preds = %109
store i8 0, i8* %89
store i8 0, i8* %90
br label %116
116: ; preds = %115, %112
%117 = call i32 @write(i32 %26, i8* %40, i32 %37)
%118 = call i32 @usleep(i32 8000)
br i1 %88, label %122, label %119
119: ; preds = %116
%120 = call i32 @write(i32 %26, i8* %34, i32 14)
%121 = call i32 @usleep(i32 8000)
br label %123
122: ; preds = %116
store i8 0, i8* %89
store i8 0, i8* %90
br label %123
123: ; preds = %122, %119
%124 = call i32 @write(i32 %26, i8* %40, i32 %37)
%125 = call i32 @usleep(i32 8000)
br i1 %88, label %129, label %126
126: ; preds = %123
%127 = call i32 @write(i32 %26, i8* %34, i32 14)
%128 = call i32 @usleep(i32 8000)
br label %130
129: ; preds = %123
store i8 0, i8* %89
store i8 0, i8* %90
br label %130
130: ; preds = %129, %126
%131 = call i32 @write(i32 %26, i8* %40, i32 %37)
%132 = call i32 @usleep(i32 8000)
br i1 %88, label %136, label %133
133: ; preds = %130
%134 = call i32 @write(i32 %26, i8* %34, i32 14)
%135 = call i32 @usleep(i32 8000)
br label %137
136: ; preds = %130
store i8 0, i8* %89
store i8 0, i8* %90
br label %137
137: ; preds = %136, %133
%138 = call i32 @write(i32 %26, i8* %40, i32 %37)
%139 = call i32 @usleep(i32 8000)
br i1 %84, label %140, label %142
140: ; preds = %137
%141 = call i32 @write(i32 %26, i8* %35, i32 4)
br label %142
142: ; preds = %140, %137
%143 = call i32 @write(i32 %26, i8* %41, i32 8192)
%144 = call i32 @usleep(i32 150000)
%145 = load i32, i32* @VIDEO_STOP
%146 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 %145, i32 0)
%147 = call i32 @c(i32 %146)
%148 = load i32, i32* @VIDEO_SELECT_SOURCE
%149 = load i32, i32* @VIDEO_SOURCE_DEMUX
%150 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 %148, i32 %149)
%151 = call i32 @c(i32 %150)
br label %152
152: ; preds = %18, %30, %142, %28, %9
%153 = phi i32 [ 3, %9 ], [ 4, %18 ], [ 2, %28 ], [ 0, %142 ], [ 0, %30 ]
ret i32 %153
}