#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 */

/* Variables and functions */
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int /*<<< orphan*/, unsigned char *, int);
int main(int argc, char *argv[]) {
  int input1_file;
  int input2_file;
  int input3_file;
  int byte_read1;
  int byte_read2;
  int byte_read3;
  int index1;
  int index2;
  unsigned char ts_packet1[188];
  unsigned char ts_packet2[188];
  unsigned char ts_packet3[188];
  if (argc >= 4) {
    input1_file = open(argv[1], O_RDONLY);
    if (input1_file < 0) {
      fprintf(stderr, "Can't open file %s\n", argv[1]);
      return 0;
    }
    input2_file = open(argv[2], O_RDONLY);
    if (input2_file < 0) {
      fprintf(stderr, "Can't open file %s\n", argv[2]);
      return 0;
    }
    input3_file = open(argv[3], O_RDONLY);
    if (input3_file < 0) {
      fprintf(stderr, "Can't open file %s\n", argv[3]);
      return 0;
    }
  } else {
    fprintf(stderr, "Usage: 'tsororts inputfile1.ts inputfile2.ts "
                    "inputfile3.ts > output.ts'\n");
    fprintf(stderr,
            "ts packets are read from inputfile3.ts if they are not immediatly "
            "available from inputfile1.ts or inputfile2.ts'\n");
    return 0;
  }
  fcntl(input1_file, F_SETFL, fcntl(input1_file, F_GETFL, 0) | O_NONBLOCK);
  fcntl(input2_file, F_SETFL, fcntl(input2_file, F_GETFL, 0) | O_NONBLOCK);
  index1 = 0;
  index2 = 0;
  while (1) {
    byte_read1 = read(input1_file, ts_packet1 + index1, 188 - index1);
    byte_read2 = read(input2_file, ts_packet2 + index2, 188 - index2);
    if (byte_read1 > 0) {
      index1 += byte_read1;
      if (index1 == 188) {
        write(STDOUT_FILENO, ts_packet1, 188);
        index1 = 0;
      }
    }
    if (byte_read2 > 0) {
      index2 += byte_read2;
      if (index2 == 188) {
        write(STDOUT_FILENO, ts_packet2, 188);
        index2 = 0;
      }
    }
    if (byte_read1 <= 0 && byte_read2 <= 0 && index1 == 0 && index2 == 0) {
      byte_read3 = read(input3_file, ts_packet3, 188);
      if (byte_read3 == 0) {
        close(input3_file);
        input3_file = open(argv[3], O_RDONLY);
        if (input3_file < 0) {
          fprintf(stderr, "Can't open file %s\n", argv[2]);
          return 0;
        } else {
          byte_read3 = read(input3_file, ts_packet3, 188);
          if (byte_read3 > 0) {
            write(STDOUT_FILENO, ts_packet3, 188);
          }
        }
      } else {
        write(STDOUT_FILENO, ts_packet3, 188);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     1272 <main+0x112>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d1 <main+0x71>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    151e <main+0x3be>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    121f <main+0xbf>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    151e <main+0x3be>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    126d <main+0x10d>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    151e <main+0x3be>
jmp    12ac <main+0x14c>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    151e <main+0x3be>
mov    -0x14(%rbp),%eax
mov    %eax,-0x280(%rbp)
mov    0x2d04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x27c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cea(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x280(%rbp),%edi
mov    -0x27c(%rbp),%esi
mov    %eax,%edx
mov    0x2cf4(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x278(%rbp)
mov    0x2cbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x274(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2ca3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x278(%rbp),%edi
mov    -0x274(%rbp),%esi
mov    %eax,%edx
mov    0x2cad(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0xf0(%rbp),%rsi
movslq -0x2c(%rbp),%rax
add    %rax,%rsi
mov    $0xbc,%edx
sub    -0x2c(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x1b0(%rbp),%rsi
movslq -0x30(%rbp),%rax
add    %rax,%rsi
mov    $0xbc,%edx
sub    -0x30(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    13d0 <main+0x270>
mov    -0x20(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0xbc,-0x2c(%rbp)
jne    13cb <main+0x26b>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
lea    -0xf0(%rbp),%rsi
mov    $0xbc,%edx
call   1040 <write@plt>
movl   $0x0,-0x2c(%rbp)
jmp    13d0 <main+0x270>
cmpl   $0x0,-0x24(%rbp)
jle    1416 <main+0x2b6>
mov    -0x24(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0xbc,-0x30(%rbp)
jne    1411 <main+0x2b1>
mov    0x2bf9(%rip),%rax
mov    (%rax),%edi
lea    -0x1b0(%rbp),%rsi
mov    $0xbc,%edx
call   1040 <write@plt>
movl   $0x0,-0x30(%rbp)
jmp    1416 <main+0x2b6>
cmpl   $0x0,-0x20(%rbp)
jg     1519 <main+0x3b9>
cmpl   $0x0,-0x24(%rbp)
jg     1519 <main+0x3b9>
cmpl   $0x0,-0x2c(%rbp)
jne    1519 <main+0x3b9>
cmpl   $0x0,-0x30(%rbp)
jne    1519 <main+0x3b9>
mov    -0x1c(%rbp),%edi
lea    -0x270(%rbp),%rsi
mov    $0xbc,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    14fa <main+0x39a>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2b62(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    14b5 <main+0x355>
mov    0x2b37(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xb5e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    151e <main+0x3be>
mov    -0x1c(%rbp),%edi
lea    -0x270(%rbp),%rsi
mov    $0xbc,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    14f0 <main+0x390>
mov    0x2b13(%rip),%rax
mov    (%rax),%edi
lea    -0x270(%rbp),%rsi
mov    $0xbc,%edx
call   1040 <write@plt>
jmp    14f5 <main+0x395>
jmp    1514 <main+0x3b4>
mov    0x2aef(%rip),%rax
mov    (%rax),%edi
lea    -0x270(%rbp),%rsi
mov    $0xbc,%edx
call   1040 <write@plt>
jmp    1519 <main+0x3b9>
jmp    1348 <main+0x1e8>
mov    -0x4(%rbp),%eax
add    $0x280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x258,%rsp
cmp    $0x4,%edi
jl     1372 <main+0x212>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x2e50(%rip),%r15
mov    (%r15),%esi
call   1080 <open@plt>
test   %eax,%eax
js     13aa <main+0x24a>
mov    %eax,%ebp
mov    0x10(%r14),%rdi
mov    (%r15),%esi
call   1080 <open@plt>
test   %eax,%eax
js     139b <main+0x23b>
mov    %eax,%ebx
mov    0x18(%r14),%rdi
mov    (%r15),%esi
call   1080 <open@plt>
test   %eax,%eax
js     13b9 <main+0x259>
mov    %eax,0x4(%rsp)
mov    %r14,0x8(%rsp)
mov    0x2dec(%rip),%rax
mov    (%rax),%r14d
mov    0x2dda(%rip),%r13
mov    0x0(%r13),%esi
xor    %r12d,%r12d
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    0x2deb(%rip),%r15
or     (%r15),%eax
mov    %ebp,%edi
mov    %r14d,%esi
mov    %eax,%edx
call   1030 <fcntl@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%r14d
mov    0x0(%r13),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
or     (%r15),%eax
mov    %ebx,%edi
mov    %r14d,%esi
mov    %eax,%edx
call   1030 <fcntl@plt>
xor    %r13d,%r13d
jmp    1270 <main+0x110>
mov    0x4(%rsp),%r14d
mov    %r14d,%edi
lea    0x190(%rsp),%r15
mov    %r15,%rsi
mov    $0xbc,%edx
call   1060 <read@plt>
test   %eax,%eax
je     132f <main+0x1cf>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
mov    $0xbc,%edx
call   1040 <write@plt>
nopw   0x0(%rax,%rax,1)
movslq %r12d,%rax
lea    (%rsp,%rax,1),%rsi
add    $0xd0,%rsi
mov    $0xbc,%edx
sub    %eax,%edx
mov    %ebp,%edi
call   1060 <read@plt>
mov    %eax,%r14d
movslq %r13d,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x10,%rsi
mov    $0xbc,%edx
sub    %eax,%edx
mov    %ebx,%edi
call   1060 <read@plt>
mov    %eax,%r15d
test   %r14d,%r14d
jle    12da <main+0x17a>
add    %r14d,%r12d
cmp    $0xbc,%r12d
jne    12da <main+0x17a>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    0xd0(%rsp),%rsi
mov    $0xbc,%edx
call   1040 <write@plt>
xor    %r12d,%r12d
test   %r15d,%r15d
jle    1306 <main+0x1a6>
add    %r15d,%r13d
cmp    $0xbc,%r13d
jne    1306 <main+0x1a6>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
mov    $0xbc,%edx
call   1040 <write@plt>
xor    %r13d,%r13d
test   %r14d,%r14d
jg     1270 <main+0x110>
test   %r15d,%r15d
jg     1270 <main+0x110>
test   %r12d,%r12d
jne    1270 <main+0x110>
test   %r13d,%r13d
jne    1270 <main+0x110>
jmp    122f <main+0xcf>
mov    %r14d,%edi
call   1050 <close@plt>
mov    0x8(%rsp),%r14
mov    0x18(%r14),%rdi
mov    0x2c91(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     139b <main+0x23b>
mov    %eax,0x4(%rsp)
mov    %eax,%edi
mov    %r15,%rsi
mov    $0xbc,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     1254 <main+0xf4>
jmp    1270 <main+0x110>
mov    0x2c4f(%rip),%rbx
mov    (%rbx),%edi
lea    0xc92(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xccb(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    13d4 <main+0x274>
mov    0x2c26(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r14),%rdx
jmp    13c6 <main+0x266>
mov    0x2c17(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
jmp    13c6 <main+0x266>
mov    0x2c08(%rip),%rax
mov    (%rax),%edi
mov    0x18(%r14),%rdx
lea    0xc33(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x258,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"Can't open file %s\0A\00"
@.str.1 = [73 x i8] c"Usage: 'tsororts inputfile1.ts inputfile2.ts inputfile3.ts > output.ts'\0A\00"
@.str.2 = [114 x i8] c"ts packets are read from inputfile3.ts if they are not immediatly available from inputfile1.ts or inputfile2.ts'\0A\00"
@F_SETFL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@STDOUT_FILENO = 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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [188 x i8]
%15 = alloca [188 x i8]
%16 = alloca [188 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp sge i32 %17, 4
br i1 %18, label %19, label %62
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %31)
store i32 0, i32* %3
br label %180
33: ; preds = %19
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = load i32, i32* @O_RDONLY
%38 = call i32 @open(i8* %36, i32 %37)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %33
%42 = load i32, i32* @stderr
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %45)
store i32 0, i32* %3
br label %180
47: ; preds = %33
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 3
%50 = load i8*, i8** %49
%51 = load i32, i32* @O_RDONLY
%52 = call i32 @open(i8* %50, i32 %51)
store i32 %52, i32* %8
%53 = load i32, i32* %8
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %61
55: ; preds = %47
%56 = load i32, i32* @stderr
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 3
%59 = load i8*, i8** %58
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %59)
store i32 0, i32* %3
br label %180
61: ; preds = %47
br label %67
62: ; preds = %2
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0))
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %180
67: ; preds = %61
%68 = load i32, i32* %6
%69 = load i32, i32* @F_SETFL
%70 = load i32, i32* %6
%71 = load i32, i32* @F_GETFL
%72 = call i32 @fcntl(i32 %70, i32 %71, i32 0)
%73 = load i32, i32* @O_NONBLOCK
%74 = or i32 %72, %73
%75 = call i32 @fcntl(i32 %68, i32 %69, i32 %74)
%76 = load i32, i32* %7
%77 = load i32, i32* @F_SETFL
%78 = load i32, i32* %7
%79 = load i32, i32* @F_GETFL
%80 = call i32 @fcntl(i32 %78, i32 %79, i32 0)
%81 = load i32, i32* @O_NONBLOCK
%82 = or i32 %80, %81
%83 = call i32 @fcntl(i32 %76, i32 %77, i32 %82)
store i32 0, i32* %12
store i32 0, i32* %13
br label %84
84: ; preds = %67, %179
%85 = load i32, i32* %6
%86 = getelementptr inbounds [188 x i8], [188 x i8]* %14, i64 0, i64 0
%87 = load i32, i32* %12
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
%90 = load i32, i32* %12
%91 = sub nsw i32 188, %90
%92 = call i32 @read(i32 %85, i8* %89, i32 %91)
store i32 %92, i32* %9
%93 = load i32, i32* %7
%94 = getelementptr inbounds [188 x i8], [188 x i8]* %15, i64 0, i64 0
%95 = load i32, i32* %13
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %94, i64 %96
%98 = load i32, i32* %13
%99 = sub nsw i32 188, %98
%100 = call i32 @read(i32 %93, i8* %97, i32 %99)
store i32 %100, i32* %10
%101 = load i32, i32* %9
%102 = icmp sgt i32 %101, 0
br i1 %102, label %103, label %114
103: ; preds = %84
%104 = load i32, i32* %9
%105 = load i32, i32* %12
%106 = add nsw i32 %105, %104
store i32 %106, i32* %12
%107 = load i32, i32* %12
%108 = icmp eq i32 %107, 188
br i1 %108, label %109, label %113
109: ; preds = %103
%110 = load i32, i32* @STDOUT_FILENO
%111 = getelementptr inbounds [188 x i8], [188 x i8]* %14, i64 0, i64 0
%112 = call i32 @write(i32 %110, i8* %111, i32 188)
store i32 0, i32* %12
br label %113
113: ; preds = %109, %103
br label %114
114: ; preds = %113, %84
%115 = load i32, i32* %10
%116 = icmp sgt i32 %115, 0
br i1 %116, label %117, label %128
117: ; preds = %114
%118 = load i32, i32* %10
%119 = load i32, i32* %13
%120 = add nsw i32 %119, %118
store i32 %120, i32* %13
%121 = load i32, i32* %13
%122 = icmp eq i32 %121, 188
br i1 %122, label %123, label %127
123: ; preds = %117
%124 = load i32, i32* @STDOUT_FILENO
%125 = getelementptr inbounds [188 x i8], [188 x i8]* %15, i64 0, i64 0
%126 = call i32 @write(i32 %124, i8* %125, i32 188)
store i32 0, i32* %13
br label %127
127: ; preds = %123, %117
br label %128
128: ; preds = %127, %114
%129 = load i32, i32* %9
%130 = icmp sle i32 %129, 0
br i1 %130, label %131, label %179
131: ; preds = %128
%132 = load i32, i32* %10
%133 = icmp sle i32 %132, 0
br i1 %133, label %134, label %179
134: ; preds = %131
%135 = load i32, i32* %12
%136 = icmp eq i32 %135, 0
br i1 %136, label %137, label %179
137: ; preds = %134
%138 = load i32, i32* %13
%139 = icmp eq i32 %138, 0
br i1 %139, label %140, label %179
140: ; preds = %137
%141 = load i32, i32* %8
%142 = getelementptr inbounds [188 x i8], [188 x i8]* %16, i64 0, i64 0
%143 = call i32 @read(i32 %141, i8* %142, i32 188)
store i32 %143, i32* %11
%144 = load i32, i32* %11
%145 = icmp eq i32 %144, 0
br i1 %145, label %146, label %174
146: ; preds = %140
%147 = load i32, i32* %8
%148 = call i32 @close(i32 %147)
%149 = load i8**, i8*** %5
%150 = getelementptr inbounds i8*, i8** %149, i64 3
%151 = load i8*, i8** %150
%152 = load i32, i32* @O_RDONLY
%153 = call i32 @open(i8* %151, i32 %152)
store i32 %153, i32* %8
%154 = load i32, i32* %8
%155 = icmp slt i32 %154, 0
br i1 %155, label %156, label %162
156: ; preds = %146
%157 = load i32, i32* @stderr
%158 = load i8**, i8*** %5
%159 = getelementptr inbounds i8*, i8** %158, i64 2
%160 = load i8*, i8** %159
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %157, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %160)
store i32 0, i32* %3
br label %180
162: ; preds = %146
%163 = load i32, i32* %8
%164 = getelementptr inbounds [188 x i8], [188 x i8]* %16, i64 0, i64 0
%165 = call i32 @read(i32 %163, i8* %164, i32 188)
store i32 %165, i32* %11
%166 = load i32, i32* %11
%167 = icmp sgt i32 %166, 0
br i1 %167, label %168, label %172
168: ; preds = %162
%169 = load i32, i32* @STDOUT_FILENO
%170 = getelementptr inbounds [188 x i8], [188 x i8]* %16, i64 0, i64 0
%171 = call i32 @write(i32 %169, i8* %170, i32 188)
br label %172
172: ; preds = %168, %162
br label %173
173: ; preds = %172
br label %178
174: ; preds = %140
%175 = load i32, i32* @STDOUT_FILENO
%176 = getelementptr inbounds [188 x i8], [188 x i8]* %16, i64 0, i64 0
%177 = call i32 @write(i32 %175, i8* %176, i32 188)
br label %178
178: ; preds = %174, %173
br label %179
179: ; preds = %178, %137, %134, %131, %128
br label %84
180: ; preds = %156, %62, %55, %41, %27
%181 = load i32, i32* %3
ret i32 %181
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"Can't open file %s\0A\00"
@.str.1 = [73 x i8] c"Usage: 'tsororts inputfile1.ts inputfile2.ts inputfile3.ts > output.ts'\0A\00"
@.str.2 = [114 x i8] c"ts packets are read from inputfile3.ts if they are not immediatly available from inputfile1.ts or inputfile2.ts'\0A\00"
@F_SETFL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [188 x i8]
%4 = alloca [188 x i8]
%5 = alloca [188 x i8]
%6 = getelementptr inbounds [188 x i8], [188 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [188 x i8], [188 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [188 x i8], [188 x i8]* %5, i64 0, i64 0
%9 = icmp sgt i32 %0, 3
br i1 %9, label %10, label %40
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %11
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %120
20: ; preds = %10
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = tail call i32 @open(i8* %22, i32 %23)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %21
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %120
30: ; preds = %20
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = load i8*, i8** %31
%33 = load i32, i32* @O_RDONLY
%34 = tail call i32 @open(i8* %32, i32 %33)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %31
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %38)
br label %120
40: ; preds = %2
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str.2, i64 0, i64 0))
br label %120
45: ; preds = %30
%46 = load i32, i32* @F_SETFL
%47 = load i32, i32* @F_GETFL
%48 = tail call i32 @fcntl(i32 %14, i32 %47, i32 0)
%49 = load i32, i32* @O_NONBLOCK
%50 = or i32 %49, %48
%51 = tail call i32 @fcntl(i32 %14, i32 %46, i32 %50)
%52 = load i32, i32* @F_SETFL
%53 = load i32, i32* @F_GETFL
%54 = tail call i32 @fcntl(i32 %24, i32 %53, i32 0)
%55 = load i32, i32* @O_NONBLOCK
%56 = or i32 %55, %54
%57 = tail call i32 @fcntl(i32 %24, i32 %52, i32 %56)
br label %58
58: ; preds = %114, %45
%59 = phi i32 [ %34, %45 ], [ %115, %114 ]
%60 = phi i32 [ 0, %45 ], [ %81, %114 ]
%61 = phi i32 [ 0, %45 ], [ %90, %114 ]
br label %62
62: ; preds = %58, %89
%63 = phi i32 [ %81, %89 ], [ %60, %58 ]
%64 = phi i32 [ %90, %89 ], [ %61, %58 ]
%65 = sext i32 %63 to i64
%66 = getelementptr inbounds [188 x i8], [188 x i8]* %3, i64 0, i64 %65
%67 = sub nsw i32 188, %63
%68 = call i32 @read(i32 %14, i8* %66, i32 %67)
%69 = sext i32 %64 to i64
%70 = getelementptr inbounds [188 x i8], [188 x i8]* %4, i64 0, i64 %69
%71 = sub nsw i32 188, %64
%72 = call i32 @read(i32 %24, i8* %70, i32 %71)
%73 = icmp sgt i32 %68, 0
br i1 %73, label %74, label %80
74: ; preds = %62
%75 = add nsw i32 %68, %63
%76 = icmp eq i32 %75, 188
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load i32, i32* @STDOUT_FILENO
%79 = call i32 @write(i32 %78, i8* %6, i32 188)
br label %80
80: ; preds = %74, %77, %62
%81 = phi i32 [ 0, %77 ], [ %75, %74 ], [ %63, %62 ]
%82 = icmp sgt i32 %72, 0
br i1 %82, label %83, label %89
83: ; preds = %80
%84 = add nsw i32 %72, %64
%85 = icmp eq i32 %84, 188
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i32, i32* @STDOUT_FILENO
%88 = call i32 @write(i32 %87, i8* %7, i32 188)
br label %89
89: ; preds = %83, %86, %80
%90 = phi i32 [ 0, %86 ], [ %84, %83 ], [ %64, %80 ]
%91 = icmp slt i32 %68, 1
%92 = icmp slt i32 %72, 1
%93 = and i1 %91, %92
%94 = icmp eq i32 %81, 0
%95 = select i1 %93, i1 %94, i1 false
%96 = icmp eq i32 %90, 0
%97 = select i1 %95, i1 %96, i1 false
br i1 %97, label %98, label %62
98: ; preds = %89
%99 = call i32 @read(i32 %59, i8* %8, i32 188)
%100 = icmp eq i32 %99, 0
br i1 %100, label %101, label %116
101: ; preds = %98
%102 = tail call i32 @close(i32 %59)
%103 = load i8*, i8** %31
%104 = load i32, i32* @O_RDONLY
%105 = tail call i32 @open(i8* %103, i32 %104)
%106 = icmp slt i32 %105, 0
br i1 %106, label %107, label %111
107: ; preds = %101
%108 = load i32, i32* @stderr
%109 = load i8*, i8** %21
%110 = tail call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %109)
br label %120
111: ; preds = %101
%112 = call i32 @read(i32 %105, i8* %8, i32 188)
%113 = icmp sgt i32 %112, 0
br i1 %113, label %116, label %114
114: ; preds = %111, %116
%115 = phi i32 [ %117, %116 ], [ %105, %111 ]
br label %58
116: ; preds = %98, %111
%117 = phi i32 [ %105, %111 ], [ %59, %98 ]
%118 = load i32, i32* @STDOUT_FILENO
%119 = call i32 @write(i32 %118, i8* %8, i32 188)
br label %114
120: ; preds = %107, %40, %36, %26, %16
ret i32 0
}