#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 uint64_t;
typedef int /*<<< orphan*/ to;
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  scalar_t__ sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
void *AF_INET;
scalar_t__ EAGAIN;
scalar_t__ EWOULDBLOCK;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOCK_STREAM;
int bind(int, struct sockaddr *, int);
int close(int);
int connect(int, struct sockaddr *, int);
int current_time();
scalar_t__ errno;
int /*<<< orphan*/ fatal(char *, char *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
scalar_t__ htons(unsigned int);
int /*<<< orphan*/ inet_addr(char const *);
void *malloc(unsigned int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, unsigned int);
int recv(int, void *, int, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int sendto(int, void *, unsigned int, int /*<<< orphan*/, struct sockaddr *,
           int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
void run_client(const char *to_ip, unsigned to_port, unsigned pkt_size) {
  int status, fd, cfd;
  uint64_t seq;
  struct sockaddr_in addr, to;
  void *buffer;
  if (pkt_size < (14 + 20 + 8))
    fatal(NULL, "Cannot send packets that small.");
  pkt_size -= (14 + 20 + 8);
  buffer = malloc(pkt_size);
  if (!buffer)
    fatal("malloc", NULL);
  memset(buffer, 0, pkt_size);
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (fd == -1)
    fatal("socket", "Unable to create udp socket");
  cfd = socket(AF_INET, SOCK_STREAM, 0);
  if (cfd == -1)
    fatal("socket", "Unable to create tcp socket");
  addr.sin_family = AF_INET;
  addr.sin_port = 0;
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  to.sin_family = AF_INET;
  to.sin_port = htons(to_port);
  to.sin_addr.s_addr = inet_addr(to_ip);
  status = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
  if (status == -1)
    fatal("bind", NULL);
  status = connect(cfd, (struct sockaddr *)&to, sizeof(to));
  if (status == -1)
    fatal("connect", "Can not connect to server");
  for (seq = 0;; seq++) {
    ssize_t written;
    uint64_t now;
    fd_set rfds;
    struct timeval tv;
    FD_ZERO(&rfds);
    FD_SET(cfd, &rfds);
    tv.tv_sec = 0;
    tv.tv_usec = 0;
    status = select(cfd + 1, &rfds, NULL, NULL, &tv);
    if (status == -1)
      fatal("select", NULL);
    if (status) {
      status = recv(cfd, buffer, 8, 0);
      if (status == -1)
        fatal("recv", NULL);
      if (((uint64_t *)buffer)[0] == 0xdeadbeef)
        break;
      fatal(NULL, "Received invalid control message");
    }
    now = current_time();
    if (pkt_size >= sizeof(uint64_t))
      ((uint64_t *)buffer)[0] = now;
    if (pkt_size >= 2 * sizeof(uint64_t))
      ((uint64_t *)buffer)[1] = seq;
    written =
        sendto(fd, buffer, pkt_size, 0, (struct sockaddr *)&to, sizeof(to));
    if (written == -1 && (errno == EWOULDBLOCK || errno == EAGAIN))
      continue;
    if (written == -1)
      fatal("sendto", NULL);
  }
  free(buffer);
  status = close(cfd);
  if (status == -1)
    fatal("close", "Unable to close socket");
  status = close(fd);
  if (status == -1)
    fatal("close", "Unable to close socket");
}


x86 assembly (clang, -O0):
<run_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x2a,-0x10(%rbp)
jae    123f <run_client+0x2f>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc6(%rip),%rsi
call   1110 <fatal@plt>
mov    -0x10(%rbp),%eax
sub    $0x2a,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   10e0 <malloc@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    126f <run_client+0x5f>
lea    0xdba(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1110 <fatal@plt>
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%rdi
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12b7 <run_client+0xa7>
lea    0xe25(%rip),%rdi
lea    0xd75(%rip),%rsi
call   1110 <fatal@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%rdi
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12f1 <run_client+0xe1>
lea    0xdeb(%rip),%rdi
lea    0xd57(%rip),%rsi
call   1110 <fatal@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x38(%rbp)
mov    0x2cc9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <htons@plt>
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x50(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x18,%edx
call   10f0 <bind@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    136c <run_client+0x15c>
lea    0xcfc(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1110 <fatal@plt>
mov    -0x1c(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x18,%edx
call   1100 <connect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    139d <run_client+0x18d>
lea    0xcd3(%rip),%rdi
lea    0xcd4(%rip),%rsi
call   1110 <fatal@plt>
movl   $0x0,-0x20(%rbp)
lea    -0x64(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    -0x1c(%rbp),%edi
lea    -0x64(%rbp),%rsi
call   1120 <FD_SET@plt>
movq   $0x0,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
lea    -0x64(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x78(%rbp),%r8
mov    %rcx,%rdx
call   10d0 <select@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1400 <run_client+0x1f0>
lea    0xc8f(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1110 <fatal@plt>
cmpl   $0x0,-0x14(%rbp)
je     145f <run_client+0x24f>
mov    -0x1c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    143a <run_client+0x22a>
lea    0xc5c(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1110 <fatal@plt>
mov    -0x58(%rbp),%rax
cmpl   $0xdeadbeef,(%rax)
jne    144f <run_client+0x23f>
jmp    1524 <run_client+0x314>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc38(%rip),%rsi
call   1110 <fatal@plt>
mov    $0x0,%al
call   10b0 <current_time@plt>
mov    %eax,-0x60(%rbp)
mov    -0x10(%rbp),%eax
cmp    $0x4,%rax
jb     147f <run_client+0x26f>
mov    -0x60(%rbp),%ecx
mov    -0x58(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%eax
cmp    $0x8,%rax
jb     1496 <run_client+0x286>
mov    -0x20(%rbp),%ecx
mov    -0x58(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    -0x50(%rbp),%r8
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1080 <sendto@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jne    14f7 <run_client+0x2e7>
mov    0x2afb(%rip),%rax
mov    (%rax),%rax
mov    0x2ae9(%rip),%rcx
cmp    (%rcx),%rax
je     14f2 <run_client+0x2e2>
mov    0x2ae1(%rip),%rax
mov    (%rax),%rax
mov    0x2abf(%rip),%rcx
cmp    (%rcx),%rax
jne    14f7 <run_client+0x2e7>
jmp    1516 <run_client+0x306>
cmpl   $0xffffffff,-0x5c(%rbp)
jne    1511 <run_client+0x301>
lea    0xbab(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1110 <fatal@plt>
jmp    1516 <run_client+0x306>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    13a4 <run_client+0x194>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1555 <run_client+0x345>
lea    0xb71(%rip),%rdi
lea    0xb70(%rip),%rsi
call   1110 <fatal@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    157d <run_client+0x36d>
lea    0xb49(%rip),%rdi
lea    0xb48(%rip),%rsi
call   1110 <fatal@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_client>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %edx,%r13d
mov    %esi,%r14d
mov    %rdi,%r12
cmp    $0x29,%edx
ja     123a <run_client+0x2a>
lea    0xddd(%rip),%rsi
xor    %edi,%edi
call   1110 <fatal@plt>
add    $0xffffffd6,%r13d
mov    %r13d,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    125c <run_client+0x4c>
lea    0xddb(%rip),%rdi
xor    %esi,%esi
call   1110 <fatal@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r13d,%edx
call   1070 <memset@plt>
mov    0x2d78(%rip),%rbp
mov    0x0(%rbp),%rdi
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,0x8(%rsp)
cmp    $0xffffffff,%eax
jne    12a0 <run_client+0x90>
lea    0xe4c(%rip),%rdi
lea    0xd9c(%rip),%rsi
call   1110 <fatal@plt>
mov    0x0(%rbp),%rdi
mov    0x2d1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    12cf <run_client+0xbf>
lea    0xe1d(%rip),%rdi
lea    0xd89(%rip),%rsi
call   1110 <fatal@plt>
mov    0x0(%rbp),%rbp
mov    %rbp,0x38(%rsp)
movq   $0x0,0x30(%rsp)
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x28(%rsp)
mov    %rbp,0x20(%rsp)
mov    %r14d,%edi
call   1050 <htons@plt>
mov    %rax,0x18(%rsp)
mov    %r12,%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x10(%rsp)
lea    0x28(%rsp),%rsi
mov    0x8(%rsp),%edi
mov    $0x18,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1337 <run_client+0x127>
lea    0xd3f(%rip),%rdi
xor    %esi,%esi
call   1110 <fatal@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0x18,%edx
call   1100 <connect@plt>
cmp    $0xffffffff,%eax
jne    1361 <run_client+0x151>
lea    0xd1f(%rip),%rdi
lea    0xd20(%rip),%rsi
call   1110 <fatal@plt>
mov    %r15d,%r12d
add    $0x1,%r12d
lea    0xc(%rsp),%rbp
xor    %r14d,%r14d
jmp    13a9 <run_client+0x199>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    %r13d,%edx
xor    %ecx,%ecx
lea    0x10(%rsp),%r8
mov    $0x18,%r9d
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
je     1450 <run_client+0x240>
add    $0x1,%r14d
mov    %rbp,%rdi
call   10c0 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1120 <FD_SET@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
mov    %r12d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x40(%rsp),%r8
call   10d0 <select@plt>
test   %eax,%eax
je     142a <run_client+0x21a>
cmp    $0xffffffff,%eax
jne    13ef <run_client+0x1df>
lea    0xcae(%rip),%rdi
xor    %esi,%esi
call   1110 <fatal@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
cmp    $0xffffffff,%eax
jne    1414 <run_client+0x204>
lea    0xc90(%rip),%rdi
xor    %esi,%esi
call   1110 <fatal@plt>
cmpl   $0xdeadbeef,(%rbx)
je     148d <run_client+0x27d>
xor    %edi,%edi
lea    0xc7d(%rip),%rsi
call   1110 <fatal@plt>
xor    %eax,%eax
call   10b0 <current_time@plt>
cmp    $0x4,%r13d
jb     1380 <run_client+0x170>
mov    %eax,(%rbx)
cmp    $0x8,%r13d
jb     1380 <run_client+0x170>
mov    %r14d,0x4(%rbx)
jmp    1380 <run_client+0x170>
mov    0x2b69(%rip),%rax
mov    (%rax),%rax
mov    0x2b57(%rip),%rcx
cmp    (%rcx),%rax
je     13a5 <run_client+0x195>
mov    0x2b37(%rip),%rcx
cmp    (%rcx),%rax
je     13a5 <run_client+0x195>
lea    0xc42(%rip),%rdi
xor    %esi,%esi
call   1110 <fatal@plt>
jmp    13a5 <run_client+0x195>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   1090 <close@plt>
cmp    $0xffffffff,%eax
jne    14b5 <run_client+0x2a5>
lea    0xc21(%rip),%rdi
lea    0xc20(%rip),%rsi
call   1110 <fatal@plt>
mov    0x8(%rsp),%edi
call   1090 <close@plt>
cmp    $0xffffffff,%eax
jne    14d6 <run_client+0x2c6>
lea    0xc00(%rip),%rdi
lea    0xbff(%rip),%rsi
call   1110 <fatal@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i64, i64 }
%struct.sockaddr = type { i32 }
@.str = [32 x i8] c"Cannot send packets that small.\00"
@.str.1 = [7 x i8] c"malloc\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [28 x i8] c"Unable to create udp socket\00"
@SOCK_STREAM = global i32 0
@.str.4 = [28 x i8] c"Unable to create tcp socket\00"
@INADDR_ANY = global i32 0
@.str.5 = [5 x i8] c"bind\00"
@.str.6 = [8 x i8] c"connect\00"
@.str.7 = [26 x i8] c"Can not connect to server\00"
@.str.8 = [7 x i8] c"select\00"
@.str.9 = [5 x i8] c"recv\00"
@.str.10 = [33 x i8] c"Received invalid control message\00"
@errno = global i64 0
@EWOULDBLOCK = global i64 0
@EAGAIN = global i64 0
@.str.11 = [7 x i8] c"sendto\00"
@.str.12 = [6 x i8] c"close\00"
@.str.13 = [23 x i8] c"Unable to close socket\00"
define void @run_client(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca %struct.timeval
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%18 = load i32, i32* %6
%19 = icmp ult i32 %18, 42
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @fatal(i8* null, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %3
%23 = load i32, i32* %6
%24 = sub i32 %23, 42
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = call i8* @malloc(i32 %25)
store i8* %26, i8** %13
%27 = load i8*, i8** %13
%28 = icmp ne i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %22
%30 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* null)
br label %31
31: ; preds = %29, %22
%32 = load i8*, i8** %13
%33 = load i32, i32* %6
%34 = call i32 @memset(i8* %32, i32 0, i32 %33)
%35 = load i8*, i8** @AF_INET
%36 = load i32, i32* @SOCK_DGRAM
%37 = call i32 @socket(i8* %35, i32 %36, i32 0)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %31
%41 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %31
%43 = load i8*, i8** @AF_INET
%44 = load i32, i32* @SOCK_STREAM
%45 = call i32 @socket(i8* %43, i32 %44, i32 0)
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %48, %42
%51 = load i8*, i8** @AF_INET
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i8* %51, i8** %52
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i64 0, i64* %53
%54 = load i32, i32* @INADDR_ANY
%55 = call i32 @htonl(i32 %54)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%57 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %56, i32 0, i32 0
store i32 %55, i32* %57
%58 = load i8*, i8** @AF_INET
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i8* %58, i8** %59
%60 = load i32, i32* %5
%61 = call i64 @htons(i32 %60)
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i64 %61, i64* %62
%63 = load i8*, i8** %4
%64 = call i32 @inet_addr(i8* %63)
%65 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%66 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %65, i32 0, i32 0
store i32 %64, i32* %66
%67 = load i32, i32* %8
%68 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%69 = call i32 @bind(i32 %67, %struct.sockaddr* %68, i32 24)
store i32 %69, i32* %7
%70 = load i32, i32* %7
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %74
72: ; preds = %50
%73 = call i32 @fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* null)
br label %74
74: ; preds = %72, %50
%75 = load i32, i32* %9
%76 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%77 = call i32 @connect(i32 %75, %struct.sockaddr* %76, i32 24)
store i32 %77, i32* %7
%78 = load i32, i32* %7
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %82
80: ; preds = %74
%81 = call i32 @fatal(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
br label %82
82: ; preds = %80, %74
store i32 0, i32* %10
br label %83
83: ; preds = %158, %82
%84 = call i32 @FD_ZERO(i32* %16)
%85 = load i32, i32* %9
%86 = call i32 @FD_SET(i32 %85, i32* %16)
%87 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 1
store i64 0, i64* %87
%88 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
store i64 0, i64* %88
%89 = load i32, i32* %9
%90 = add nsw i32 %89, 1
%91 = call i32 @select(i32 %90, i32* %16, i32* null, i32* null, %struct.timeval* %17)
store i32 %91, i32* %7
%92 = load i32, i32* %7
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %96
94: ; preds = %83
%95 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* null)
br label %96
96: ; preds = %94, %83
%97 = load i32, i32* %7
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %116
99: ; preds = %96
%100 = load i32, i32* %9
%101 = load i8*, i8** %13
%102 = call i32 @recv(i32 %100, i8* %101, i32 8, i32 0)
store i32 %102, i32* %7
%103 = load i32, i32* %7
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %107
105: ; preds = %99
%106 = call i32 @fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* null)
br label %107
107: ; preds = %105, %99
%108 = load i8*, i8** %13
%109 = bitcast i8* %108 to i32*
%110 = getelementptr inbounds i32, i32* %109, i64 0
%111 = load i32, i32* %110
%112 = icmp eq i32 %111, -559038737
br i1 %112, label %113, label %114
113: ; preds = %107
br label %161
114: ; preds = %107
%115 = call i32 @fatal(i8* null, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
br label %116
116: ; preds = %114, %96
%117 = call i32 (...) @current_time()
store i32 %117, i32* %15
%118 = load i32, i32* %6
%119 = zext i32 %118 to i64
%120 = icmp uge i64 %119, 4
br i1 %120, label %121, label %126
121: ; preds = %116
%122 = load i32, i32* %15
%123 = load i8*, i8** %13
%124 = bitcast i8* %123 to i32*
%125 = getelementptr inbounds i32, i32* %124, i64 0
store i32 %122, i32* %125
br label %126
126: ; preds = %121, %116
%127 = load i32, i32* %6
%128 = zext i32 %127 to i64
%129 = icmp uge i64 %128, 8
br i1 %129, label %130, label %135
130: ; preds = %126
%131 = load i32, i32* %10
%132 = load i8*, i8** %13
%133 = bitcast i8* %132 to i32*
%134 = getelementptr inbounds i32, i32* %133, i64 1
store i32 %131, i32* %134
br label %135
135: ; preds = %130, %126
%136 = load i32, i32* %8
%137 = load i8*, i8** %13
%138 = load i32, i32* %6
%139 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%140 = call i32 @sendto(i32 %136, i8* %137, i32 %138, i32 0, %struct.sockaddr* %139, i32 24)
store i32 %140, i32* %14
%141 = load i32, i32* %14
%142 = icmp eq i32 %141, -1
br i1 %142, label %143, label %152
143: ; preds = %135
%144 = load i64, i64* @errno
%145 = load i64, i64* @EWOULDBLOCK
%146 = icmp eq i64 %144, %145
br i1 %146, label %151, label %147
147: ; preds = %143
%148 = load i64, i64* @errno
%149 = load i64, i64* @EAGAIN
%150 = icmp eq i64 %148, %149
br i1 %150, label %151, label %152
151: ; preds = %147, %143
br label %158
152: ; preds = %147, %135
%153 = load i32, i32* %14
%154 = icmp eq i32 %153, -1
br i1 %154, label %155, label %157
155: ; preds = %152
%156 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* null)
br label %157
157: ; preds = %155, %152
br label %158
158: ; preds = %157, %151
%159 = load i32, i32* %10
%160 = add nsw i32 %159, 1
store i32 %160, i32* %10
br label %83
161: ; preds = %113
%162 = load i8*, i8** %13
%163 = call i32 @free(i8* %162)
%164 = load i32, i32* %9
%165 = call i32 @close(i32 %164)
store i32 %165, i32* %7
%166 = load i32, i32* %7
%167 = icmp eq i32 %166, -1
br i1 %167, label %168, label %170
168: ; preds = %161
%169 = call i32 @fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
br label %170
170: ; preds = %168, %161
%171 = load i32, i32* %8
%172 = call i32 @close(i32 %171)
store i32 %172, i32* %7
%173 = load i32, i32* %7
%174 = icmp eq i32 %173, -1
br i1 %174, label %175, label %177
175: ; preds = %170
%176 = call i32 @fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
br label %177
177: ; preds = %175, %170
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i64, i64 }
%struct.sockaddr = type { i32 }
@.str = [32 x i8] c"Cannot send packets that small.\00"
@.str.1 = [7 x i8] c"malloc\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [28 x i8] c"Unable to create udp socket\00"
@SOCK_STREAM = global i32 0
@.str.4 = [28 x i8] c"Unable to create tcp socket\00"
@INADDR_ANY = global i32 0
@.str.5 = [5 x i8] c"bind\00"
@.str.6 = [8 x i8] c"connect\00"
@.str.7 = [26 x i8] c"Can not connect to server\00"
@.str.8 = [7 x i8] c"select\00"
@.str.9 = [5 x i8] c"recv\00"
@.str.10 = [33 x i8] c"Received invalid control message\00"
@errno = global i64 0
@EWOULDBLOCK = global i64 0
@EAGAIN = global i64 0
@.str.11 = [7 x i8] c"sendto\00"
@.str.12 = [6 x i8] c"close\00"
@.str.13 = [23 x i8] c"Unable to close socket\00"
define void @run_client(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = icmp ult i32 %2, 42
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @fatal(i8* null, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %3
%14 = add i32 %2, -42
%15 = tail call i8* @malloc(i32 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* null)
br label %19
19: ; preds = %17, %13
%20 = tail call i32 @memset(i8* %15, i32 0, i32 %14)
%21 = load i8*, i8** @AF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = tail call i32 @socket(i8* %21, i32 %22, i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = tail call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
%28 = load i8*, i8** @AF_INET
%29 = load i32, i32* @SOCK_STREAM
%30 = tail call i32 @socket(i8* %28, i32 %29, i32 0)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = tail call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = load i8*, i8** @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %35, i8** %36
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i64 0, i64* %37
%38 = load i32, i32* @INADDR_ANY
%39 = tail call i32 @htonl(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %39, i32* %40
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i8* %35, i8** %41
%42 = tail call i64 @htons(i32 %1)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i64 %42, i64* %43
%44 = tail call i32 @inet_addr(i8* %0)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %44, i32* %45
%46 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%47 = call i32 @bind(i32 %23, %struct.sockaddr* %46, i32 24)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %34
%50 = call i32 @fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* null)
br label %51
51: ; preds = %49, %34
%52 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%53 = call i32 @connect(i32 %30, %struct.sockaddr* %52, i32 24)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = call i32 @fatal(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
br label %57
57: ; preds = %55, %51
%58 = bitcast i32* %6 to i8*
%59 = bitcast %struct.timeval* %7 to i8*
%60 = add nsw i32 %30, 1
%61 = bitcast i8* %15 to i32*
%62 = icmp ugt i32 %14, 3
%63 = icmp ugt i32 %14, 7
%64 = getelementptr inbounds i32, i32* %61, i64 1
%65 = bitcast %struct.timeval* %7 to i8*
br label %66
66: ; preds = %105, %57
%67 = phi i32 [ 0, %57 ], [ %106, %105 ]
%68 = call i32 @FD_ZERO(i32* %6)
%69 = call i32 @FD_SET(i32 %30, i32* %6)
%70 = call i32 @select(i32 %60, i32* %6, i32* null, i32* null, %struct.timeval* %7)
switch i32 %70, label %73 [
i32 -1, label %71
i32 0, label %87
]
71: ; preds = %66
%72 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* null)
br label %73
73: ; preds = %71, %66
%74 = call i32 @recv(i32 %30, i8* %15, i32 8, i32 0)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %78
76: ; preds = %73
%77 = call i32 @fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* null)
br label %78
78: ; preds = %76, %73
%79 = load i32, i32* %61
%80 = icmp eq i32 %79, -559038737
br i1 %80, label %81, label %85
81: ; preds = %78
%82 = call i32 @free(i8* %15)
%83 = call i32 @close(i32 %30)
%84 = icmp eq i32 %83, -1
br i1 %84, label %107, label %109
85: ; preds = %78
%86 = call i32 @fatal(i8* null, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
br label %87
87: ; preds = %66, %85
%88 = call i32 (...) @current_time()
br i1 %62, label %89, label %91
89: ; preds = %87
store i32 %88, i32* %61
br i1 %63, label %90, label %91
90: ; preds = %89
store i32 %67, i32* %64
br label %91
91: ; preds = %87, %90, %89
%92 = call i32 @sendto(i32 %23, i8* %15, i32 %14, i32 0, %struct.sockaddr* %52, i32 24)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %103
94: ; preds = %91
%95 = load i64, i64* @errno
%96 = load i64, i64* @EWOULDBLOCK
%97 = icmp eq i64 %95, %96
%98 = load i64, i64* @EAGAIN
%99 = icmp eq i64 %95, %98
%100 = select i1 %97, i1 true, i1 %99
br i1 %100, label %104, label %101
101: ; preds = %94
%102 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* null)
br label %103
103: ; preds = %91, %101
br label %105
104: ; preds = %94
br label %105
105: ; preds = %104, %103
%106 = add nuw nsw i32 %67, 1
br label %66
107: ; preds = %81
%108 = call i32 @fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
br label %109
109: ; preds = %107, %81
%110 = call i32 @close(i32 %23)
%111 = icmp eq i32 %110, -1
br i1 %111, label %112, label %114
112: ; preds = %109
%113 = call i32 @fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
br label %114
114: ; preds = %112, %109
ret void
}