#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 */
struct timeval {
  float tv_usec;
  scalar_t__ tv_sec;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ si_other;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ _exit(int);
int atoi(char *);
int ceil(float);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int /*<<< orphan*/ usleep(double);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int i;
  int r;
  int t;
  int packet_count = 0;
  int overhead = 40;
  if (argc < 3) {
    usage();
    exit(0);
  } else {
    for (i = 1; i < argc; i += 2) {
      if (argv[i][0] == '-') {
        switch (argv[i][1]) {
        case 'r':
          r = atoi(argv[i + 1]);
          break;
        case 't':
          t = atoi(argv[i + 1]);
          break;
        default:
          return (0);
          break;
        }
      }
    }
  }
  if (r < 180) {
    overhead = 41;
  } else if (r < 458) {
    overhead = 20;
  } else if (r <= 600) {
    overhead = 10;
  } else if (r < 800) {
    overhead = 1;
  }
  printf("overhead=%d\n", overhead);
  printf("r=%d t=%d\n", r, t);
  struct sockaddr_in si_other;
  int slen = sizeof(si_other);
  int _socket;
  char buf[1514];
  _socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if (_socket == -1) {
    printf("Error: socket");
    exit(0);
  }
  memset((char *)&si_other, sizeof(si_other), 0);
  si_other.sin_family = AF_INET;
  si_other.sin_port = htons(32000);
  if (inet_aton("127.0.0.1", &si_other.sin_addr) == 0) {
    fprintf(stderr, "inet_aton() failed\n");
    _exit(1);
  }
  int r_bits = r * 1000000;
  int num_of_packets = r_bits / 11776;
  double sleep_time = (1 / (double)num_of_packets);
  double usleep_time = sleep_time * 1000000;
  usleep_time = usleep_time - overhead;
  printf("raw  sleep=%lf\n", sleep_time);
  printf("raw usleep=%lf\n", usleep_time);
  int workers = ceil((float)30 / usleep_time);
  printf("launching %d worker(s)\n", workers);
  usleep_time = usleep_time * workers;
  if (usleep_time < 30) {
    printf("WARNING: usleep_time < 30us -- this percission is not reliable: "
           "%lf, exiting\n",
           usleep_time);
    return 0;
  }
  printf("%d / %d = %d, sleep=%lf\n", r_bits, 11776, num_of_packets,
         usleep_time);
  for (int i = 0; i < workers; i++) {
    if (fork() == 0) {
      printf("child started: pid=%d, w/ sleep:%lf\n", getpid(), usleep_time);
      struct timeval start_time;
      struct timeval stop_time;
      float elapsed;
      gettimeofday(&start_time, NULL);
      for (;;) {
        if (sendto(_socket, buf, 1514, 0, (struct sockaddr *)&si_other, slen) ==
            -1)
          printf("Error: sendto()\n");
        packet_count++;
        usleep(usleep_time);
        gettimeofday(&stop_time, NULL);
        elapsed = (float)(stop_time.tv_sec - start_time.tv_sec);
        elapsed += (stop_time.tv_usec - start_time.tv_usec) / (float)1000000;
        if (elapsed >= (double)t)
          break;
      }
      printf("child closed: %d - %d packets sent\n", getpid(), packet_count);
      _exit(0);
    } else {
    }
  }
  printf("waiting for children\n");
  wait(NULL);
  close(_socket);
  printf("exiting main\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x680,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x28,-0x24(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    125f <main+0x3f>
mov    $0x0,%al
call   10e0 <usage@plt>
xor    %edi,%edi
call   1100 <exit@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1322 <main+0x102>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    130f <main+0xef>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x678(%rbp)
sub    $0x72,%eax
je     12c2 <main+0xa2>
jmp    12ae <main+0x8e>
mov    -0x678(%rbp),%eax
sub    $0x74,%eax
je     12e0 <main+0xc0>
jmp    12fe <main+0xde>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    130a <main+0xea>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    130a <main+0xea>
movl   $0x0,-0x4(%rbp)
jmp    1743 <main+0x523>
jmp    130f <main+0xef>
jmp    1314 <main+0xf4>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1266 <main+0x46>
jmp    1327 <main+0x107>
cmpl   $0xb4,-0x18(%rbp)
jge    1340 <main+0x120>
movl   $0x29,-0x24(%rbp)
jmp    1395 <main+0x175>
cmpl   $0x1ca,-0x18(%rbp)
jge    1359 <main+0x139>
movl   $0x14,-0x24(%rbp)
jmp    1390 <main+0x170>
cmpl   $0x258,-0x18(%rbp)
jg     1372 <main+0x152>
movl   $0xa,-0x24(%rbp)
jmp    138b <main+0x16b>
cmpl   $0x320,-0x18(%rbp)
jge    1386 <main+0x166>
movl   $0x1,-0x24(%rbp)
jmp    138b <main+0x16b>
jmp    1390 <main+0x170>
jmp    1395 <main+0x175>
mov    -0x24(%rbp),%esi
lea    0xc7d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xc76(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xc,-0x34(%rbp)
mov    0x2c20(%rip),%rax
mov    (%rax),%edi
mov    0x2c0f(%rip),%rax
mov    (%rax),%esi
mov    0x2be6(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    1403 <main+0x1e3>
lea    0xc3f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
xor    %edx,%edx
call   1090 <memset@plt>
mov    0x2bce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x7d00,%edi
call   1060 <htons@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xc0b(%rip),%rdi
call   10d0 <inet_aton@plt>
cmp    $0x0,%rax
jne    1465 <main+0x245>
mov    0x2b83(%rip),%rax
mov    (%rax),%edi
lea    0xbf6(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
imul   $0xf4240,-0x18(%rbp),%eax
mov    %eax,-0x634(%rbp)
mov    -0x634(%rbp),%eax
mov    $0x2e00,%ecx
cltd
idiv   %ecx
mov    %eax,-0x638(%rbp)
cvtsi2sdl -0x638(%rbp),%xmm1
ff
movsd  0xb7a(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x640(%rbp)
ff
movsd  0xb5e(%rip),%xmm0
mulsd  -0x640(%rbp),%xmm0
ff
movsd  %xmm0,-0x648(%rbp)
ff
movsd  -0x648(%rbp),%xmm0
ff
cvtsi2sdl -0x24(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x648(%rbp)
ff
movsd  -0x640(%rbp),%xmm0
ff
lea    0xb7e(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
movsd  -0x648(%rbp),%xmm0
ff
lea    0xb78(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
movsd  0xaf9(%rip),%xmm0
divsd  -0x648(%rbp),%xmm0
ff
cvtsd2ss %xmm0,%xmm0
call   1050 <ceil@plt>
mov    %eax,-0x64c(%rbp)
mov    -0x64c(%rbp),%esi
lea    0xb55(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movsd  -0x648(%rbp),%xmm0
ff
cvtsi2sdl -0x64c(%rbp),%xmm1
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x648(%rbp)
ff
movsd  0xaaa(%rip),%xmm0
ucomisd -0x648(%rbp),%xmm0
ff
jbe    1586 <main+0x366>
movsd  -0x648(%rbp),%xmm0
ff
lea    0xb25(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1743 <main+0x523>
mov    -0x634(%rbp),%esi
mov    -0x638(%rbp),%ecx
movsd  -0x648(%rbp),%xmm0
ff
lea    0xb45(%rip),%rdi
mov    $0x2e00,%edx
mov    $0x1,%al
call   1070 <printf@plt>
movl   $0x0,-0x650(%rbp)
mov    -0x650(%rbp),%eax
cmp    -0x64c(%rbp),%eax
jge    170f <main+0x4ef>
mov    $0x0,%al
call   1120 <fork@plt>
cmp    $0x0,%rax
jne    16f1 <main+0x4d1>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
movsd  -0x648(%rbp),%xmm0
ff
lea    0xb0d(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
lea    -0x660(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
mov    -0x38(%rbp),%edi
lea    -0x630(%rbp),%rsi
lea    -0x30(%rbp),%r8
mov    -0x34(%rbp),%r9d
mov    $0x5ea,%edx
xor    %ecx,%ecx
call   10a0 <sendto@plt>
cmp    $0xffffffff,%eax
jne    163e <main+0x41e>
lea    0xaed(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movsd  -0x648(%rbp),%xmm0
ff
call   1130 <usleep@plt>
lea    -0x670(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
mov    -0x668(%rbp),%rax
sub    -0x658(%rbp),%rax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x674(%rbp)
ff
movss  -0x670(%rbp),%xmm0
ff
subss  -0x660(%rbp),%xmm0
ff
movss  0x981(%rip),%xmm1
divss  %xmm1,%xmm0
addss  -0x674(%rbp),%xmm0
ff
movss  %xmm0,-0x674(%rbp)
ff
movss  -0x674(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jb     16cb <main+0x4ab>
jmp    16d0 <main+0x4b0>
jmp    1609 <main+0x3e9>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x20(%rbp),%edx
lea    0xa52(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
jmp    16f6 <main+0x4d6>
jmp    16fb <main+0x4db>
mov    -0x650(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x650(%rbp)
jmp    15b7 <main+0x397>
lea    0xa43(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1110 <wait@plt>
mov    -0x38(%rbp),%edi
call   10b0 <close@plt>
lea    0xa3a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x680,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x648,%rsp
cmp    $0x3,%edi
jl     15ad <main+0x37d>
mov    %rsi,%rbp
mov    %edi,%r15d
mov    $0x1,%ebx
jmp    1276 <main+0x46>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rbp,%rbx,8),%rdi
call   1100 <atoi@plt>
mov    %eax,%r14d
add    $0x2,%rbx
cmp    %r15d,%ebx
jge    12a1 <main+0x71>
mov    0x0(%rbp,%rbx,8),%rax
cmpb   $0x2d,(%rax)
jne    126d <main+0x3d>
movsbl 0x1(%rax),%eax
cmp    $0x74,%eax
je     1260 <main+0x30>
cmp    $0x72,%eax
jne    1498 <main+0x268>
mov    0x8(%rbp,%rbx,8),%rdi
call   1100 <atoi@plt>
mov    %eax,%r12d
jmp    126d <main+0x3d>
mov    $0x29,%r15d
cmp    $0xb4,%r12d
jl     12e4 <main+0xb4>
mov    $0x14,%r15d
cmp    $0x1ca,%r12d
jb     12e4 <main+0xb4>
mov    $0xa,%r15d
cmp    $0x259,%r12d
jb     12e4 <main+0xb4>
cmp    $0x320,%r12d
mov    $0x1,%eax
mov    $0x28,%r15d
cmovb  %eax,%r15d
lea    0xd31(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd2d(%rip),%rdi
mov    %r12d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2cd8(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2cc6(%rip),%rax
mov    (%rax),%esi
mov    0x2c9d(%rip),%rax
mov    (%rax),%edx
call   1150 <socket@plt>
cmp    $0xffffffff,%eax
je     15bb <main+0x38b>
mov    %eax,%r13d
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
xor    %edx,%edx
call   10a0 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x20(%rsp)
mov    $0x7d00,%edi
call   1070 <htons@plt>
mov    %eax,0x1c(%rsp)
lea    0xcdc(%rip),%rdi
mov    %rbx,%rsi
call   10e0 <inet_aton@plt>
test   %rax,%rax
je     15d0 <main+0x3a0>
imul   $0xf4240,%r12d,%r12d
movslq %r12d,%rax
imul   $0xffffffffb21642c9,%rax,%rbx
shr    $0x20,%rbx
add    %r12d,%ebx
mov    %ebx,%eax
shr    $0x1f,%eax
sar    $0xd,%ebx
add    %eax,%ebx
cvtsi2sd %ebx,%xmm1
movsd  0xc5b(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  0xc57(%rip),%xmm2
mulsd  %xmm0,%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %r15d,%xmm1
subsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
lea    0xc92(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
lea    0xc94(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1080 <printf@plt>
movsd  0xc1f(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1060 <ceil@plt>
mov    %eax,%ebp
lea    0xc77(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  0xbe9(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    143d <main+0x20d>
lea    0xc64(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
jmp    1498 <main+0x268>
lea    0xca2(%rip),%rdi
mov    %r12d,%esi
mov    $0x2e00,%edx
mov    %ebx,%ecx
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%al
call   1080 <printf@plt>
test   %ebp,%ebp
jle    1471 <main+0x241>
nop
xor    %eax,%eax
call   1130 <fork@plt>
test   %rax,%rax
je     14ac <main+0x27c>
add    $0xffffffff,%ebp
jne    1460 <main+0x230>
lea    0xcd0(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1120 <wait@plt>
mov    %r13d,%edi
call   10c0 <close@plt>
lea    0xcca(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x648,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xc43(%rip),%rdi
mov    %eax,%esi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1080 <printf@plt>
lea    0x40(%rsp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
mov    0x48(%rsp),%r15
movss  0x40(%rsp),%xmm0
movss  %xmm0,0x14(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movsd  %xmm0,0x28(%rsp)
lea    0x50(%rsp),%r14
lea    0x18(%rsp),%r12
lea    0x30(%rsp),%rbp
jmp    155f <main+0x32f>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
movsd  0x8(%rsp),%xmm0
call   1140 <usleep@plt>
mov    %rbp,%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
mov    0x38(%rsp),%rax
sub    %r15,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  0x30(%rsp),%xmm1
subss  0x14(%rsp),%xmm1
divss  0xacc(%rip),%xmm1
addss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
ucomisd 0x28(%rsp),%xmm0
jae    158d <main+0x35d>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x5ea,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0xc,%r9d
call   10b0 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1510 <main+0x2e0>
lea    0xbe4(%rip),%rdi
call   1040 <puts@plt>
jmp    1510 <main+0x2e0>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xb89(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
xor    %eax,%eax
call   10f0 <usage@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    0xa72(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    0x29f9(%rip),%rax
mov    (%rax),%edi
lea    0xa6c(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.timeval = type { float, i64 }
%struct.sockaddr = type { i32 }
@.str = [13 x i8] c"overhead=%d\0A\00"
@.str.1 = [11 x i8] c"r=%d t=%d\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.2 = [14 x i8] c"Error: socket\00"
@.str.3 = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.4 = [20 x i8] c"inet_aton() failed\0A\00"
@.str.5 = [16 x i8] c"raw sleep=%lf\0A\00"
@.str.6 = [16 x i8] c"raw usleep=%lf\0A\00"
@.str.7 = [24 x i8] c"launching %d worker(s)\0A\00"
@.str.8 = [78 x i8] c"WARNING: usleep_time < 30us -- this percission is not reliable: %lf, exiting\0A\00"
@.str.9 = [25 x i8] c"%d / %d = %d, sleep=%lf\0A\00"
@.str.10 = [37 x i8] c"child started: pid=%d, w/ sleep:%lf\0A\00"
@.str.11 = [17 x i8] c"Error: sendto()\0A\00"
@.str.12 = [36 x i8] c"child closed: %d - %d packets sent\0A\00"
@.str.13 = [22 x i8] c"waiting for children\0A\00"
@.str.14 = [14 x i8] c"exiting main\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 i32
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca i32
%14 = alloca [1514 x i8]
%15 = alloca i32
%16 = alloca i32
%17 = alloca double
%18 = alloca double
%19 = alloca i32
%20 = alloca i32
%21 = alloca %struct.timeval
%22 = alloca %struct.timeval
%23 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 40, i32* %10
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 3
br i1 %25, label %26, label %29
26: ; preds = %2
%27 = call i32 (...) @usage()
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %2
store i32 1, i32* %6
br label %30
30: ; preds = %72, %29
%31 = load i32, i32* %6
%32 = load i32, i32* %4
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %75
34: ; preds = %30
%35 = load i8**, i8*** %5
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 45
br i1 %43, label %44, label %71
44: ; preds = %34
%45 = load i8**, i8*** %5
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
switch i32 %52, label %69 [
i32 114, label %53
i32 116, label %61
]
53: ; preds = %44
%54 = load i8**, i8*** %5
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %54, i64 %57
%59 = load i8*, i8** %58
%60 = call i32 @atoi(i8* %59)
store i32 %60, i32* %7
br label %70
61: ; preds = %44
%62 = load i8**, i8*** %5
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %62, i64 %65
%67 = load i8*, i8** %66
%68 = call i32 @atoi(i8* %67)
store i32 %68, i32* %8
br label %70
69: ; preds = %44
store i32 0, i32* %3
br label %226
70: ; preds = %61, %53
br label %71
71: ; preds = %70, %34
br label %72
72: ; preds = %71
%73 = load i32, i32* %6
%74 = add nsw i32 %73, 2
store i32 %74, i32* %6
br label %30
75: ; preds = %30
br label %76
76: ; preds = %75
%77 = load i32, i32* %7
%78 = icmp slt i32 %77, 180
br i1 %78, label %79, label %80
79: ; preds = %76
store i32 41, i32* %10
br label %95
80: ; preds = %76
%81 = load i32, i32* %7
%82 = icmp slt i32 %81, 458
br i1 %82, label %83, label %84
83: ; preds = %80
store i32 20, i32* %10
br label %94
84: ; preds = %80
%85 = load i32, i32* %7
%86 = icmp sle i32 %85, 600
br i1 %86, label %87, label %88
87: ; preds = %84
store i32 10, i32* %10
br label %93
88: ; preds = %84
%89 = load i32, i32* %7
%90 = icmp slt i32 %89, 800
br i1 %90, label %91, label %92
91: ; preds = %88
store i32 1, i32* %10
br label %92
92: ; preds = %91, %88
br label %93
93: ; preds = %92, %87
br label %94
94: ; preds = %93, %83
br label %95
95: ; preds = %94, %79
%96 = load i32, i32* %10
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %96)
%98 = load i32, i32* %7
%99 = load i32, i32* %8
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %98, i32 %99)
store i32 12, i32* %12
%101 = load i32, i32* @AF_INET
%102 = load i32, i32* @SOCK_DGRAM
%103 = load i32, i32* @IPPROTO_UDP
%104 = call i32 @socket(i32 %101, i32 %102, i32 %103)
store i32 %104, i32* %13
%105 = load i32, i32* %13
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %110
107: ; preds = %95
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%109 = call i32 @exit(i32 0)
unreachable
110: ; preds = %95
%111 = bitcast %struct.sockaddr_in* %11 to i8*
%112 = call i32 @memset(i8* %111, i32 12, i32 0)
%113 = load i32, i32* @AF_INET
%114 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %113, i32* %114
%115 = call i32 @htons(i32 32000)
%116 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %115, i32* %116
%117 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%118 = call i64 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %117)
%119 = icmp eq i64 %118, 0
br i1 %119, label %120, label %124
120: ; preds = %110
%121 = load i32, i32* @stderr
%122 = call i32 @fprintf(i32 %121, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%123 = call i32 @_exit(i32 1)
unreachable
124: ; preds = %110
%125 = load i32, i32* %7
%126 = mul nsw i32 %125, 1000000
store i32 %126, i32* %15
%127 = load i32, i32* %15
%128 = sdiv i32 %127, 11776
store i32 %128, i32* %16
%129 = load i32, i32* %16
%130 = sitofp i32 %129 to double
%131 = fdiv double 1.000000e+00, %130
store double %131, double* %17
%132 = load double, double* %17
%133 = fmul double %132, 1.000000e+06
store double %133, double* %18
%134 = load double, double* %18
%135 = load i32, i32* %10
%136 = sitofp i32 %135 to double
%137 = fsub double %134, %136
store double %137, double* %18
%138 = load double, double* %17
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), double %138)
%140 = load double, double* %18
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), double %140)
%142 = load double, double* %18
%143 = fdiv double 3.000000e+01, %142
%144 = fptrunc double %143 to float
%145 = call i32 @ceil(float %144)
store i32 %145, i32* %19
%146 = load i32, i32* %19
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %146)
%148 = load double, double* %18
%149 = load i32, i32* %19
%150 = sitofp i32 %149 to double
%151 = fmul double %148, %150
store double %151, double* %18
%152 = load double, double* %18
%153 = fcmp olt double %152, 3.000000e+01
br i1 %153, label %154, label %157
154: ; preds = %124
%155 = load double, double* %18
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.8, i64 0, i64 0), double %155)
store i32 0, i32* %3
br label %226
157: ; preds = %124
%158 = load i32, i32* %15
%159 = load i32, i32* %16
%160 = load double, double* %18
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %158, i32 11776, i32 %159, double %160)
store i32 0, i32* %20
br label %162
162: ; preds = %217, %157
%163 = load i32, i32* %20
%164 = load i32, i32* %19
%165 = icmp slt i32 %163, %164
br i1 %165, label %166, label %220
166: ; preds = %162
%167 = call i64 (...) @fork()
%168 = icmp eq i64 %167, 0
br i1 %168, label %169, label %215
169: ; preds = %166
%170 = call i32 (...) @getpid()
%171 = load double, double* %18
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), i32 %170, double %171)
%173 = call i32 @gettimeofday(%struct.timeval* %21, i32* null)
br label %174
174: ; preds = %209, %169
%175 = load i32, i32* %13
%176 = getelementptr inbounds [1514 x i8], [1514 x i8]* %14, i64 0, i64 0
%177 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%178 = load i32, i32* %12
%179 = call i32 @sendto(i32 %175, i8* %176, i32 1514, i32 0, %struct.sockaddr* %177, i32 %178)
%180 = icmp eq i32 %179, -1
br i1 %180, label %181, label %183
181: ; preds = %174
%182 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %183
183: ; preds = %181, %174
%184 = load i32, i32* %9
%185 = add nsw i32 %184, 1
store i32 %185, i32* %9
%186 = load double, double* %18
%187 = call i32 @usleep(double %186)
%188 = call i32 @gettimeofday(%struct.timeval* %22, i32* null)
%189 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
%190 = load i64, i64* %189
%191 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 1
%192 = load i64, i64* %191
%193 = sub nsw i64 %190, %192
%194 = sitofp i64 %193 to float
store float %194, float* %23
%195 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
%196 = load float, float* %195
%197 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 0
%198 = load float, float* %197
%199 = fsub float %196, %198
%200 = fdiv float %199, 1.000000e+06
%201 = load float, float* %23
%202 = fadd float %201, %200
store float %202, float* %23
%203 = load float, float* %23
%204 = fpext float %203 to double
%205 = load i32, i32* %8
%206 = sitofp i32 %205 to double
%207 = fcmp oge double %204, %206
br i1 %207, label %208, label %209
208: ; preds = %183
br label %210
209: ; preds = %183
br label %174
210: ; preds = %208
%211 = call i32 (...) @getpid()
%212 = load i32, i32* %9
%213 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0), i32 %211, i32 %212)
%214 = call i32 @_exit(i32 0)
unreachable
215: ; preds = %166
br label %216
216: ; preds = %215
br label %217
217: ; preds = %216
%218 = load i32, i32* %20
%219 = add nsw i32 %218, 1
store i32 %219, i32* %20
br label %162
220: ; preds = %162
%221 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.13, i64 0, i64 0))
%222 = call i32 @wait(i32* null)
%223 = load i32, i32* %13
%224 = call i32 @close(i32 %223)
%225 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* %3
br label %226
226: ; preds = %220, %154, %69
%227 = load i32, i32* %3
ret i32 %227
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.timeval = type { float, i64 }
%struct.sockaddr = type { i32 }
@.str = [13 x i8] c"overhead=%d\0A\00"
@.str.1 = [11 x i8] c"r=%d t=%d\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.2 = [14 x i8] c"Error: socket\00"
@.str.3 = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.4 = [20 x i8] c"inet_aton() failed\0A\00"
@.str.5 = [16 x i8] c"raw sleep=%lf\0A\00"
@.str.6 = [16 x i8] c"raw usleep=%lf\0A\00"
@.str.7 = [24 x i8] c"launching %d worker(s)\0A\00"
@.str.8 = [78 x i8] c"WARNING: usleep_time < 30us -- this percission is not reliable: %lf, exiting\0A\00"
@.str.9 = [25 x i8] c"%d / %d = %d, sleep=%lf\0A\00"
@.str.10 = [37 x i8] c"child started: pid=%d, w/ sleep:%lf\0A\00"
@.str.12 = [36 x i8] c"child closed: %d - %d packets sent\0A\00"
@str = [21 x i8] c"waiting for children\00"
@str.15 = [13 x i8] c"exiting main\00"
@str.16 = [16 x i8] c"Error: sendto()\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1514 x i8]
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 (...) @usage()
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %2, %33
%12 = phi i64 [ %36, %33 ], [ 1, %2 ]
%13 = phi i32 [ %35, %33 ], [ undef, %2 ]
%14 = phi i32 [ %34, %33 ], [ undef, %2 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 %12
%16 = load i8*, i8** %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 45
br i1 %18, label %19, label %33
19: ; preds = %11
%20 = getelementptr inbounds i8, i8* %16, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
switch i32 %22, label %147 [
i32 114, label %23
i32 116, label %28
]
23: ; preds = %19
%24 = add nuw nsw i64 %12, 1
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = tail call i32 @atoi(i8* %26)
br label %33
28: ; preds = %19
%29 = add nuw nsw i64 %12, 1
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i8*, i8** %30
%32 = tail call i32 @atoi(i8* %31)
br label %33
33: ; preds = %11, %28, %23
%34 = phi i32 [ %32, %28 ], [ %14, %23 ], [ %14, %11 ]
%35 = phi i32 [ %13, %28 ], [ %27, %23 ], [ %13, %11 ]
%36 = add nuw i64 %12, 2
%37 = trunc i64 %36 to i32
%38 = icmp slt i32 %37, %0
br i1 %38, label %11, label %39
39: ; preds = %33
%40 = icmp slt i32 %35, 180
br i1 %40, label %48, label %41
41: ; preds = %39
%42 = icmp ult i32 %35, 458
br i1 %42, label %48, label %43
43: ; preds = %41
%44 = icmp ult i32 %35, 601
br i1 %44, label %48, label %45
45: ; preds = %43
%46 = icmp ult i32 %35, 800
%47 = select i1 %46, i32 1, i32 40
br label %48
48: ; preds = %45, %43, %41, %39
%49 = phi i32 [ 41, %39 ], [ 20, %41 ], [ 10, %43 ], [ %47, %45 ]
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %49)
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %34)
%52 = bitcast %struct.sockaddr_in* %3 to i8*
%53 = getelementptr inbounds [1514 x i8], [1514 x i8]* %4, i64 0, i64 0
%54 = load i32, i32* @AF_INET
%55 = load i32, i32* @SOCK_DGRAM
%56 = load i32, i32* @IPPROTO_UDP
%57 = tail call i32 @socket(i32 %54, i32 %55, i32 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %48
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%61 = tail call i32 @exit(i32 0)
unreachable
62: ; preds = %48
%63 = call i32 @memset(i8* %52, i32 12, i32 0)
%64 = load i32, i32* @AF_INET
%65 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %64, i32* %65
%66 = call i32 @htons(i32 32000)
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %66, i32* %67
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%69 = call i64 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %68)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %62
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%74 = call i32 @_exit(i32 1)
unreachable
75: ; preds = %62
%76 = mul nsw i32 %35, 1000000
%77 = sdiv i32 %76, 11776
%78 = sitofp i32 %77 to double
%79 = fdiv double 1.000000e+00, %78
%80 = fmul double %79, 1.000000e+06
%81 = sitofp i32 %49 to double
%82 = fsub double %80, %81
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), double %79)
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), double %82)
%85 = fdiv double 3.000000e+01, %82
%86 = fptrunc double %85 to float
%87 = call i32 @ceil(float %86)
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %87)
%89 = sitofp i32 %87 to double
%90 = fmul double %82, %89
%91 = fcmp olt double %90, 3.000000e+01
br i1 %91, label %92, label %94
92: ; preds = %75
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @.str.8, i64 0, i64 0), double %90)
br label %146
94: ; preds = %75
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %76, i32 11776, i32 %77, double %90)
%96 = icmp sgt i32 %87, 0
br i1 %96, label %104, label %99
97: ; preds = %104
%98 = icmp eq i32 %108, %87
br i1 %98, label %99, label %104
99: ; preds = %97, %94
%100 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%101 = call i32 @wait(i32* null)
%102 = call i32 @close(i32 %57)
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.15, i64 0, i64 0))
br label %146
104: ; preds = %94, %97
%105 = phi i32 [ %108, %97 ], [ 0, %94 ]
%106 = call i64 (...) @fork()
%107 = icmp eq i64 %106, 0
%108 = add nuw nsw i32 %105, 1
br i1 %107, label %109, label %97
109: ; preds = %104
%110 = call i32 (...) @getpid()
%111 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), i32 %110, double %90)
%112 = bitcast %struct.timeval* %5 to i8*
%113 = bitcast %struct.timeval* %6 to i8*
%114 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%115 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%116 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%117 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%118 = load i64, i64* %117
%119 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%120 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%121 = load float, float* %120
%122 = sitofp i32 %34 to double
br label %123
123: ; preds = %129, %109
%124 = phi i32 [ 0, %109 ], [ %130, %129 ]
%125 = call i32 @sendto(i32 %57, i8* %53, i32 1514, i32 0, %struct.sockaddr* %115, i32 12)
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %129
127: ; preds = %123
%128 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.16, i64 0, i64 0))
br label %129
129: ; preds = %127, %123
%130 = add nuw nsw i32 %124, 1
%131 = call i32 @usleep(double %90)
%132 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%133 = load i64, i64* %116
%134 = sub nsw i64 %133, %118
%135 = sitofp i64 %134 to float
%136 = load float, float* %119
%137 = fsub float %136, %121
%138 = fdiv float %137, 1.000000e+06
%139 = fadd float %138, %135
%140 = fpext float %139 to double
%141 = fcmp ult double %140, %122
br i1 %141, label %123, label %142
142: ; preds = %129
%143 = call i32 (...) @getpid()
%144 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0), i32 %143, i32 %130)
%145 = call i32 @_exit(i32 0)
unreachable
146: ; preds = %99, %92
br label %147
147: ; preds = %19, %146
ret i32 0
}