#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*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(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, unsigned char *, int);
int main(int argc, char *argv[]) {
  int input_file;
  int output_file1;
  int output_file2;
  int byte_read;
  unsigned char packet[188];
  if (argc >= 4) {
    input_file = open(argv[1], O_RDONLY);
    if (input_file < 0) {
      fprintf(stderr, "Can't open file %s\n", argv[1]);
      return 0;
    }
    output_file1 = open(argv[2], O_WRONLY);
    if (output_file1 < 0) {
      fprintf(stderr, "Can't open file %s\n", argv[2]);
      return 0;
    }
    output_file2 = open(argv[3], O_WRONLY);
    if (output_file2 < 0) {
      fprintf(stderr, "Can't open file %s\n", argv[3]);
      return 0;
    }
  } else {
    fprintf(
        stderr,
        "Usage: 'tsdoubleoutput inputfile.ts outputfile1.ts outputfile2.ts'\n");
    fprintf(stderr, "N.B. files must exist, touch them if needed'\n");
    return 0;
  }
  byte_read = 1;
  while (byte_read) {
    byte_read = read(input_file, packet, 188);
    write(output_file1, packet, 188);
    write(output_file2, packet, 188);
  }
  close(input_file);
  close(output_file1);
  close(output_file2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     1262 <main+0x112>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c1 <main+0x71>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1310 <main+0x1c0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    120f <main+0xbf>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1310 <main+0x1c0>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    125d <main+0x10d>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xdb6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1310 <main+0x1c0>
jmp    129c <main+0x14c>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1310 <main+0x1c0>
movl   $0x1,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     12f1 <main+0x1a1>
mov    -0x14(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0xbc,%edx
call   1050 <read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0xbc,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0xbc,%edx
call   1030 <write@plt>
jmp    12a3 <main+0x153>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
cmp    $0x4,%edi
jl     1210 <main+0xc0>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1239 <main+0xe9>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
mov    0x2e33(%rip),%rbx
mov    (%rbx),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1248 <main+0xf8>
mov    %eax,%r12d
mov    0x18(%r14),%rdi
mov    (%rbx),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1257 <main+0x107>
mov    %eax,%r13d
mov    %rsp,%rbp
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xbc,%edx
call   1050 <read@plt>
mov    %eax,%ebx
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0xbc,%edx
call   1030 <write@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0xbc,%edx
call   1030 <write@plt>
test   %ebx,%ebx
jne    11c0 <main+0x70>
mov    %r15d,%edi
call   1040 <close@plt>
mov    %r12d,%edi
call   1040 <close@plt>
mov    %r13d,%edi
call   1040 <close@plt>
jmp    1272 <main+0x122>
mov    0x2dc1(%rip),%rbx
mov    (%rbx),%edi
lea    0xdf4(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe28(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1272 <main+0x122>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
jmp    1264 <main+0x114>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r14),%rdx
jmp    1264 <main+0x114>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    0x18(%r14),%rdx
lea    0xd95(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0xc8,%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"
@O_WRONLY = global i32 0
@.str.1 = [68 x i8] c"Usage: 'tsdoubleoutput inputfile.ts outputfile1.ts outputfile2.ts'\0A\00"
@.str.2 = [46 x i8] c"N.B. files must exist, touch them if needed'\0A\00"
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 [188 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sge i32 %11, 4
br i1 %12, label %13, label %56
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 0, i32* %3
br label %82
27: ; preds = %13
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = load i32, i32* @O_WRONLY
%32 = call i32 @open(i8* %30, i32 %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %27
%36 = load i32, i32* @stderr
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %39)
store i32 0, i32* %3
br label %82
41: ; preds = %27
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 3
%44 = load i8*, i8** %43
%45 = load i32, i32* @O_WRONLY
%46 = call i32 @open(i8* %44, i32 %45)
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %41
%50 = load i32, i32* @stderr
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 3
%53 = load i8*, i8** %52
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %53)
store i32 0, i32* %3
br label %82
55: ; preds = %41
br label %61
56: ; preds = %2
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %82
61: ; preds = %55
store i32 1, i32* %9
br label %62
62: ; preds = %65, %61
%63 = load i32, i32* %9
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %75
65: ; preds = %62
%66 = load i32, i32* %6
%67 = getelementptr inbounds [188 x i8], [188 x i8]* %10, i64 0, i64 0
%68 = call i32 @read(i32 %66, i8* %67, i32 188)
store i32 %68, i32* %9
%69 = load i32, i32* %7
%70 = getelementptr inbounds [188 x i8], [188 x i8]* %10, i64 0, i64 0
%71 = call i32 @write(i32 %69, i8* %70, i32 188)
%72 = load i32, i32* %8
%73 = getelementptr inbounds [188 x i8], [188 x i8]* %10, i64 0, i64 0
%74 = call i32 @write(i32 %72, i8* %73, i32 188)
br label %62
75: ; preds = %62
%76 = load i32, i32* %6
%77 = call i32 @close(i32 %76)
%78 = load i32, i32* %7
%79 = call i32 @close(i32 %78)
%80 = load i32, i32* %8
%81 = call i32 @close(i32 %80)
store i32 0, i32* %3
br label %82
82: ; preds = %75, %56, %49, %35, %21
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"Can't open file %s\0A\00"
@O_WRONLY = global i32 0
@.str.1 = [68 x i8] c"Usage: 'tsdoubleoutput inputfile.ts outputfile1.ts outputfile2.ts'\0A\00"
@.str.2 = [46 x i8] c"N.B. files must exist, touch them if needed'\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [188 x i8]
%4 = getelementptr inbounds [188 x i8], [188 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 3
br i1 %5, label %6, label %36
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %7
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %50
16: ; preds = %6
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_WRONLY
%20 = tail call i32 @open(i8* %18, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %17
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %50
26: ; preds = %16
%27 = getelementptr inbounds i8*, i8** %1, i64 3
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_WRONLY
%30 = tail call i32 @open(i8* %28, i32 %29)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %27
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %34)
br label %50
36: ; preds = %2
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
br label %50
41: ; preds = %26, %41
%42 = call i32 @read(i32 %10, i8* %4, i32 188)
%43 = call i32 @write(i32 %20, i8* %4, i32 188)
%44 = call i32 @write(i32 %30, i8* %4, i32 188)
%45 = icmp eq i32 %42, 0
br i1 %45, label %46, label %41
46: ; preds = %41
%47 = tail call i32 @close(i32 %10)
%48 = tail call i32 @close(i32 %20)
%49 = tail call i32 @close(i32 %30)
br label %50
50: ; preds = %46, %36, %32, %22, %12
ret i32 0
}