#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*/ option_ttl;
typedef int /*<<< orphan*/ nano_sleep_packet;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_MULTICAST_TTL;
int /*<<< orphan*/ IP_TTL;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_DGRAM;
void *atoi(char *);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ htons(void *);
int /*<<< orphan*/ inet_addr(char *);
unsigned char *malloc(unsigned long);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(struct timespec *, int /*<<< orphan*/, int);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, unsigned char *, unsigned long);
int sendto(int, unsigned char *, int, int /*<<< orphan*/, struct sockaddr *,
           int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, unsigned char *,
               int);
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 sent;
  int ret;
  int is_multicast;
  int transport_fd;
  unsigned char option_ttl;
  char start_addr[4];
  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] "
            "[udp_packet_ttl]\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_DGRAM, 0);
  if (sockfd < 0) {
    perror("socket(): error ");
    return 0;
  }
  if (argc >= 7) {
    option_ttl = atoi(argv[6]);
    is_multicast = 0;
    memcpy(start_addr, argv[2], 3);
    start_addr[3] = 0;
    is_multicast = atoi(start_addr);
    is_multicast = (is_multicast >= 224) || (is_multicast <= 239);
    if (is_multicast) {
      ret = setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &option_ttl,
                       sizeof(option_ttl));
    } else {
      ret = setsockopt(sockfd, IPPROTO_IP, IP_TTL, &option_ttl,
                       sizeof(option_ttl));
    }
    if (ret < 0) {
      perror("ttl configuration fail");
    }
  }
  transport_fd = open(tsfile, O_RDONLY);
  if (transport_fd < 0) {
    fprintf(stderr, "can't open file %s\n", tsfile);
    close(sockfd);
    return 0;
  }
  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);
    while (real_time * bitrate > packet_time * 1000000 && !completed) {
      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 = sendto(sockfd, send_buf, len, 0, (struct sockaddr *)&addr,
                      sizeof(struct sockaddr_in));
        if (sent <= 0) {
          perror("send(): error ");
          completed = 1;
        } else {
          packet_time += packet_size * 8;
        }
      }
    }
    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    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
