#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 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);
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);
    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;
    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    160a <main+0x45a>
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    160a <main+0x45a>
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    160a <main+0x45a>
mov    $0x0,%al
call   10c0 <fork@plt>
cmp    $0x0,%rax
je     129a <main+0xea>
movl   $0x0,-0x4(%rbp)
jmp    160a <main+0x45a>
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    -0x2068(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    13a4 <main+0x1f4>
mov    -0x2068(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    13a4 <main+0x1f4>
mov    -0x2068(%rbp),%rax
movzbl 0x2(%rax),%eax
cmp    $0x0,%eax
jne    13a4 <main+0x1f4>
mov    -0x2068(%rbp),%rax
movzbl 0x3(%rax),%eax
cmp    $0x1,%eax
jne    13a4 <main+0x1f4>
mov    -0x2068(%rbp),%rax
movzbl 0x4(%rax),%eax
and    $0xf,%eax
cmp    $0x7,%eax
jne    13a4 <main+0x1f4>
mov    -0x20(%rbp),%edi
mov    0x2c67(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
mov    $0x0,%al
call   1060 <ioctl@plt>
jmp    13b9 <main+0x209>
mov    -0x20(%rbp),%edi
mov    0x2c4a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    -0x20(%rbp),%edi
mov    0x2bc5(%rip),%rax
mov    (%rax),%esi
mov    0x2bd4(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x20(%rbp),%edi
mov    0x2bfa(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x20(%rbp),%edi
mov    0x2ba8(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    -0x20(%rbp),%edi
mov    0x2b9e(%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     14db <main+0x32b>
mov    -0x2068(%rbp),%rcx
mov    -0x28(%rbp),%rdx
xor    %eax,%eax
cmpb   $0x0,(%rcx,%rdx,1)
mov    %al,-0x206a(%rbp)
jne    14c2 <main+0x312>
mov    -0x2068(%rbp),%rcx
mov    -0x28(%rbp),%rdx
xor    %eax,%eax
cmpb   $0x0,0x1(%rcx,%rdx,1)
mov    %al,-0x206a(%rbp)
jne    14c2 <main+0x312>
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    14c2 <main+0x312>
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    14ee <main+0x33e>
jmp    14ff <main+0x34f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    142a <main+0x27a>
jmp    1504 <main+0x354>
mov    -0x30(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x30(%rbp)
cmp    $0x0,%eax
je     157f <main+0x3cf>
mov    -0x2068(%rbp),%rax
movzbl 0x3(%rax),%eax
sar    $0x4,%eax
cmp    $0xe,%eax
je     154f <main+0x39f>
mov    -0x20(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
mov    $0x1f40,%edi
call   10d0 <usleep@plt>
jmp    155e <main+0x3ae>
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    1504 <main+0x354>
cmpl   $0x0,-0x2c(%rbp)
jne    159a <main+0x3ea>
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    0x2a2e(%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    0x29aa(%rip),%rax
mov    (%rax),%esi
mov    0x29e1(%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    1603 <main+0x453>
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    13a4 <main+0x1f4>
mov    0x8(%rbx),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     1636 <main+0x486>
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    1646 <main+0x496>
mov    %eax,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jne    1625 <main+0x475>
mov    %r14d,-0x54(%rbp)
mov    %rsp,-0x60(%rbp)
movabs $0x100010021058080,%rax
mov    %rax,-0x42(%rbp)
movabs $0x80800000e0010000,%rax
mov    %rax,-0x48(%rbp)
movl   $0xb7010000,-0x58(%rbp)
mov    -0x50(%rbp),%r15d
movslq %r15d,%r14
mov    %rsp,%rbx
mov    %r15,-0x30(%rbp)
add    $0xf,%r15
and    $0xfffffffffffffff0,%r15
mov    %rbx,%r12
sub    %r15,%r12
mov    %r12,%rsp
neg    %r15
lea    -0x2060(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1050 <memset@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %r14d,%edx
call   1070 <read@plt>
mov    (%rbx,%r15,1),%bl
test   %bl,%bl
jne    12d1 <main+0x121>
cmpb   $0x0,0x1(%r12)
jne    12d1 <main+0x121>
cmpb   $0x0,0x2(%r12)
jne    12d1 <main+0x121>
cmpb   $0x1,0x3(%r12)
jne    12d1 <main+0x121>
mov    0x4(%r12),%al
and    $0xf,%al
mov    $0x1,%edx
cmp    $0x7,%al
je     12d3 <main+0x123>
xor    %edx,%edx
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
mov    -0x54(%rbp),%r15d
mov    %r15d,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    0x2c97(%rip),%r13
mov    0x0(%r13),%esi
mov    0x2ca4(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
mov    0x2c6e(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    %eax,%edi
call   1080 <c@plt>
add    $0xfffffffffffffffc,%r14
mov    $0x1,%eax
test   %bl,%bl
jne    1390 <main+0x1e0>
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,(%r12,%rax,1)
jne    1390 <main+0x1e0>
cmpb   $0x1,0x1(%r12,%rax,1)
jne    1390 <main+0x1e0>
cmpb   $0xb7,0x2(%r12,%rax,1)
je     1659 <main+0x4a9>
nopl   0x0(%rax,%rax,1)
cmp    %r14,%rax
ja     13bd <main+0x20d>
movzbl (%r12,%rax,1),%ebx
add    $0x1,%rax
test   %bl,%bl
jne    1390 <main+0x1e0>
jmp    1370 <main+0x1c0>
mov    (%rbx),%rsi
lea    0xc52(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3,%ebx
jmp    1625 <main+0x475>
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    13e2 <main+0x232>
movw   $0x0,0x4(%r12)
jmp    13fd <main+0x24d>
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    1426 <main+0x276>
movw   $0x0,0x4(%r12)
jmp    1441 <main+0x291>
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    146a <main+0x2ba>
movw   $0x0,0x4(%r12)
jmp    1485 <main+0x2d5>
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    14ae <main+0x2fe>
movw   $0x0,0x4(%r12)
jmp    14c9 <main+0x319>
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    14f2 <main+0x342>
movw   $0x0,0x4(%r12)
jmp    150d <main+0x35d>
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    1536 <main+0x386>
movw   $0x0,0x4(%r12)
jmp    1551 <main+0x3a1>
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    157a <main+0x3ca>
movw   $0x0,0x4(%r12)
jmp    1595 <main+0x3e5>
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     15c9 <main+0x419>
lea    -0x58(%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    0x2a02(%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    0x29b9(%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    1625 <main+0x475>
lea    0x9c7(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%ebx
jmp    1625 <main+0x475>
mov    %r13,%r14
movl   $0x0,-0x34(%rbp)
jmp    13c5 <main+0x215>

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 %206
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 %206
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 %206
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 %206
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 = getelementptr inbounds i8, i8* %58, i64 0
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %94
69: ; preds = %51
%70 = getelementptr inbounds i8, i8* %58, i64 1
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %94
74: ; preds = %69
%75 = getelementptr inbounds i8, i8* %58, i64 2
%76 = load i8, i8* %75
%77 = zext i8 %76 to i32
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %94
79: ; preds = %74
%80 = getelementptr inbounds i8, i8* %58, i64 3
%81 = load i8, i8* %80
%82 = zext i8 %81 to i32
%83 = icmp eq i32 %82, 1
br i1 %83, label %84, label %94
84: ; preds = %79
%85 = getelementptr inbounds i8, i8* %58, i64 4
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = and i32 %87, 15
%89 = icmp eq i32 %88, 7
br i1 %89, label %90, label %94
90: ; preds = %84
%91 = load i32, i32* %8
%92 = load i32, i32* @VIDEO_SET_STREAMTYPE
%93 = call i32 (i32, i32, ...) @ioctl(i32 %91, i32 %92, i32 1)
br label %98
94: ; preds = %84, %79, %74, %69, %51
%95 = load i32, i32* %8
%96 = load i32, i32* @VIDEO_SET_STREAMTYPE
%97 = call i32 (i32, i32, ...) @ioctl(i32 %95, i32 %96, i32 0)
br label %98
98: ; preds = %94, %90
%99 = load i32, i32* %8
%100 = load i32, i32* @VIDEO_SELECT_SOURCE
%101 = load i32, i32* @VIDEO_SOURCE_MEMORY
%102 = call i32 (i32, i32, ...) @ioctl(i32 %99, i32 %100, i32 %101)
%103 = call i32 @c(i32 %102)
%104 = load i32, i32* %8
%105 = load i32, i32* @VIDEO_PLAY
%106 = call i32 (i32, i32, ...) @ioctl(i32 %104, i32 %105)
%107 = call i32 @c(i32 %106)
%108 = load i32, i32* %8
%109 = load i32, i32* @VIDEO_CONTINUE
%110 = call i32 (i32, i32, ...) @ioctl(i32 %108, i32 %109)
%111 = call i32 @c(i32 %110)
%112 = load i32, i32* %8
%113 = load i32, i32* @VIDEO_CLEAR_BUFFER
%114 = call i32 (i32, i32, ...) @ioctl(i32 %112, i32 %113)
%115 = call i32 @c(i32 %114)
br label %116
116: ; preds = %154, %98
%117 = load i64, i64* %9
%118 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%119 = load i32, i32* %118
%120 = sub nsw i32 %119, 4
%121 = sext i32 %120 to i64
%122 = icmp ule i64 %117, %121
br i1 %122, label %123, label %152
123: ; preds = %116
%124 = load i64, i64* %9
%125 = getelementptr inbounds i8, i8* %58, i64 %124
%126 = load i8, i8* %125
%127 = icmp ne i8 %126, 0
br i1 %127, label %148, label %128
128: ; preds = %123
%129 = load i64, i64* %9
%130 = add i64 %129, 1
%131 = getelementptr inbounds i8, i8* %58, i64 %130
%132 = load i8, i8* %131
%133 = icmp ne i8 %132, 0
br i1 %133, label %148, label %134
134: ; preds = %128
%135 = load i64, i64* %9
%136 = add i64 %135, 2
%137 = getelementptr inbounds i8, i8* %58, i64 %136
%138 = load i8, i8* %137
%139 = zext i8 %138 to i32
%140 = icmp eq i32 %139, 1
br i1 %140, label %141, label %148
141: ; preds = %134
%142 = load i64, i64* %9
%143 = add i64 %142, 3
%144 = getelementptr inbounds i8, i8* %58, i64 %143
%145 = load i8, i8* %144
%146 = zext i8 %145 to i32
%147 = icmp eq i32 %146, 183
br label %148
148: ; preds = %141, %134, %128, %123
%149 = phi i1 [ false, %134 ], [ false, %128 ], [ false, %123 ], [ %147, %141 ]
%150 = zext i1 %149 to i32
store i32 %150, i32* %10
%151 = xor i1 %149, true
br label %152
152: ; preds = %148, %116
%153 = phi i1 [ false, %116 ], [ %151, %148 ]
br i1 %153, label %154, label %157
154: ; preds = %152
%155 = load i64, i64* %9
%156 = add i64 %155, 1
store i64 %156, i64* %9
br label %116
157: ; preds = %152
br label %158
158: ; preds = %176, %157
%159 = load i32, i32* %11
%160 = add nsw i32 %159, -1
store i32 %160, i32* %11
%161 = icmp ne i32 %159, 0
br i1 %161, label %162, label %182
162: ; preds = %158
%163 = getelementptr inbounds i8, i8* %58, i64 3
%164 = load i8, i8* %163
%165 = zext i8 %164 to i32
%166 = ashr i32 %165, 4
%167 = icmp ne i32 %166, 14
br i1 %167, label %168, label %173
168: ; preds = %162
%169 = load i32, i32* %8
%170 = getelementptr inbounds [14 x i8], [14 x i8]* %12, i64 0, i64 0
%171 = call i32 @write(i32 %169, i8* %170, i32 14)
%172 = call i32 @usleep(i32 8000)
br label %176
173: ; preds = %162
%174 = getelementptr inbounds i8, i8* %58, i64 5
store i8 0, i8* %174
%175 = getelementptr inbounds i8, i8* %58, i64 4
store i8 0, i8* %175
br label %176
176: ; preds = %173, %168
%177 = load i32, i32* %8
%178 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%179 = load i32, i32* %178
%180 = call i32 @write(i32 %177, i8* %58, i32 %179)
%181 = call i32 @usleep(i32 8000)
br label %158
182: ; preds = %158
%183 = load i32, i32* %10
%184 = icmp ne i32 %183, 0
br i1 %184, label %189, label %185
185: ; preds = %182
%186 = load i32, i32* %8
%187 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%188 = call i32 @write(i32 %186, i8* %187, i32 4)
br label %189
189: ; preds = %185, %182
%190 = load i32, i32* %8
%191 = getelementptr inbounds [8192 x i8], [8192 x i8]* %16, i64 0, i64 0
%192 = call i32 @write(i32 %190, i8* %191, i32 8192)
%193 = call i32 @usleep(i32 150000)
%194 = load i32, i32* %8
%195 = load i32, i32* @VIDEO_STOP
%196 = call i32 (i32, i32, ...) @ioctl(i32 %194, i32 %195, i32 0)
%197 = call i32 @c(i32 %196)
%198 = load i32, i32* %8
%199 = load i32, i32* @VIDEO_SELECT_SOURCE
%200 = load i32, i32* @VIDEO_SOURCE_DEMUX
%201 = call i32 (i32, i32, ...) @ioctl(i32 %198, i32 %199, i32 %200)
%202 = call i32 @c(i32 %201)
%203 = load i8*, i8** %14
br label %204
204: ; preds = %189
br label %205
205: ; preds = %204
store i32 0, i32* %3
br label %206
206: ; preds = %205, %50, %45, %31, %19
%207 = load i32, i32* %3
ret i32 %207
}

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