#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ time_stop;
typedef int /*<<< orphan*/ time_start;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct timespec {
  int tv_nsec;
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr_in {
  int tv_nsec;
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ nano_sleep_packet;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_STREAM;
unsigned int atoi(char *);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ htons(unsigned int);
int /*<<< orphan*/ inet_addr(char *);
unsigned char *malloc(unsigned long);
int /*<<< orphan*/ memset(struct timespec *, int /*<<< orphan*/, int);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, unsigned long);
int send(int, unsigned char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strtoul(char *, int /*<<< orphan*/, int /*<<< orphan*/);
unsigned long long usecDiff(struct timespec *, struct timespec *);
int main(int argc, char *argv[]) {
  int sockfd;
  int len;
  int rc;
  int sent;
  int transport_fd;
  struct sockaddr_in addr;
  unsigned long int packet_size;
  char *tsfile;
  unsigned char *send_buf;
  unsigned int bitrate;
  unsigned long long int packet_time;
  unsigned long long int real_time;
  struct timespec time_start;
  struct timespec time_stop;
  struct timespec nano_sleep_packet;
  memset(&addr, 0, sizeof(addr));
  memset(&time_start, 0, sizeof(time_start));
  memset(&time_stop, 0, sizeof(time_stop));
  memset(&nano_sleep_packet, 0, sizeof(nano_sleep_packet));
  if (argc < 5) {
    fprintf(stderr,
            "Usage: %s file.ts ipaddr port bitrate [ts_packet_per_ip_packet]\n",
            argv[0]);
    fprintf(stderr, "ts_packet_per_ip_packet default is 7\n");
    fprintf(stderr, "bit rate refers to transport stream bit rate\n");
    fprintf(stderr, "zero bitrate is 100.000.000 bps\n");
    return 0;
  } else {
    tsfile = argv[1];
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = inet_addr(argv[2]);
    addr.sin_port = htons(atoi(argv[3]));
    bitrate = atoi(argv[4]);
    if (bitrate <= 0) {
      bitrate = 100000000;
    }
    if (argc >= 6) {
      packet_size = strtoul(argv[5], 0, 0) * 188;
    } else {
      packet_size = 7 * 188;
    }
  }
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    fprintf(stderr, "socket(): error ");
    return 0;
  }
  transport_fd = open(tsfile, O_RDONLY);
  if (transport_fd < 0) {
    fprintf(stderr, "can't open file %s\n", tsfile);
    close(sockfd);
    return 0;
  }
  rc = connect(sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in));
  if (rc < 0) {
    fprintf(stderr, "connect() error\n");
    close(transport_fd);
    close(sockfd);
    return 0;
  } else {
    fprintf(stderr, "connect successful\n");
  }
  int completed = 0;
  send_buf = malloc(packet_size);
  packet_time = 0;
  real_time = 0;
  nano_sleep_packet.tv_nsec = 665778;
  clock_gettime(CLOCK_MONOTONIC, &time_start);
  while (!completed) {
    clock_gettime(CLOCK_MONOTONIC, &time_stop);
    real_time = usecDiff(&time_stop, &time_start);
    if (real_time * bitrate > packet_time * 1000000) {
      len = read(transport_fd, send_buf, packet_size);
      if (len < 0) {
        fprintf(stderr, "ts file read error \n");
        completed = 1;
      } else if (len == 0) {
        fprintf(stderr, "ts sent done\n");
        completed = 1;
      } else {
        sent = send(sockfd, send_buf, len, 0);
        if (sent <= 0) {
          fprintf(stderr, "send(): error ");
          completed = 1;
        } else {
          packet_time += packet_size * 8;
        }
      }
    } else {
      nanosleep(&nano_sleep_packet, 0);
    }
  }
  close(transport_fd);
  close(sockfd);
  free(send_buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    -0x78(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    -0x88(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    -0x98(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
cmpl   $0x5,-0x8(%rbp)
jge    12e8 <main+0xd8>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    162a <main+0x41a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
ja     1348 <main+0x138>
movl   $0x5f5e100,-0x54(%rbp)
cmpl   $0x6,-0x8(%rbp)
jl     1374 <main+0x164>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1100 <strtoul@plt>
imul   $0xbc,%eax,%eax
cltq
mov    %rax,-0x40(%rbp)
jmp    137c <main+0x16c>
movq   $0x524,-0x40(%rbp)
jmp    1381 <main+0x171>
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
mov    0x2c2f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    13ca <main+0x1ba>
mov    0x2c1a(%rip),%rax
mov    (%rax),%edi
lea    0xcff(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    162a <main+0x41a>
mov    -0x48(%rbp),%rdi
mov    0x2c0b(%rip),%rax
mov    (%rax),%esi
call   10f0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1418 <main+0x208>
mov    0x2bd8(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
lea    0xcca(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    162a <main+0x41a>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   1120 <connect@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1469 <main+0x259>
mov    0x2b8b(%rip),%rax
mov    (%rax),%edi
lea    0xc95(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    162a <main+0x41a>
mov    0x2b58(%rip),%rax
mov    (%rax),%edi
lea    0xc73(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x0,-0x9c(%rbp)
mov    -0x40(%rbp),%rdi
call   10e0 <malloc@plt>
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movl   $0xa28b2,-0x98(%rbp)
mov    0x2b20(%rip),%rax
mov    (%rax),%edi
lea    -0x78(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmpl   $0x0,-0x9c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    14dc <main+0x2cc>
jmp    160a <main+0x3fa>
mov    0x2af5(%rip),%rax
mov    (%rax),%edi
lea    -0x88(%rbp),%rsi
call   1040 <clock_gettime@plt>
lea    -0x88(%rbp),%rdi
lea    -0x78(%rbp),%rsi
call   10d0 <usecDiff@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
mov    -0x54(%rbp),%ecx
imul   %rcx,%rax
imul   $0xf4240,-0x60(%rbp),%rcx
cmp    %rcx,%rax
jbe    15f7 <main+0x3e7>
mov    -0x24(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   10a0 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1564 <main+0x354>
mov    0x2a83(%rip),%rax
mov    (%rax),%edi
lea    0xbb2(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0x9c(%rbp)
jmp    15f2 <main+0x3e2>
cmpl   $0x0,-0x18(%rbp)
jne    1594 <main+0x384>
mov    0x2a53(%rip),%rax
mov    (%rax),%edi
lea    0xb97(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0x9c(%rbp)
jmp    15ed <main+0x3dd>
mov    -0x14(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x18(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     15d8 <main+0x3c8>
mov    0x2a0f(%rip),%rax
mov    (%rax),%edi
lea    0xb61(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0x9c(%rbp)
jmp    15e8 <main+0x3d8>
mov    -0x40(%rbp),%rax
shl    $0x3,%rax
add    -0x60(%rbp),%rax
mov    %rax,-0x60(%rbp)
jmp    15ed <main+0x3dd>
jmp    15f2 <main+0x3e2>
jmp    1605 <main+0x3f5>
lea    -0x98(%rbp),%rdi
xor    %esi,%esi
call   1070 <nanosleep@plt>
jmp    14c3 <main+0x2b3>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    0x58(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    0x48(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    0x38(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
cmp    $0x4,%ebp
jg     12b8 <main+0xa8>
mov    0x2d55(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xd80(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xdb0(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xdc5(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xde2(%rip),%rsi
jmp    1489 <main+0x279>
mov    0x8(%rbx),%r12
mov    0x2d25(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x24(%rsp)
mov    0x10(%rbx),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x20(%rsp)
mov    0x18(%rbx),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x1c(%rsp)
mov    0x20(%rbx),%rdi
call   1110 <atoi@plt>
test   %eax,%eax
mov    $0x5f5e100,%r14d
cmovne %eax,%r14d
mov    $0x524,%eax
mov    %rax,0x8(%rsp)
cmp    $0x5,%ebp
je     1329 <main+0x119>
mov    0x28(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1100 <strtoul@plt>
imul   $0xbc,%eax,%eax
cltq
mov    %rax,0x8(%rsp)
mov    (%r15),%edi
mov    0x2c8d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
js     1479 <main+0x269>
mov    %eax,%ebx
mov    0x2c93(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   10f0 <open@plt>
mov    %eax,(%rsp)
test   %eax,%eax
js     1495 <main+0x285>
lea    0x18(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1120 <connect@plt>
mov    0x2c4e(%rip),%rcx
mov    (%rcx),%edi
test   %eax,%eax
js     14b1 <main+0x2a1>
mov    %ebx,0x4(%rsp)
lea    0xd5d(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x8(%rsp),%r15
mov    %r15,%rdi
call   10e0 <malloc@plt>
mov    %rax,0x10(%rsp)
movl   $0xa28b2,0x38(%rsp)
mov    0x2c21(%rip),%r13
mov    0x0(%r13),%edi
lea    0x58(%rsp),%rbp
mov    %rbp,%rsi
call   1040 <clock_gettime@plt>
xor    %eax,%eax
mov    %r14d,%ebx
lea    0x0(,%r15,8),%rcx
mov    %rcx,0x28(%rsp)
lea    0x48(%rsp),%r12
lea    0x38(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,0x30(%rsp)
imul   $0xf4240,%rax,%r15
nopl   0x0(%rax)
mov    0x0(%r13),%edi
mov    %r12,%rsi
call   1040 <clock_gettime@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   10d0 <usecDiff@plt>
imul   %rbx,%rax
cmp    %r15,%rax
ja     1430 <main+0x220>
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <nanosleep@plt>
jmp    1400 <main+0x1f0>
nopl   0x0(%rax)
mov    (%rsp),%edi
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
call   10a0 <read@plt>
test   %eax,%eax
js     14d0 <main+0x2c0>
mov    0x4(%rsp),%r15d
je     14de <main+0x2ce>
mov    %r15d,%edi
mov    0x10(%rsp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
jle    14e7 <main+0x2d7>
mov    0x30(%rsp),%rax
add    0x28(%rsp),%rax
jmp    13f0 <main+0x1e0>
mov    0x2b48(%rip),%rax
mov    (%rax),%edi
lea    0xc2d(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    1518 <main+0x308>
mov    0x2b2c(%rip),%rax
mov    (%rax),%edi
lea    0xc22(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    14c7 <main+0x2b7>
lea    0xc23(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%rsp),%edi
call   1090 <close@plt>
mov    %ebx,%edi
call   1090 <close@plt>
jmp    1518 <main+0x308>
mov    0x4(%rsp),%r15d
lea    0xc24(%rip),%rsi
jmp    14ee <main+0x2de>
lea    0xc30(%rip),%rsi
jmp    14ee <main+0x2de>
lea    0xc35(%rip),%rsi
mov    0x2ad3(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%rsp),%edi
call   1090 <close@plt>
mov    %r15d,%edi
call   1090 <close@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timespec = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [65 x i8] c"Usage: %s file.ts ipaddr port bitrate [ts_packet_per_ip_packet]\0A\00"
@.str.1 = [38 x i8] c"ts_packet_per_ip_packet default is 7\0A\00"
@.str.2 = [46 x i8] c"bit rate refers to transport stream bit rate\0A\00"
@.str.3 = [33 x i8] c"zero bitrate is 100.000.000 bps\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [17 x i8] c"socket(): error \00"
@O_RDONLY = global i32 0
@.str.5 = [20 x i8] c"can't open file %s\0A\00"
@.str.6 = [17 x i8] c"connect() error\0A\00"
@.str.7 = [20 x i8] c"connect successful\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.8 = [21 x i8] c"ts file read error \0A\00"
@.str.9 = [14 x i8] c"ts sent done\0A\00"
@.str.10 = [15 x i8] c"send(): error \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 i32
%11 = alloca %struct.sockaddr_in
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i64
%17 = alloca i64
%18 = alloca %struct.timespec
%19 = alloca %struct.timespec
%20 = alloca %struct.timespec
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = bitcast %struct.sockaddr_in* %11 to %struct.timespec*
%23 = call i32 @memset(%struct.timespec* %22, i32 0, i32 16)
%24 = call i32 @memset(%struct.timespec* %18, i32 0, i32 16)
%25 = call i32 @memset(%struct.timespec* %19, i32 0, i32 16)
%26 = call i32 @memset(%struct.timespec* %20, i32 0, i32 16)
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 5
br i1 %28, label %29, label %41
29: ; preds = %2
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %180
41: ; preds = %2
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
store i8* %44, i8** %13
%45 = load i32, i32* @AF_INET
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 3
store i32 %45, i32* %46
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i32 @inet_addr(i8* %49)
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
%52 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %51, i32 0, i32 0
store i32 %50, i32* %52
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 3
%55 = load i8*, i8** %54
%56 = call i32 @atoi(i8* %55)
%57 = call i32 @htons(i32 %56)
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %57, i32* %58
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 4
%61 = load i8*, i8** %60
%62 = call i32 @atoi(i8* %61)
store i32 %62, i32* %15
%63 = load i32, i32* %15
%64 = icmp ule i32 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %41
store i32 100000000, i32* %15
br label %66
66: ; preds = %65, %41
%67 = load i32, i32* %4
%68 = icmp sge i32 %67, 6
br i1 %68, label %69, label %76
69: ; preds = %66
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 5
%72 = load i8*, i8** %71
%73 = call i32 @strtoul(i8* %72, i32 0, i32 0)
%74 = mul nsw i32 %73, 188
%75 = sext i32 %74 to i64
store i64 %75, i64* %12
br label %77
76: ; preds = %66
store i64 1316, i64* %12
br label %77
77: ; preds = %76, %69
br label %78
78: ; preds = %77
%79 = load i32, i32* @AF_INET
%80 = load i32, i32* @SOCK_STREAM
%81 = call i32 @socket(i32 %79, i32 %80, i32 0)
store i32 %81, i32* %6
%82 = load i32, i32* %6
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %78
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %180
87: ; preds = %78
%88 = load i8*, i8** %13
%89 = load i32, i32* @O_RDONLY
%90 = call i32 @open(i8* %88, i32 %89)
store i32 %90, i32* %10
%91 = load i32, i32* %10
%92 = icmp slt i32 %91, 0
br i1 %92, label %93, label %99
93: ; preds = %87
%94 = load i32, i32* @stderr
%95 = load i8*, i8** %13
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %95)
%97 = load i32, i32* %6
%98 = call i32 @close(i32 %97)
store i32 0, i32* %3
br label %180
99: ; preds = %87
%100 = load i32, i32* %6
%101 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%102 = call i32 @connect(i32 %100, %struct.sockaddr* %101, i32 16)
store i32 %102, i32* %8
%103 = load i32, i32* %8
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %112
105: ; preds = %99
%106 = load i32, i32* @stderr
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%108 = load i32, i32* %10
%109 = call i32 @close(i32 %108)
%110 = load i32, i32* %6
%111 = call i32 @close(i32 %110)
store i32 0, i32* %3
br label %180
112: ; preds = %99
%113 = load i32, i32* @stderr
%114 = call i32 (i32, i8*, ...) @fprintf(i32 %113, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
br label %115
115: ; preds = %112
store i32 0, i32* %21
%116 = load i64, i64* %12
%117 = call i8* @malloc(i64 %116)
store i8* %117, i8** %14
store i64 0, i64* %16
store i64 0, i64* %17
%118 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 0
store i32 665778, i32* %118
%119 = load i32, i32* @CLOCK_MONOTONIC
%120 = call i32 @clock_gettime(i32 %119, %struct.timespec* %18)
br label %121
121: ; preds = %172, %115
%122 = load i32, i32* %21
%123 = icmp ne i32 %122, 0
%124 = xor i1 %123, true
br i1 %124, label %125, label %173
125: ; preds = %121
%126 = load i32, i32* @CLOCK_MONOTONIC
%127 = call i32 @clock_gettime(i32 %126, %struct.timespec* %19)
%128 = call i64 @usecDiff(%struct.timespec* %19, %struct.timespec* %18)
store i64 %128, i64* %17
%129 = load i64, i64* %17
%130 = load i32, i32* %15
%131 = zext i32 %130 to i64
%132 = mul i64 %129, %131
%133 = load i64, i64* %16
%134 = mul i64 %133, 1000000
%135 = icmp ugt i64 %132, %134
br i1 %135, label %136, label %170
136: ; preds = %125
%137 = load i32, i32* %10
%138 = load i8*, i8** %14
%139 = load i64, i64* %12
%140 = call i32 @read(i32 %137, i8* %138, i64 %139)
store i32 %140, i32* %7
%141 = load i32, i32* %7
%142 = icmp slt i32 %141, 0
br i1 %142, label %143, label %146
143: ; preds = %136
%144 = load i32, i32* @stderr
%145 = call i32 (i32, i8*, ...) @fprintf(i32 %144, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %21
br label %169
146: ; preds = %136
%147 = load i32, i32* %7
%148 = icmp eq i32 %147, 0
br i1 %148, label %149, label %152
149: ; preds = %146
%150 = load i32, i32* @stderr
%151 = call i32 (i32, i8*, ...) @fprintf(i32 %150, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %21
br label %168
152: ; preds = %146
%153 = load i32, i32* %6
%154 = load i8*, i8** %14
%155 = load i32, i32* %7
%156 = call i32 @send(i32 %153, i8* %154, i32 %155, i32 0)
store i32 %156, i32* %9
%157 = load i32, i32* %9
%158 = icmp sle i32 %157, 0
br i1 %158, label %159, label %162
159: ; preds = %152
%160 = load i32, i32* @stderr
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %160, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %21
br label %167
162: ; preds = %152
%163 = load i64, i64* %12
%164 = mul i64 %163, 8
%165 = load i64, i64* %16
%166 = add i64 %165, %164
store i64 %166, i64* %16
br label %167
167: ; preds = %162, %159
br label %168
168: ; preds = %167, %149
br label %169
169: ; preds = %168, %143
br label %172
170: ; preds = %125
%171 = call i32 @nanosleep(%struct.timespec* %20, i32 0)
br label %172
172: ; preds = %170, %169
br label %121
173: ; preds = %121
%174 = load i32, i32* %10
%175 = call i32 @close(i32 %174)
%176 = load i32, i32* %6
%177 = call i32 @close(i32 %176)
%178 = load i8*, i8** %14
%179 = call i32 @free(i8* %178)
store i32 0, i32* %3
br label %180
180: ; preds = %173, %105, %93, %84, %29
%181 = load i32, i32* %3
ret i32 %181
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timespec = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [65 x i8] c"Usage: %s file.ts ipaddr port bitrate [ts_packet_per_ip_packet]\0A\00"
@.str.1 = [38 x i8] c"ts_packet_per_ip_packet default is 7\0A\00"
@.str.2 = [46 x i8] c"bit rate refers to transport stream bit rate\0A\00"
@.str.3 = [33 x i8] c"zero bitrate is 100.000.000 bps\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [17 x i8] c"socket(): error \00"
@O_RDONLY = global i32 0
@.str.5 = [20 x i8] c"can't open file %s\0A\00"
@.str.6 = [17 x i8] c"connect() error\0A\00"
@.str.7 = [20 x i8] c"connect successful\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.8 = [21 x i8] c"ts file read error \0A\00"
@.str.9 = [14 x i8] c"ts sent done\0A\00"
@.str.10 = [15 x i8] c"send(): error \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
%6 = alloca %struct.timespec
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.timespec* %4 to i8*
%9 = bitcast %struct.timespec* %5 to i8*
%10 = bitcast %struct.timespec* %6 to i8*
%11 = bitcast %struct.sockaddr_in* %3 to %struct.timespec*
%12 = call i32 @memset(%struct.timespec* %11, i32 0, i32 16)
%13 = call i32 @memset(%struct.timespec* %4, i32 0, i32 16)
%14 = call i32 @memset(%struct.timespec* %5, i32 0, i32 16)
%15 = call i32 @memset(%struct.timespec* %6, i32 0, i32 16)
%16 = icmp slt i32 %0, 5
br i1 %16, label %17, label %27
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %115
27: ; preds = %2
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %30, i32* %31
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @inet_addr(i8* %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i32 %34, i32* %35
%36 = getelementptr inbounds i8*, i8** %1, i64 3
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
%39 = call i32 @htons(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %39, i32* %40
%41 = getelementptr inbounds i8*, i8** %1, i64 4
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i32 100000000, i32 %43
%46 = icmp eq i32 %0, 5
br i1 %46, label %53, label %47
47: ; preds = %27
%48 = getelementptr inbounds i8*, i8** %1, i64 5
%49 = load i8*, i8** %48
%50 = call i32 @strtoul(i8* %49, i32 0, i32 0)
%51 = mul nsw i32 %50, 188
%52 = sext i32 %51 to i64
br label %53
53: ; preds = %27, %47
%54 = phi i64 [ %52, %47 ], [ 1316, %27 ]
%55 = load i32, i32* @AF_INET
%56 = load i32, i32* @SOCK_STREAM
%57 = call i32 @socket(i32 %55, i32 %56, i32 0)
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %115
62: ; preds = %53
%63 = load i32, i32* @O_RDONLY
%64 = call i32 @open(i8* %29, i32 %63)
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %62
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %29)
%69 = call i32 @close(i32 %57)
br label %115
70: ; preds = %62
%71 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%72 = call i32 @connect(i32 %57, %struct.sockaddr* %71, i32 16)
%73 = icmp slt i32 %72, 0
%74 = load i32, i32* @stderr
br i1 %73, label %75, label %79
75: ; preds = %70
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%77 = call i32 @close(i32 %64)
%78 = call i32 @close(i32 %57)
br label %115
79: ; preds = %70
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%81 = call i8* @malloc(i64 %54)
%82 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 0
store i32 665778, i32* %82
%83 = load i32, i32* @CLOCK_MONOTONIC
%84 = call i32 @clock_gettime(i32 %83, %struct.timespec* %4)
%85 = zext i32 %45 to i64
%86 = shl nsw i64 %54, 3
br label %87
87: ; preds = %104, %79
%88 = phi i64 [ %105, %104 ], [ 0, %79 ]
%89 = mul i64 %88, 1000000
br label %90
90: ; preds = %87, %106
%91 = load i32, i32* @CLOCK_MONOTONIC
%92 = call i32 @clock_gettime(i32 %91, %struct.timespec* %5)
%93 = call i64 @usecDiff(%struct.timespec* %5, %struct.timespec* %4)
%94 = mul i64 %93, %85
%95 = icmp ugt i64 %94, %89
br i1 %95, label %96, label %106
96: ; preds = %90
%97 = call i32 @read(i32 %64, i8* %81, i64 %54)
%98 = icmp slt i32 %97, 0
br i1 %98, label %108, label %99
99: ; preds = %96
%100 = icmp eq i32 %97, 0
br i1 %100, label %108, label %101
101: ; preds = %99
%102 = call i32 @send(i32 %57, i8* %81, i32 %97, i32 0)
%103 = icmp slt i32 %102, 1
br i1 %103, label %108, label %104
104: ; preds = %101
%105 = add i64 %88, %86
br label %87
106: ; preds = %90
%107 = call i32 @nanosleep(%struct.timespec* %6, i32 0)
br label %90
108: ; preds = %101, %99, %96
%109 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), %96 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), %99 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), %101 ]
%110 = load i32, i32* @stderr
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* %109)
%112 = call i32 @close(i32 %64)
%113 = call i32 @close(i32 %57)
%114 = call i32 @free(i8* %81)
br label %115
115: ; preds = %108, %75, %66, %59, %17
ret i32 0
}