cmpl   $0x5,-0x8(%rbp)
jge    1308 <main+0xd8>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd50(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    16f6 <main+0x4c6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2ccd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1140 <atoi@plt>
mov    %rax,%rdi
call   1060 <htons@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1140 <atoi@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
ja     1369 <main+0x139>
movl   $0x5f5e100,-0x5c(%rbp)
cmpl   $0x6,-0x8(%rbp)
jl     1395 <main+0x165>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1130 <strtoul@plt>
imul   $0xbc,%eax,%eax
cltq
mov    %rax,-0x48(%rbp)
jmp    139d <main+0x16d>
movq   $0x524,-0x48(%rbp)
jmp    13a2 <main+0x172>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
mov    0x2c16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    13e0 <main+0x1b0>
lea    0xcf8(%rip),%rdi
call   1120 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    16f6 <main+0x4c6>
cmpl   $0x7,-0x8(%rbp)
jl     14d2 <main+0x2a2>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
call   1140 <atoi@plt>
mov    %al,-0x29(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x2d(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x3,%edx
call   10e0 <memcpy@plt>
movb   $0x0,-0x2a(%rbp)
lea    -0x2d(%rbp),%rdi
call   1140 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    $0x1,%al
cmpl   $0xe0,-0x24(%rbp)
mov    %al,-0xa5(%rbp)
jge    144c <main+0x21c>
cmpl   $0xef,-0x24(%rbp)
setle  %al
mov    %al,-0xa5(%rbp)
mov    -0xa5(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1490 <main+0x260>
mov    -0x14(%rbp),%edi
mov    0x2b6a(%rip),%rax
mov    (%rax),%esi
mov    0x2b39(%rip),%rax
mov    (%rax),%edx
lea    -0x29(%rbp),%rcx
mov    $0x1,%r8d
call   1040 <setsockopt@plt>
mov    %eax,-0x20(%rbp)
jmp    14b7 <main+0x287>
mov    -0x14(%rbp),%edi
mov    0x2b3e(%rip),%rax
mov    (%rax),%esi
mov    0x2afd(%rip),%rax
mov    (%rax),%edx
lea    -0x29(%rbp),%rcx
mov    $0x1,%r8d
call   1040 <setsockopt@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    14cd <main+0x29d>
lea    0xc10(%rip),%rdi
call   1120 <perror@plt>
jmp    14d2 <main+0x2a2>
mov    -0x50(%rbp),%rdi
mov    0x2b03(%rip),%rax
mov    (%rax),%esi
call   1110 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1520 <main+0x2f0>
mov    0x2ac0(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%rdx
lea    0xbea(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    16f6 <main+0x4c6>
movl   $0x0,-0xa4(%rbp)
mov    -0x48(%rbp),%rdi
call   1100 <malloc@plt>
mov    %rax,-0x58(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
movl   $0xa28b2,-0xa0(%rbp)
mov    0x2a78(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
call   1050 <clock_gettime@plt>
cmpl   $0x0,-0xa4(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    157c <main+0x34c>
jmp    16d6 <main+0x4a6>
mov    0x2a4d(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rsi
call   1050 <clock_gettime@plt>
lea    -0x90(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   10f0 <usecDiff@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rcx
mov    -0x5c(%rbp),%eax
imul   %rax,%rcx
imul   $0xf4240,-0x68(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0xa6(%rbp)
jbe    15db <main+0x3ab>
cmpl   $0x0,-0xa4(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0xa6(%rbp)
mov    -0xa6(%rbp),%al
test   $0x1,%al
jne    15ee <main+0x3be>
jmp    16c3 <main+0x493>
mov    -0x28(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   10b0 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1631 <main+0x401>
mov    0x29a6(%rip),%rax
mov    (%rax),%edi
lea    0xae8(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
movl   $0x1,-0xa4(%rbp)
jmp    16be <main+0x48e>
cmpl   $0x0,-0x18(%rbp)
jne    1661 <main+0x431>
mov    0x2976(%rip),%rax
mov    (%rax),%edi
lea    0xacd(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
movl   $0x1,-0xa4(%rbp)
jmp    16b9 <main+0x489>
mov    -0x14(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    -0x40(%rbp),%r8
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1090 <sendto@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     16a4 <main+0x474>
lea    0xa96(%rip),%rdi
call   1120 <perror@plt>
movl   $0x1,-0xa4(%rbp)
jmp    16b4 <main+0x484>
mov    -0x48(%rbp),%rax
shl    $0x3,%rax
add    -0x68(%rbp),%rax
mov    %rax,-0x68(%rbp)
jmp    16b9 <main+0x489>
jmp    16be <main+0x48e>
jmp    15a5 <main+0x375>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
call   1070 <nanosleep@plt>
jmp    1563 <main+0x333>
mov    -0x28(%rbp),%edi
call   10a0 <close@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    0x68(%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>
cmp    $0x4,%ebx
jg     12dc <main+0xac>
mov    0x2d25(%rip),%rbx
mov    (%rbx),%edi
mov    0x0(%rbp),%rdx
lea    0xd60(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xda2(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdb8(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdd6(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    156e <main+0x33e>
mov    0x8(%rbp),%r13
mov    0x2d01(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x2c(%rsp)
mov    0x10(%rbp),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,0x28(%rsp)
mov    0x18(%rbp),%rdi
call   1140 <atoi@plt>
mov    %rax,%rdi
call   1060 <htons@plt>
mov    %eax,0x24(%rsp)
mov    0x20(%rbp),%rdi
call   1140 <atoi@plt>
mov    %rax,%r12
mov    $0x524,%eax
mov    %rax,0x10(%rsp)
cmp    $0x5,%ebx
je     1345 <main+0x115>
mov    0x28(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1130 <strtoul@plt>
imul   $0xbc,%eax,%eax
cltq
mov    %rax,0x10(%rsp)
mov    (%r14),%edi
mov    0x2c79(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,0x8(%rsp)
test   %eax,%eax
js     157f <main+0x34f>
cmp    $0x7,%ebx
jb     13bc <main+0x18c>
mov    0x30(%rbp),%rdi
call   1140 <atoi@plt>
mov    %al,0x7(%rsp)
mov    0x10(%rbp),%rsi
lea    0x1c(%rsp),%rdi
mov    $0x3,%edx
call   10e0 <memcpy@plt>
movb   $0x0,0x1f(%rsp)
mov    0x2c43(%rip),%rax
mov    (%rax),%esi
mov    0x2c12(%rip),%rax
mov    (%rax),%edx
lea    0x7(%rsp),%rcx
mov    0x8(%rsp),%edi
mov    $0x1,%r8d
call   1040 <setsockopt@plt>
test   %eax,%eax
js     158d <main+0x35d>
mov    0x2c1d(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1110 <open@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
js     14fa <main+0x2ca>
mov    0x10(%rsp),%r15
mov    %r15,%rdi
call   1100 <malloc@plt>
mov    %rax,%r14
movl   $0xa28b2,0x48(%rsp)
mov    0x2bd8(%rip),%rbx
mov    (%rbx),%edi
lea    0x68(%rsp),%rbp
mov    %rbp,%rsi
call   1050 <clock_gettime@plt>
test   %r12d,%r12d
mov    %r12d,%eax
mov    $0x5f5e100,%r13d
cmovne %rax,%r13
mov    %rbx,%rax
lea    0x0(,%r15,8),%rcx
mov    %rcx,0x38(%rsp)
imul   $0x7a1200,%r15,%rcx
mov    %rcx,0x30(%rsp)
xor    %r15d,%r15d
lea    0x58(%rsp),%rbx
mov    %r13,0x40(%rsp)
jmp    1472 <main+0x242>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x48(%rsp),%rdi
xor    %esi,%esi
call   1070 <nanosleep@plt>
mov    0x2b6d(%rip),%rax
lea    0x68(%rsp),%rbp
mov    0x40(%rsp),%r13
lea    0x58(%rsp),%rbx
mov    (%rax),%edi
mov    %rbx,%rsi
call   1050 <clock_gettime@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10f0 <usecDiff@plt>
mov    %rax,%r12
imul   %r13,%r12
imul   $0xf4240,%r15,%rbp
cmp    %rbp,%r12
jbe    1450 <main+0x220>
mov    0x38(%rsp),%r13
mov    0x30(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0xc(%rsp),%edi
mov    %r14,%rsi
mov    0x10(%rsp),%rdx
call   10b0 <read@plt>
test   %eax,%eax
js     151f <main+0x2ef>
je     1531 <main+0x301>
mov    0x8(%rsp),%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
mov    $0x10,%r9d
call   1090 <sendto@plt>
test   %eax,%eax
jle    159e <main+0x36e>
add    %r13,%r15
add    %rbx,%rbp
cmp    %rbp,%r12
ja     14b0 <main+0x280>
jmp    1450 <main+0x220>
mov    0x2ab7(%rip),%rax
mov    (%rax),%edi
lea    0xbe5(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x8(%rsp),%edi
call   10a0 <close@plt>
jmp    156e <main+0x33e>
mov    0x2a92(%rip),%rax
mov    (%rax),%edi
lea    0xbd4(%rip),%rsi
jmp    1541 <main+0x311>
mov    0x2a80(%rip),%rax
mov    (%rax),%edi
lea    0xbd7(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
lea    0x48(%rsp),%rdi
xor    %esi,%esi
call   1070 <nanosleep@plt>
mov    0xc(%rsp),%edi
call   10a0 <close@plt>
mov    0x8(%rsp),%edi
call   10a0 <close@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb41(%rip),%rdi
call   1120 <perror@plt>
jmp    156e <main+0x33e>
lea    0xb44(%rip),%rdi
call   1120 <perror@plt>
jmp    13bc <main+0x18c>
lea    0xb81(%rip),%rdi
call   1120 <perror@plt>
jmp    1548 <main+0x318>

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 = [82 x i8] c"Usage: %s file.ts ipaddr port bitrate [ts_packet_per_ip_packet] [udp_packet_ttl]\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_DGRAM = global i32 0
@.str.4 = [17 x i8] c"socket(): error \00"
@IPPROTO_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
@IP_TTL = global i32 0
@.str.5 = [23 x i8] c"ttl configuration fail\00"
@O_RDONLY = global i32 0
@.str.6 = [20 x i8] c"can't open file %s\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.7 = [21 x i8] c"ts file read error \0A\00"
@.str.8 = [14 x i8] c"ts sent done\0A\00"
@.str.9 = [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 i32
%12 = alloca i8
%13 = alloca [4 x i8]
%14 = alloca %struct.sockaddr_in
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i64
%20 = alloca i64
%21 = alloca %struct.timespec
%22 = alloca %struct.timespec
%23 = alloca %struct.timespec
%24 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%25 = bitcast %struct.sockaddr_in* %14 to %struct.timespec*
%26 = call i32 @memset(%struct.timespec* %25, i32 0, i32 16)
%27 = call i32 @memset(%struct.timespec* %21, i32 0, i32 16)
%28 = call i32 @memset(%struct.timespec* %22, i32 0, i32 16)
%29 = call i32 @memset(%struct.timespec* %23, i32 0, i32 16)
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 5
br i1 %31, label %32, label %44
32: ; preds = %2
%33 = load i32, i32* @stderr
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %217
44: ; preds = %2
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
store i8* %47, i8** %16
%48 = load i32, i32* @AF_INET
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 3
store i32 %48, i32* %49
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i32 @inet_addr(i8* %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 2
%55 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %54, i32 0, i32 0
store i32 %53, i32* %55
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 3
%58 = load i8*, i8** %57
%59 = call i8* @atoi(i8* %58)
%60 = call i32 @htons(i8* %59)
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
store i32 %60, i32* %61
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 4
%64 = load i8*, i8** %63
%65 = call i8* @atoi(i8* %64)
%66 = ptrtoint i8* %65 to i32
store i32 %66, i32* %18
%67 = load i32, i32* %18
%68 = icmp ule i32 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %44
store i32 100000000, i32* %18
br label %70
70: ; preds = %69, %44
%71 = load i32, i32* %4
%72 = icmp sge i32 %71, 6
br i1 %72, label %73, label %80
73: ; preds = %70
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 5
%76 = load i8*, i8** %75
%77 = call i32 @strtoul(i8* %76, i32 0, i32 0)
%78 = mul nsw i32 %77, 188
%79 = sext i32 %78 to i64
store i64 %79, i64* %15
br label %81
80: ; preds = %70
store i64 1316, i64* %15
br label %81
81: ; preds = %80, %73
br label %82
82: ; preds = %81
%83 = load i32, i32* @AF_INET
%84 = load i32, i32* @SOCK_DGRAM
%85 = call i32 @socket(i32 %83, i32 %84, i32 0)
store i32 %85, i32* %6
%86 = load i32, i32* %6
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %82
%89 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %217
90: ; preds = %82
%91 = load i32, i32* %4
%92 = icmp sge i32 %91, 7
br i1 %92, label %93, label %134
93: ; preds = %90
%94 = load i8**, i8*** %5
%95 = getelementptr inbounds i8*, i8** %94, i64 6
%96 = load i8*, i8** %95
%97 = call i8* @atoi(i8* %96)
%98 = ptrtoint i8* %97 to i8
store i8 %98, i8* %12
store i32 0, i32* %10
%99 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%100 = load i8**, i8*** %5
%101 = getelementptr inbounds i8*, i8** %100, i64 2
%102 = load i8*, i8** %101
%103 = call i32 @memcpy(i8* %99, i8* %102, i32 3)
%104 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 3
store i8 0, i8* %104
%105 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%106 = call i8* @atoi(i8* %105)
%107 = ptrtoint i8* %106 to i32
store i32 %107, i32* %10
%108 = load i32, i32* %10
%109 = icmp sge i32 %108, 224
br i1 %109, label %113, label %110
110: ; preds = %93
%111 = load i32, i32* %10
%112 = icmp sle i32 %111, 239
br label %113
113: ; preds = %110, %93
%114 = phi i1 [ true, %93 ], [ %112, %110 ]
%115 = zext i1 %114 to i32
store i32 %115, i32* %10
%116 = load i32, i32* %10
%117 = icmp ne i32 %116, 0
br i1 %117, label %118, label %123
118: ; preds = %113
%119 = load i32, i32* %6
%120 = load i32, i32* @IPPROTO_IP
%121 = load i32, i32* @IP_MULTICAST_TTL
%122 = call i32 @setsockopt(i32 %119, i32 %120, i32 %121, i8* %12, i32 1)
store i32 %122, i32* %9
br label %128
123: ; preds = %113
%124 = load i32, i32* %6
%125 = load i32, i32* @IPPROTO_IP
%126 = load i32, i32* @IP_TTL
%127 = call i32 @setsockopt(i32 %124, i32 %125, i32 %126, i8* %12, i32 1)
store i32 %127, i32* %9
br label %128
128: ; preds = %123, %118
%129 = load i32, i32* %9
%130 = icmp slt i32 %129, 0
br i1 %130, label %131, label %133
131: ; preds = %128
%132 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %133
133: ; preds = %131, %128
br label %134
134: ; preds = %133, %90
%135 = load i8*, i8** %16
%136 = load i32, i32* @O_RDONLY
%137 = call i32 @open(i8* %135, i32 %136)
store i32 %137, i32* %11
%138 = load i32, i32* %11
%139 = icmp slt i32 %138, 0
br i1 %139, label %140, label %146
140: ; preds = %134
%141 = load i32, i32* @stderr
%142 = load i8*, i8** %16
%143 = call i32 (i32, i8*, ...) @fprintf(i32 %141, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %142)
%144 = load i32, i32* %6
%145 = call i32 @close(i32 %144)
store i32 0, i32* %3
br label %217
146: ; preds = %134
store i32 0, i32* %24
%147 = load i64, i64* %15
%148 = call i8* @malloc(i64 %147)
store i8* %148, i8** %17
store i64 0, i64* %19
store i64 0, i64* %20
%149 = getelementptr inbounds %struct.timespec, %struct.timespec* %23, i32 0, i32 0
store i32 665778, i32* %149
%150 = load i32, i32* @CLOCK_MONOTONIC
%151 = call i32 @clock_gettime(i32 %150, %struct.timespec* %21)
br label %152
152: ; preds = %208, %146
%153 = load i32, i32* %24
%154 = icmp ne i32 %153, 0
%155 = xor i1 %154, true
br i1 %155, label %156, label %210
156: ; preds = %152
%157 = load i32, i32* @CLOCK_MONOTONIC
%158 = call i32 @clock_gettime(i32 %157, %struct.timespec* %22)
%159 = call i64 @usecDiff(%struct.timespec* %22, %struct.timespec* %21)
store i64 %159, i64* %20
br label %160
160: ; preds = %207, %156
%161 = load i64, i64* %20
%162 = load i32, i32* %18
%163 = zext i32 %162 to i64
%164 = mul i64 %161, %163
%165 = load i64, i64* %19
%166 = mul i64 %165, 1000000
%167 = icmp ugt i64 %164, %166
br i1 %167, label %168, label %172
168: ; preds = %160
%169 = load i32, i32* %24
%170 = icmp ne i32 %169, 0
%171 = xor i1 %170, true
br label %172
172: ; preds = %168, %160
%173 = phi i1 [ false, %160 ], [ %171, %168 ]
br i1 %173, label %174, label %208
174: ; preds = %172
%175 = load i32, i32* %11
%176 = load i8*, i8** %17
%177 = load i64, i64* %15
%178 = call i32 @read(i32 %175, i8* %176, i64 %177)
store i32 %178, i32* %7
%179 = load i32, i32* %7
%180 = icmp slt i32 %179, 0
br i1 %180, label %181, label %184
181: ; preds = %174
%182 = load i32, i32* @stderr
%183 = call i32 (i32, i8*, ...) @fprintf(i32 %182, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %24
br label %207
184: ; preds = %174
%185 = load i32, i32* %7
%186 = icmp eq i32 %185, 0
br i1 %186, label %187, label %190
187: ; preds = %184
%188 = load i32, i32* @stderr
%189 = call i32 (i32, i8*, ...) @fprintf(i32 %188, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %24
br label %206
190: ; preds = %184
%191 = load i32, i32* %6
%192 = load i8*, i8** %17
%193 = load i32, i32* %7
%194 = bitcast %struct.sockaddr_in* %14 to %struct.sockaddr*
%195 = call i32 @sendto(i32 %191, i8* %192, i32 %193, i32 0, %struct.sockaddr* %194, i32 16)
store i32 %195, i32* %8
%196 = load i32, i32* %8
%197 = icmp sle i32 %196, 0
br i1 %197, label %198, label %200
198: ; preds = %190
%199 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %24
br label %205
200: ; preds = %190
%201 = load i64, i64* %15
%202 = mul i64 %201, 8
%203 = load i64, i64* %19
%204 = add i64 %203, %202
store i64 %204, i64* %19
br label %205
205: ; preds = %200, %198
br label %206
206: ; preds = %205, %187
br label %207
207: ; preds = %206, %181
br label %160
208: ; preds = %172
%209 = call i32 @nanosleep(%struct.timespec* %23, i32 0)
br label %152
210: ; preds = %152
%211 = load i32, i32* %11
%212 = call i32 @close(i32 %211)
%213 = load i32, i32* %6
%214 = call i32 @close(i32 %213)
%215 = load i8*, i8** %17
%216 = call i32 @free(i8* %215)
store i32 0, i32* %3
br label %217
217: ; preds = %210, %140, %88, %32
%218 = load i32, i32* %3
ret i32 %218
}

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 = [82 x i8] c"Usage: %s file.ts ipaddr port bitrate [ts_packet_per_ip_packet] [udp_packet_ttl]\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_DGRAM = global i32 0
@.str.4 = [17 x i8] c"socket(): error \00"
@IPPROTO_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
@IP_TTL = global i32 0
@.str.5 = [23 x i8] c"ttl configuration fail\00"
@O_RDONLY = global i32 0
@.str.6 = [20 x i8] c"can't open file %s\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.7 = [21 x i8] c"ts file read error \0A\00"
@.str.8 = [14 x i8] c"ts sent done\0A\00"
@.str.9 = [15 x i8] c"send(): error \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca [4 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.timespec
%7 = alloca %struct.timespec
%8 = alloca %struct.timespec
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in* %5 to i8*
%11 = bitcast %struct.timespec* %6 to i8*
%12 = bitcast %struct.timespec* %7 to i8*
%13 = bitcast %struct.timespec* %8 to i8*
%14 = bitcast %struct.sockaddr_in* %5 to %struct.timespec*
%15 = call i32 @memset(%struct.timespec* %14, i32 0, i32 16)
%16 = call i32 @memset(%struct.timespec* %6, i32 0, i32 16)
%17 = call i32 @memset(%struct.timespec* %7, i32 0, i32 16)
%18 = call i32 @memset(%struct.timespec* %8, i32 0, i32 16)
%19 = icmp slt i32 %0, 5
br i1 %19, label %20, label %30
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %1
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %136
30: ; preds = %2
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 3
store i32 %33, i32* %34
%35 = getelementptr inbounds i8*, i8** %1, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @inet_addr(i8* %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2, i32 0
store i32 %37, i32* %38
%39 = getelementptr inbounds i8*, i8** %1, i64 3
%40 = load i8*, i8** %39
%41 = call i8* @atoi(i8* %40)
%42 = call i32 @htons(i8* %41)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %42, i32* %43
%44 = getelementptr inbounds i8*, i8** %1, i64 4
%45 = load i8*, i8** %44
%46 = call i8* @atoi(i8* %45)
%47 = ptrtoint i8* %46 to i64
%48 = trunc i64 %47 to i32
%49 = icmp eq i32 %48, 0
%50 = icmp eq i32 %0, 5
br i1 %50, label %57, label %51
51: ; preds = %30
%52 = getelementptr inbounds i8*, i8** %1, i64 5
%53 = load i8*, i8** %52
%54 = call i32 @strtoul(i8* %53, i32 0, i32 0)
%55 = mul nsw i32 %54, 188
%56 = sext i32 %55 to i64
br label %57
57: ; preds = %30, %51
%58 = phi i64 [ %56, %51 ], [ 1316, %30 ]
%59 = load i32, i32* @AF_INET
%60 = load i32, i32* @SOCK_DGRAM
%61 = call i32 @socket(i32 %59, i32 %60, i32 0)
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %57
%64 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %136
65: ; preds = %57
%66 = icmp ugt i32 %0, 6
br i1 %66, label %67, label %82
67: ; preds = %65
%68 = getelementptr inbounds i8*, i8** %1, i64 6
%69 = load i8*, i8** %68
%70 = call i8* @atoi(i8* %69)
%71 = ptrtoint i8* %70 to i64
%72 = trunc i64 %71 to i8
store i8 %72, i8* %3
%73 = load i8*, i8** %35
%74 = call i32 @memcpy(i8* %9, i8* %73, i32 3)
%75 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
store i8 0, i8* %75
%76 = load i32, i32* @IPPROTO_IP
%77 = load i32, i32* @IP_MULTICAST_TTL
%78 = call i32 @setsockopt(i32 %61, i32 %76, i32 %77, i8* %3, i32 1)
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %67
%81 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %82
82: ; preds = %67, %80, %65
%83 = load i32, i32* @O_RDONLY
%84 = call i32 @open(i8* %32, i32 %83)
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %90
86: ; preds = %82
%87 = load i32, i32* @stderr
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %32)
%89 = call i32 @close(i32 %61)
br label %136
90: ; preds = %82
%91 = call i8* @malloc(i64 %58)
%92 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 0
store i32 665778, i32* %92
%93 = load i32, i32* @CLOCK_MONOTONIC
%94 = call i32 @clock_gettime(i32 %93, %struct.timespec* %6)
%95 = and i64 %47, 4294967295
%96 = select i1 %49, i64 100000000, i64 %95
%97 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%98 = shl nsw i64 %58, 3
br label %99
99: ; preds = %128, %90
%100 = phi i64 [ 0, %90 ], [ %129, %128 ]
%101 = load i32, i32* @CLOCK_MONOTONIC
%102 = call i32 @clock_gettime(i32 %101, %struct.timespec* %7)
%103 = call i64 @usecDiff(%struct.timespec* %7, %struct.timespec* %6)
%104 = mul i64 %103, %96
%105 = mul i64 %100, 1000000
%106 = icmp ugt i64 %104, %105
br i1 %106, label %107, label %128
107: ; preds = %99, %124
%108 = phi i64 [ %125, %124 ], [ %100, %99 ]
%109 = call i32 @read(i32 %84, i8* %91, i64 %58)
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %114
111: ; preds = %107
%112 = load i32, i32* @stderr
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %131
114: ; preds = %107
%115 = icmp eq i32 %109, 0
br i1 %115, label %116, label %119
116: ; preds = %114
%117 = load i32, i32* @stderr
%118 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
br label %131
119: ; preds = %114
%120 = call i32 @sendto(i32 %61, i8* %91, i32 %109, i32 0, %struct.sockaddr* %97, i32 16)
%121 = icmp slt i32 %120, 1
br i1 %121, label %122, label %124
122: ; preds = %119
%123 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %131
124: ; preds = %119
%125 = add i64 %108, %98
%126 = mul i64 %125, 1000000
%127 = icmp ugt i64 %104, %126
br i1 %127, label %107, label %128
128: ; preds = %124, %99
%129 = phi i64 [ %100, %99 ], [ %125, %124 ]
%130 = call i32 @nanosleep(%struct.timespec* %8, i32 0)
br label %99
131: ; preds = %111, %116, %122
%132 = call i32 @nanosleep(%struct.timespec* %8, i32 0)
%133 = call i32 @close(i32 %84)
%134 = call i32 @close(i32 %61)
%135 = call i32 @free(i8* %91)
br label %136
136: ; preds = %131, %86, %63, %20
ret i32 0
}