#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*/ STDOUT_FILENO;
unsigned int atoi(char *);
unsigned long long atol(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned char *malloc(unsigned int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, unsigned int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int /*<<< orphan*/, unsigned char *, int);
int main(int argc, char *argv[]) {
  int fd_ts;
  int byte_read;
  unsigned int i;
  unsigned int input_buffer_size;
  unsigned int output_buffer_size;
  unsigned long long int ibits;
  unsigned long long int obits;
  unsigned long long int icounter;
  unsigned long long int ocounter;
  unsigned long long int last_ocounter;
  unsigned char *input_packet_buffer;
  unsigned char *output_packet_buffer;
  unsigned char *current_input_packet;
  unsigned char *current_output_packet;
  unsigned char null_ts_packet[188];
  input_buffer_size = 0;
  if (argc >= 4)
    fd_ts = open(argv[1], O_RDONLY);
  else {
    fprintf(stderr, "Usage: 'tsnullfiller input.ts output_bit/s input_bit/s "
                    "[packet_buffer]'\n");
    fprintf(stderr, "adds empty packets to input.ts to reach output_bit/s\n");
    return 2;
  }
  if (fd_ts < 0) {
    fprintf(stderr, "Can't find file %s\n", argv[1]);
    return 2;
  }
  obits = atol(argv[2]);
  if (obits == 0) {
    fprintf(stderr, "0 output_bit/s?\n");
    return 2;
  }
  ibits = atol(argv[3]);
  if (ibits == 0) {
    fprintf(stderr, "0 input_bit/s?\n");
    return 2;
  }
  if (obits <= ibits) {
    fprintf(stderr, "output rate has to be bigger\n");
    return 2;
  }
  if (argv[4] != NULL) {
    input_buffer_size = atoi(argv[4]);
    if (input_buffer_size == 0) {
      fprintf(stderr, "buffer size is not valid\n");
      return 2;
    }
  } else {
    input_buffer_size = 1;
  }
  output_buffer_size = (input_buffer_size * obits / ibits) + 1;
  input_buffer_size *= 188;
  output_buffer_size *= 188;
  input_packet_buffer = malloc(input_buffer_size);
  output_packet_buffer = malloc(output_buffer_size);
  if (input_packet_buffer == NULL || output_packet_buffer == NULL) {
    fprintf(stderr, "Out of memory\n");
    return 2;
  }
  memset(null_ts_packet, 0, 188);
  null_ts_packet[0] = 0x47;
  null_ts_packet[1] = 0x1F;
  null_ts_packet[2] = 0xFF;
  null_ts_packet[3] = 0x10;
  icounter = 0;
  ocounter = 0;
  byte_read = 1;
  while (byte_read) {
    byte_read = read(fd_ts, input_packet_buffer, input_buffer_size);
    current_input_packet = input_packet_buffer;
    current_output_packet = output_packet_buffer;
    for (i = 0; i < input_buffer_size; i += 188) {
      current_input_packet = input_packet_buffer + i;
      memcpy(current_output_packet, current_input_packet, 188);
      current_output_packet += 188;
      icounter += 188 * 8;
      ocounter += 188 * 8;
      while (((ocounter + 188 * 8) * ibits) <= (icounter * obits)) {
        memcpy(current_output_packet, null_ts_packet, 188);
        current_output_packet += 188;
        last_ocounter = ocounter;
        ocounter += 188 * 8;
        if (last_ocounter > ocounter) {
          last_ocounter = last_ocounter - icounter;
          icounter = 0;
          ocounter = last_ocounter + 188 * 8;
        }
      }
    }
    write(STDOUT_FILENO, output_packet_buffer,
          current_output_packet - output_packet_buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     11d8 <main+0x48>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
jmp    1212 <main+0x82>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1568 <main+0x3d8>
cmpl   $0x0,-0x14(%rbp)
jge    1247 <main+0xb7>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1568 <main+0x3d8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atol@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1286 <main+0xf6>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1568 <main+0x3d8>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atol@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12c5 <main+0x135>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1568 <main+0x3d8>
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
ja     12f6 <main+0x166>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1568 <main+0x3d8>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x20(%rax)
je     1347 <main+0x1b7>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1342 <main+0x1b2>
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1568 <main+0x3d8>
jmp    134e <main+0x1be>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x38(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x30(%rbp)
add    $0x1,%rax
mov    %eax,-0x24(%rbp)
imul   $0xbc,-0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
imul   $0xbc,-0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     13a7 <main+0x217>
cmpq   $0x0,-0x60(%rbp)
jne    13ca <main+0x23a>
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1568 <main+0x3d8>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0xbc,%edx
call   1040 <memset@plt>
movb   $0x47,-0x130(%rbp)
movb   $0x1f,-0x12f(%rbp)
movb   $0xff,-0x12e(%rbp)
movb   $0x10,-0x12d(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1561 <main+0x3d1>
mov    -0x14(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    153d <main+0x3ad>
mov    -0x58(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    $0xbc,%edx
call   1070 <memcpy@plt>
mov    -0x70(%rbp),%rax
add    $0xbc,%rax
mov    %rax,-0x70(%rbp)
mov    -0x40(%rbp),%rax
add    $0x5e0,%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
add    $0x5e0,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0x5e0,%rax
imul   -0x30(%rbp),%rax
mov    -0x40(%rbp),%rcx
imul   -0x38(%rbp),%rcx
cmp    %rcx,%rax
ja     1528 <main+0x398>
mov    -0x70(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    $0xbc,%edx
call   1070 <memcpy@plt>
mov    -0x70(%rbp),%rax
add    $0xbc,%rax
mov    %rax,-0x70(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
add    $0x5e0,%rax
mov    %rax,-0x48(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x48(%rbp),%rax
jbe    1523 <main+0x393>
mov    -0x50(%rbp),%rax
sub    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x50(%rbp),%rax
add    $0x5e0,%rax
mov    %rax,-0x48(%rbp)
jmp    1499 <main+0x309>
jmp    152d <main+0x39d>
mov    -0x1c(%rbp),%eax
add    $0xbc,%eax
mov    %eax,-0x1c(%rbp)
jmp    1443 <main+0x2b3>
mov    0x2aac(%rip),%rax
mov    (%rax),%edi
mov    -0x60(%rbp),%rsi
mov    -0x70(%rbp),%rax
mov    -0x60(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <write@plt>
jmp    1410 <main+0x280>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
cmp    $0x4,%edi
jl     122b <main+0x9b>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
test   %eax,%eax
js     1269 <main+0xd9>
mov    %eax,%r13d
mov    0x10(%r14),%rdi
call   1090 <atol@plt>
test   %rax,%rax
je     1286 <main+0xf6>
mov    %rax,%rbp
mov    0x18(%r14),%rdi
call   1090 <atol@plt>
test   %rax,%rax
je     1298 <main+0x108>
mov    %rax,%r15
cmp    %rax,%rbp
jbe    12aa <main+0x11a>
mov    0x20(%r14),%rdi
test   %rdi,%rdi
je     12bc <main+0x12c>
call   10b0 <atoi@plt>
mov    %eax,%ecx
test   %eax,%eax
jne    12c1 <main+0x131>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
jmp    124b <main+0xbb>
mov    0x2d9e(%rip),%rbx
mov    (%rbx),%edi
lea    0xdc5(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdfe(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe02(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1252 <main+0xc2>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
jmp    124b <main+0xbb>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
jmp    124b <main+0xbb>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
jmp    124b <main+0xbb>
mov    $0x1,%ecx
mov    %ecx,%eax
imul   %rbp,%rax
mov    %rax,%rdx
or     %r15,%rdx
shr    $0x20,%rdx
je     12da <main+0x14a>
xor    %edx,%edx
div    %r15
jmp    12df <main+0x14f>
xor    %edx,%edx
div    %r15d
imul   $0xbc,%ecx,%edi
imul   $0xbc,%eax,%r14d
add    $0xbc,%r14d
mov    %edi,(%rsp)
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %r14d,%edi
call   1080 <malloc@plt>
mov    %r12,0x10(%rsp)
test   %r12,%r12
je     1498 <main+0x308>
mov    %rax,%rbx
test   %rax,%rax
je     1498 <main+0x308>
mov    %r15,0x18(%rsp)
mov    %rbp,0x20(%rsp)
lea    0x30(%rsp),%rdi
xor    %r12d,%r12d
xor    %esi,%esi
mov    $0xbc,%edx
call   1040 <memset@plt>
movl   $0x10ff1f47,0x30(%rsp)
10
xor    %r15d,%r15d
mov    %r13d,%r14d
mov    %r13d,0x4(%rsp)
mov    %rbx,0x28(%rsp)
jmp    138e <main+0x1fe>
nopl   0x0(%rax,%rax,1)
mov    0x4(%rsp),%r14d
mov    0x28(%rsp),%rbx
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
sub    %ebx,%r13d
mov    %rbx,%rsi
mov    %r13d,%edx
call   1030 <write@plt>
xor    %eax,%eax
cmpl   $0x0,0x8(%rsp)
je     1257 <main+0xc7>
mov    %r14d,%edi
mov    0x10(%rsp),%rsi
mov    (%rsp),%ebp
mov    %ebp,%edx
call   1050 <read@plt>
test   %ebp,%ebp
mov    %eax,0x8(%rsp)
je     1490 <main+0x300>
xor    %eax,%eax
mov    %rbx,%r13
jmp    13d1 <main+0x241>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%r12
mov    0xc(%rsp),%eax
add    $0xbc,%eax
cmp    (%rsp),%eax
jae    1360 <main+0x1d0>
mov    %eax,0xc(%rsp)
mov    %eax,%esi
add    0x10(%rsp),%rsi
mov    %r13,%rdi
mov    $0xbc,%edx
call   1070 <memcpy@plt>
add    $0x5e0,%r15
lea    0x5e0(%r12),%rbp
add    $0xbc,%r13
mov    %r12,%rbx
add    $0xbc0,%rbx
mov    %rbx,%rax
imul   0x18(%rsp),%rax
mov    %r15,%rcx
imul   0x20(%rsp),%rcx
cmp    %rcx,%rax
ja     13c0 <main+0x230>
mov    %rbp,%r12
lea    0x30(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0xbc,%edx
call   1070 <memcpy@plt>
sub    %r15,%r12
add    $0x5e0,%r12
cmp    $0xfffffffffffffa20,%rbp
mov    $0x0,%eax
cmovae %rax,%r15
cmovb  %rbx,%r12
add    $0xbc,%r13
lea    0x5e0(%r12),%rbx
mov    %rbx,%rax
imul   0x18(%rsp),%rax
mov    %r15,%rcx
imul   0x20(%rsp),%rcx
mov    %r12,%rbp
cmp    %rcx,%rax
jbe    1430 <main+0x2a0>
jmp    13c3 <main+0x233>
nopl   0x0(%rax)
mov    %rbx,%r13
jmp    136a <main+0x1da>
mov    0x2b31(%rip),%rax
mov    (%rax),%edi
lea    0xc44(%rip),%rsi
jmp    124b <main+0xbb>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [73 x i8] c"Usage: 'tsnullfiller input.ts output_bit/s input_bit/s [packet_buffer]'\0A\00"
@.str.1 = [54 x i8] c"adds empty packets to input.ts to reach output_bit/s\0A\00"
@.str.2 = [20 x i8] c"Can't find file %s\0A\00"
@.str.3 = [17 x i8] c"0 output_bit/s?\0A\00"
@.str.4 = [16 x i8] c"0 input_bit/s?\0A\00"
@.str.5 = [30 x i8] c"output rate has to be bigger\0A\00"
@.str.6 = [26 x i8] c"buffer size is not valid\0A\00"
@.str.7 = [15 x i8] c"Out of memory\0A\00"
@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 i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca [188 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%21 = load i32, i32* %4
%22 = icmp sge i32 %21, 4
br i1 %22, label %23, label %29
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* %6
br label %34
29: ; preds = %2
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %190
34: ; preds = %23
%35 = load i32, i32* %6
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %41)
store i32 2, i32* %3
br label %190
43: ; preds = %34
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i64 @atol(i8* %46)
store i64 %47, i64* %12
%48 = load i64, i64* %12
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %43
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %190
53: ; preds = %43
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 3
%56 = load i8*, i8** %55
%57 = call i64 @atol(i8* %56)
store i64 %57, i64* %11
%58 = load i64, i64* %11
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %53
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %190
63: ; preds = %53
%64 = load i64, i64* %12
%65 = load i64, i64* %11
%66 = icmp ule i64 %64, %65
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
br label %190
70: ; preds = %63
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 4
%73 = load i8*, i8** %72
%74 = icmp ne i8* %73, null
br i1 %74, label %75, label %86
75: ; preds = %70
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 4
%78 = load i8*, i8** %77
%79 = call i32 @atoi(i8* %78)
store i32 %79, i32* %9
%80 = load i32, i32* %9
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %75
%83 = load i32, i32* @stderr
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i32 2, i32* %3
br label %190
85: ; preds = %75
br label %87
86: ; preds = %70
store i32 1, i32* %9
br label %87
87: ; preds = %86, %85
%88 = load i32, i32* %9
%89 = zext i32 %88 to i64
%90 = load i64, i64* %12
%91 = mul i64 %89, %90
%92 = load i64, i64* %11
%93 = udiv i64 %91, %92
%94 = add i64 %93, 1
%95 = trunc i64 %94 to i32
store i32 %95, i32* %10
%96 = load i32, i32* %9
%97 = mul i32 %96, 188
store i32 %97, i32* %9
%98 = load i32, i32* %10
%99 = mul i32 %98, 188
store i32 %99, i32* %10
%100 = load i32, i32* %9
%101 = call i8* @malloc(i32 %100)
store i8* %101, i8** %16
%102 = load i32, i32* %10
%103 = call i8* @malloc(i32 %102)
store i8* %103, i8** %17
%104 = load i8*, i8** %16
%105 = icmp eq i8* %104, null
br i1 %105, label %109, label %106
106: ; preds = %87
%107 = load i8*, i8** %17
%108 = icmp eq i8* %107, null
br i1 %108, label %109, label %112
109: ; preds = %106, %87
%110 = load i32, i32* @stderr
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
store i32 2, i32* %3
br label %190
112: ; preds = %106
%113 = getelementptr inbounds [188 x i8], [188 x i8]* %20, i64 0, i64 0
%114 = call i32 @memset(i8* %113, i32 0, i32 188)
%115 = getelementptr inbounds [188 x i8], [188 x i8]* %20, i64 0, i64 0
store i8 71, i8* %115
%116 = getelementptr inbounds [188 x i8], [188 x i8]* %20, i64 0, i64 1
store i8 31, i8* %116
%117 = getelementptr inbounds [188 x i8], [188 x i8]* %20, i64 0, i64 2
store i8 -1, i8* %117
%118 = getelementptr inbounds [188 x i8], [188 x i8]* %20, i64 0, i64 3
store i8 16, i8* %118
store i64 0, i64* %13
store i64 0, i64* %14
store i32 1, i32* %7
br label %119
119: ; preds = %179, %112
%120 = load i32, i32* %7
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %189
122: ; preds = %119
%123 = load i32, i32* %6
%124 = load i8*, i8** %16
%125 = load i32, i32* %9
%126 = call i32 @read(i32 %123, i8* %124, i32 %125)
store i32 %126, i32* %7
%127 = load i8*, i8** %16
store i8* %127, i8** %18
%128 = load i8*, i8** %17
store i8* %128, i8** %19
store i32 0, i32* %8
br label %129
129: ; preds = %176, %122
%130 = load i32, i32* %8
%131 = load i32, i32* %9
%132 = icmp ult i32 %130, %131
br i1 %132, label %133, label %179
133: ; preds = %129
%134 = load i8*, i8** %16
%135 = load i32, i32* %8
%136 = zext i32 %135 to i64
%137 = getelementptr inbounds i8, i8* %134, i64 %136
store i8* %137, i8** %18
%138 = load i8*, i8** %19
%139 = load i8*, i8** %18
%140 = call i32 @memcpy(i8* %138, i8* %139, i32 188)
%141 = load i8*, i8** %19
%142 = getelementptr inbounds i8, i8* %141, i64 188
store i8* %142, i8** %19
%143 = load i64, i64* %13
%144 = add i64 %143, 1504
store i64 %144, i64* %13
%145 = load i64, i64* %14
%146 = add i64 %145, 1504
store i64 %146, i64* %14
br label %147
147: ; preds = %174, %133
%148 = load i64, i64* %14
%149 = add i64 %148, 1504
%150 = load i64, i64* %11
%151 = mul i64 %149, %150
%152 = load i64, i64* %13
%153 = load i64, i64* %12
%154 = mul i64 %152, %153
%155 = icmp ule i64 %151, %154
br i1 %155, label %156, label %175
156: ; preds = %147
%157 = load i8*, i8** %19
%158 = getelementptr inbounds [188 x i8], [188 x i8]* %20, i64 0, i64 0
%159 = call i32 @memcpy(i8* %157, i8* %158, i32 188)
%160 = load i8*, i8** %19
%161 = getelementptr inbounds i8, i8* %160, i64 188
store i8* %161, i8** %19
%162 = load i64, i64* %14
store i64 %162, i64* %15
%163 = load i64, i64* %14
%164 = add i64 %163, 1504
store i64 %164, i64* %14
%165 = load i64, i64* %15
%166 = load i64, i64* %14
%167 = icmp ugt i64 %165, %166
br i1 %167, label %168, label %174
168: ; preds = %156
%169 = load i64, i64* %15
%170 = load i64, i64* %13
%171 = sub i64 %169, %170
store i64 %171, i64* %15
store i64 0, i64* %13
%172 = load i64, i64* %15
%173 = add i64 %172, 1504
store i64 %173, i64* %14
br label %174
174: ; preds = %168, %156
br label %147
175: ; preds = %147
br label %176
176: ; preds = %175
%177 = load i32, i32* %8
%178 = add i32 %177, 188
store i32 %178, i32* %8
br label %129
179: ; preds = %129
%180 = load i32, i32* @STDOUT_FILENO
%181 = load i8*, i8** %17
%182 = load i8*, i8** %19
%183 = load i8*, i8** %17
%184 = ptrtoint i8* %182 to i64
%185 = ptrtoint i8* %183 to i64
%186 = sub i64 %184, %185
%187 = trunc i64 %186 to i32
%188 = call i32 @write(i32 %180, i8* %181, i32 %187)
br label %119
189: ; preds = %119
store i32 0, i32* %3
br label %190
190: ; preds = %189, %109, %82, %67, %60, %50, %37, %29
%191 = load i32, i32* %3
ret i32 %191
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [73 x i8] c"Usage: 'tsnullfiller input.ts output_bit/s input_bit/s [packet_buffer]'\0A\00"
@.str.1 = [54 x i8] c"adds empty packets to input.ts to reach output_bit/s\0A\00"
@.str.2 = [20 x i8] c"Can't find file %s\0A\00"
@.str.3 = [17 x i8] c"0 output_bit/s?\0A\00"
@.str.4 = [16 x i8] c"0 input_bit/s?\0A\00"
@.str.5 = [30 x i8] c"output rate has to be bigger\0A\00"
@.str.6 = [26 x i8] c"buffer size is not valid\0A\00"
@.str.7 = [15 x i8] c"Out of memory\0A\00"
@STDOUT_FILENO = global i32 0
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 %12
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 %17, label %21
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
br label %128
17: ; preds = %6
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %7
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %128
21: ; preds = %6
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i64 @atol(i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %128
29: ; preds = %21
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = tail call i64 @atol(i8* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %128
37: ; preds = %29
%38 = icmp ugt i64 %24, %32
br i1 %38, label %42, label %39
39: ; preds = %37
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %128
42: ; preds = %37
%43 = getelementptr inbounds i8*, i8** %1, i64 4
%44 = load i8*, i8** %43
%45 = icmp eq i8* %44, null
br i1 %45, label %52, label %46
46: ; preds = %42
%47 = tail call i32 @atoi(i8* %44)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %128
52: ; preds = %42, %46
%53 = phi i32 [ %47, %46 ], [ 1, %42 ]
%54 = zext i32 %53 to i64
%55 = mul i64 %24, %54
%56 = udiv i64 %55, %32
%57 = trunc i64 %56 to i32
%58 = mul i32 %53, 188
%59 = mul i32 %57, 188
%60 = add i32 %59, 188
%61 = tail call i8* @malloc(i32 %58)
%62 = tail call i8* @malloc(i32 %60)
%63 = icmp eq i8* %61, null
%64 = icmp eq i8* %62, null
%65 = or i1 %63, %64
br i1 %65, label %66, label %69
66: ; preds = %52
%67 = load i32, i32* @stderr
%68 = tail call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
br label %128
69: ; preds = %52
%70 = call i32 @memset(i8* %4, i32 0, i32 188)
store i8 71, i8* %4
%71 = getelementptr inbounds [188 x i8], [188 x i8]* %3, i64 0, i64 1
store i8 31, i8* %71
%72 = getelementptr inbounds [188 x i8], [188 x i8]* %3, i64 0, i64 2
store i8 -1, i8* %72
%73 = getelementptr inbounds [188 x i8], [188 x i8]* %3, i64 0, i64 3
store i8 16, i8* %73
%74 = icmp eq i32 %58, 0
%75 = ptrtoint i8* %62 to i64
br label %76
76: ; preds = %69, %119
%77 = phi i64 [ 0, %69 ], [ %122, %119 ]
%78 = phi i64 [ 0, %69 ], [ %121, %119 ]
%79 = call i32 @read(i32 %10, i8* %61, i32 %58)
br i1 %74, label %119, label %80
80: ; preds = %76, %111
%81 = phi i8* [ %114, %111 ], [ %62, %76 ]
%82 = phi i64 [ %113, %111 ], [ %77, %76 ]
%83 = phi i64 [ %112, %111 ], [ %78, %76 ]
%84 = phi i32 [ %115, %111 ], [ 0, %76 ]
%85 = zext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %61, i64 %85
%87 = call i32 @memcpy(i8* %81, i8* %86, i32 188)
%88 = add i64 %83, 1504
%89 = add i64 %82, 1504
%90 = getelementptr inbounds i8, i8* %81, i64 188
%91 = add i64 %82, 3008
%92 = mul i64 %91, %32
%93 = mul i64 %88, %24
%94 = icmp ugt i64 %92, %93
br i1 %94, label %111, label %95
95: ; preds = %80, %95
%96 = phi i64 [ %107, %95 ], [ %91, %80 ]
%97 = phi i8* [ %106, %95 ], [ %90, %80 ]
%98 = phi i64 [ %105, %95 ], [ %89, %80 ]
%99 = phi i64 [ %104, %95 ], [ %88, %80 ]
%100 = call i32 @memcpy(i8* %97, i8* %4, i32 188)
%101 = icmp ugt i64 %98, -1505
%102 = sub i64 1504, %99
%103 = add i64 %102, %98
%104 = select i1 %101, i64 0, i64 %99
%105 = select i1 %101, i64 %103, i64 %96
%106 = getelementptr inbounds i8, i8* %97, i64 188
%107 = add i64 %105, 1504
%108 = mul i64 %107, %32
%109 = mul i64 %104, %24
%110 = icmp ugt i64 %108, %109
br i1 %110, label %111, label %95
111: ; preds = %95, %80
%112 = phi i64 [ %88, %80 ], [ %104, %95 ]
%113 = phi i64 [ %89, %80 ], [ %105, %95 ]
%114 = phi i8* [ %90, %80 ], [ %106, %95 ]
%115 = add i32 %84, 188
%116 = icmp ult i32 %115, %58
br i1 %116, label %80, label %117
117: ; preds = %111
%118 = ptrtoint i8* %114 to i64
br label %119
119: ; preds = %117, %76
%120 = phi i64 [ %118, %117 ], [ %75, %76 ]
%121 = phi i64 [ %112, %117 ], [ %78, %76 ]
%122 = phi i64 [ %113, %117 ], [ %77, %76 ]
%123 = load i32, i32* @STDOUT_FILENO
%124 = sub i64 %120, %75
%125 = trunc i64 %124 to i32
%126 = call i32 @write(i32 %123, i8* %62, i32 %125)
%127 = icmp eq i32 %79, 0
br i1 %127, label %128, label %76
128: ; preds = %119, %66, %49, %39, %34, %26, %17, %12
%129 = phi i32 [ 2, %17 ], [ 2, %26 ], [ 2, %34 ], [ 2, %39 ], [ 2, %49 ], [ 2, %66 ], [ 2, %12 ], [ 0, %119 ]
ret i32 %129
}