#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 timespec {
  int tv_sec;
  int tv_nsec;
};
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ servaddr;
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ EXIT_SUCCESS;
unsigned int Readn(int, char *, unsigned int);
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ Writen(int, char *, unsigned int);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_un *, int);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
scalar_t__ fork();
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned int, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ unlink(int /*<<< orphan*/);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
long unsigned tcp_latency(unsigned expected_size, bool debug) {
  int listenfd, connfd;
  struct sockaddr_un servaddr, cliaddr;
  socklen_t cliaddrlen;
  pid_t child_pid;
  unsigned transferred = 0;
  char buf[(512 * 1024 + 1)];
  struct timespec start;
  struct timespec end;
  struct timespec wait_for_server = {.tv_sec = 0, .tv_nsec = 1000 * 1000};
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sun_family = AF_UNIX;
  strcpy(servaddr.sun_path, "/tmp/zesty.server.so");
  child_pid = fork();
  if (child_pid < 0) {
    perror("fork");
  } else if (child_pid == 0) {
    listenfd = socket(AF_UNIX, SOCK_STREAM, 0);
    unlink(servaddr.sun_path);
    if (bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
      perror("bind");
    listen(listenfd, 128);
    cliaddrlen = sizeof(cliaddr);
    connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &cliaddrlen);
    if (connfd >= 0) {
      if ((transferred = Readn(connfd, buf, expected_size)) < expected_size)
        printf("only read %u, %u in total", transferred, expected_size);
      Writen(connfd, buf, expected_size);
    } else {
      perror("accept");
    }
    close(listenfd);
    close(connfd);
    unlink(servaddr.sun_path);
    _exit(EXIT_SUCCESS);
  } else {
    connfd = socket(AF_UNIX, SOCK_STREAM, 0);
    while (connect(connfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) !=
           0) {
      nanosleep(&wait_for_server, NULL);
    }
    clock_gettime(CLOCK_MONOTONIC, &start);
    Writen(connfd, buf, expected_size);
    if ((transferred = Readn(connfd, buf, expected_size)) < expected_size)
      printf("only read %u, %u in total", transferred, expected_size);
    clock_gettime(CLOCK_MONOTONIC, &end);
    if (debug)
      printf("child is sending %u...\n", expected_size);
    close(connfd);
    wait(NULL);
    return ((end.tv_sec - start.tv_sec) * 1000000000 + end.tv_nsec -
            start.tv_nsec) /
           2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tcp_latency>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80060,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    0xdc1(%rip),%rax
mov    %rax,-0x80058(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   10e0 <bzero@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    0xd9e(%rip),%rsi
call   1050 <strcpy@plt>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jge    1296 <tcp_latency+0x76>
lea    0xd91(%rip),%rdi
call   10d0 <perror@plt>
jmp    14af <tcp_latency+0x28f>
cmpq   $0x0,-0x38(%rbp)
jne    1398 <tcp_latency+0x178>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
mov    0x2d1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <unlink@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    12ec <tcp_latency+0xcc>
lea    0xd3b(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x14(%rbp),%edi
mov    $0x80,%esi
call   10b0 <listen@plt>
movl   $0x8,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1366 <tcp_latency+0x146>
mov    -0x18(%rbp),%edi
lea    -0x80040(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1070 <Readn@plt>
mov    %eax,-0x3c(%rbp)
cmp    -0xc(%rbp),%eax
jae    134f <tcp_latency+0x12f>
mov    -0x3c(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xcdf(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x80040(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1100 <Writen@plt>
jmp    1372 <tcp_latency+0x152>
lea    0xcd4(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
mov    -0x20(%rbp),%edi
call   1030 <unlink@plt>
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
call   1040 <_exit@plt>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
mov    0x2c28(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1110 <connect@plt>
cmp    $0x0,%rax
je     13e4 <tcp_latency+0x1c4>
lea    -0x80058(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <nanosleep@plt>
jmp    13b4 <tcp_latency+0x194>
mov    0x2bf5(%rip),%rax
mov    (%rax),%edi
lea    -0x80048(%rbp),%rsi
call   1060 <clock_gettime@plt>
mov    -0x18(%rbp),%edi
lea    -0x80040(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1100 <Writen@plt>
mov    -0x18(%rbp),%edi
lea    -0x80040(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1070 <Readn@plt>
mov    %eax,-0x3c(%rbp)
cmp    -0xc(%rbp),%eax
jae    143d <tcp_latency+0x21d>
mov    -0x3c(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xbf1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2b9c(%rip),%rax
mov    (%rax),%edi
lea    -0x80050(%rbp),%rsi
call   1060 <clock_gettime@plt>
cmpl   $0x0,-0x10(%rbp)
je     146d <tcp_latency+0x24d>
mov    -0xc(%rbp),%esi
lea    0xbe2(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1120 <wait@plt>
mov    -0x80050(%rbp),%eax
sub    -0x80048(%rbp),%eax
imul   $0x3b9aca00,%eax,%eax
add    -0x8004c(%rbp),%eax
sub    -0x80044(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x8(%rbp)
jmp    14b7 <tcp_latency+0x297>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_latency>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80030,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
movabs $0xf424000000000,%rax
mov    %rax,0x18(%rsp)
mov    %rsp,%rdi
mov    $0x8,%esi
call   10e0 <bzero@plt>
mov    0x2d90(%rip),%r12
mov    (%r12),%eax
mov    %eax,0x4(%rsp)
mov    (%rsp),%ebx
lea    0xd96(%rip),%rsi
mov    %ebx,%edi
call   1050 <strcpy@plt>
xor    %eax,%eax
call   1130 <fork@plt>
test   %rax,%rax
js     13a0 <tcp_latency+0x180>
mov    %rax,%rbp
mov    (%r12),%edi
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,%r12d
test   %rbp,%rbp
je     13b0 <tcp_latency+0x190>
mov    %rsp,%rsi
mov    %r12d,%edi
mov    $0x8,%edx
call   1110 <connect@plt>
test   %rax,%rax
je     12ef <tcp_latency+0xcf>
lea    0x18(%rsp),%rbx
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <nanosleep@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1110 <connect@plt>
test   %rax,%rax
jne    12d0 <tcp_latency+0xb0>
mov    0x2cea(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0x10(%rsp),%rsi
call   1060 <clock_gettime@plt>
lea    0x20(%rsp),%rbx
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1100 <Writen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1070 <Readn@plt>
cmp    %r15d,%eax
jae    133c <tcp_latency+0x11c>
lea    0xcef(%rip),%rdi
mov    %eax,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x0(%rbp),%edi
lea    0x8(%rsp),%rsi
call   1060 <clock_gettime@plt>
test   %r14d,%r14d
je     135f <tcp_latency+0x13f>
lea    0xceb(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12d,%edi
call   10a0 <close@plt>
xor    %edi,%edi
call   1120 <wait@plt>
mov    0x8(%rsp),%eax
sub    0x10(%rsp),%eax
imul   $0x3b9aca00,%eax,%eax
add    0xc(%rsp),%eax
sub    0x14(%rsp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rax
add    $0x80030,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc6e(%rip),%rdi
call   10d0 <perror@plt>
xor    %eax,%eax
jmp    1390 <tcp_latency+0x170>
mov    %ebx,%edi
call   1030 <unlink@plt>
mov    %rsp,%rsi
mov    %r12d,%edi
mov    $0x8,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jns    13d8 <tcp_latency+0x1b8>
lea    0xc47(%rip),%rdi
call   10d0 <perror@plt>
mov    %r12d,%edi
mov    $0x80,%esi
call   10b0 <listen@plt>
movl   $0x8,0x8(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r12d,%edi
call   10f0 <accept@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1438 <tcp_latency+0x218>
lea    0xc2c(%rip),%rdi
call   10d0 <perror@plt>
mov    %r12d,%edi
call   10a0 <close@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
mov    (%rsp),%edi
call   1030 <unlink@plt>
mov    0x2b97(%rip),%rax
mov    (%rax),%edi
call   1040 <_exit@plt>
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    %r15d,%edx
call   1070 <Readn@plt>
cmp    %r15d,%eax
jae    1460 <tcp_latency+0x240>
lea    0xbcb(%rip),%rdi
mov    %eax,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    %r15d,%edx
call   1100 <Writen@plt>
jmp    1412 <tcp_latency+0x1f2>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.tcp_latency.wait_for_server = %struct.timespec { i32 0, i32 1000000 }
@AF_UNIX = global i32 0
@.str = [21 x i8] c"/tmp/zesty.server.so\00"
@.str.1 = [5 x i8] c"fork\00"
@SOCK_STREAM = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [26 x i8] c"only read %u, %u in total\00"
@.str.4 = [7 x i8] c"accept\00"
@EXIT_SUCCESS = global i32 0
@CLOCK_MONOTONIC = global i32 0
@.str.5 = [24 x i8] c"child is sending %u...\0A\00"
define i64 @tcp_latency(i32 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_un
%9 = alloca %struct.sockaddr_un
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
%13 = alloca [524289 x i8]
%14 = alloca %struct.timespec
%15 = alloca %struct.timespec
%16 = alloca %struct.timespec
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %12
%17 = bitcast %struct.timespec* %16 to i8*
%18 = call i32 @bzero(%struct.sockaddr_un* %8, i32 8)
%19 = load i32, i32* @AF_UNIX
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @strcpy(i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%24 = call i64 (...) @fork()
store i64 %24, i64* %11
%25 = load i64, i64* %11
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %2
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %135
29: ; preds = %2
%30 = load i64, i64* %11
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %81
32: ; preds = %29
%33 = load i32, i32* @AF_UNIX
%34 = load i32, i32* @SOCK_STREAM
%35 = call i32 @socket(i32 %33, i32 %34, i32 0)
store i32 %35, i32* %6
%36 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 @unlink(i32 %37)
%39 = load i32, i32* %6
%40 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%41 = call i64 @bind(i32 %39, %struct.sockaddr* %40, i32 8)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %32
%44 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %32
%46 = load i32, i32* %6
%47 = call i32 @listen(i32 %46, i32 128)
store i32 8, i32* %10
%48 = load i32, i32* %6
%49 = bitcast %struct.sockaddr_un* %9 to %struct.sockaddr*
%50 = call i32 @accept(i32 %48, %struct.sockaddr* %49, i32* %10)
store i32 %50, i32* %7
%51 = load i32, i32* %7
%52 = icmp sge i32 %51, 0
br i1 %52, label %53, label %69
53: ; preds = %45
%54 = load i32, i32* %7
%55 = getelementptr inbounds [524289 x i8], [524289 x i8]* %13, i64 0, i64 0
%56 = load i32, i32* %4
%57 = call i32 @Readn(i32 %54, i8* %55, i32 %56)
store i32 %57, i32* %12
%58 = load i32, i32* %4
%59 = icmp ult i32 %57, %58
br i1 %59, label %60, label %64
60: ; preds = %53
%61 = load i32, i32* %12
%62 = load i32, i32* %4
%63 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %61, i32 %62)
br label %64
64: ; preds = %60, %53
%65 = load i32, i32* %7
%66 = getelementptr inbounds [524289 x i8], [524289 x i8]* %13, i64 0, i64 0
%67 = load i32, i32* %4
%68 = call i32 @Writen(i32 %65, i8* %66, i32 %67)
br label %71
69: ; preds = %45
%70 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %71
71: ; preds = %69, %64
%72 = load i32, i32* %6
%73 = call i32 @close(i32 %72)
%74 = load i32, i32* %7
%75 = call i32 @close(i32 %74)
%76 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%77 = load i32, i32* %76
%78 = call i32 @unlink(i32 %77)
%79 = load i32, i32* @EXIT_SUCCESS
%80 = call i32 @_exit(i32 %79)
unreachable
81: ; preds = %29
%82 = load i32, i32* @AF_UNIX
%83 = load i32, i32* @SOCK_STREAM
%84 = call i32 @socket(i32 %82, i32 %83, i32 0)
store i32 %84, i32* %7
br label %85
85: ; preds = %90, %81
%86 = load i32, i32* %7
%87 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%88 = call i64 @connect(i32 %86, %struct.sockaddr* %87, i32 8)
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %85
%91 = call i32 @nanosleep(%struct.timespec* %16, i32* null)
br label %85
92: ; preds = %85
%93 = load i32, i32* @CLOCK_MONOTONIC
%94 = call i32 @clock_gettime(i32 %93, %struct.timespec* %14)
%95 = load i32, i32* %7
%96 = getelementptr inbounds [524289 x i8], [524289 x i8]* %13, i64 0, i64 0
%97 = load i32, i32* %4
%98 = call i32 @Writen(i32 %95, i8* %96, i32 %97)
%99 = load i32, i32* %7
%100 = getelementptr inbounds [524289 x i8], [524289 x i8]* %13, i64 0, i64 0
%101 = load i32, i32* %4
%102 = call i32 @Readn(i32 %99, i8* %100, i32 %101)
store i32 %102, i32* %12
%103 = load i32, i32* %4
%104 = icmp ult i32 %102, %103
br i1 %104, label %105, label %109
105: ; preds = %92
%106 = load i32, i32* %12
%107 = load i32, i32* %4
%108 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %106, i32 %107)
br label %109
109: ; preds = %105, %92
%110 = load i32, i32* @CLOCK_MONOTONIC
%111 = call i32 @clock_gettime(i32 %110, %struct.timespec* %15)
%112 = load i32, i32* %5
%113 = icmp ne i32 %112, 0
br i1 %113, label %114, label %117
114: ; preds = %109
%115 = load i32, i32* %4
%116 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %115)
br label %117
117: ; preds = %114, %109
%118 = load i32, i32* %7
%119 = call i32 @close(i32 %118)
%120 = call i32 @wait(i32* null)
%121 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 0
%122 = load i32, i32* %121
%123 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 0
%124 = load i32, i32* %123
%125 = sub nsw i32 %122, %124
%126 = mul nsw i32 %125, 1000000000
%127 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 1
%128 = load i32, i32* %127
%129 = add nsw i32 %126, %128
%130 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 1
%131 = load i32, i32* %130
%132 = sub nsw i32 %129, %131
%133 = sdiv i32 %132, 2
%134 = sext i32 %133 to i64
store i64 %134, i64* %3
br label %136
135: ; preds = %27
store i64 0, i64* %3
br label %136
136: ; preds = %135, %117
%137 = load i64, i64* %3
ret i64 %137
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.timespec = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [21 x i8] c"/tmp/zesty.server.so\00"
@.str.1 = [5 x i8] c"fork\00"
@SOCK_STREAM = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [26 x i8] c"only read %u, %u in total\00"
@.str.4 = [7 x i8] c"accept\00"
@EXIT_SUCCESS = global i32 0
@CLOCK_MONOTONIC = global i32 0
@.str.5 = [24 x i8] c"child is sending %u...\0A\00"
define i64 @tcp_latency(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
%6 = alloca [524289 x i8]
%7 = alloca %struct.timespec
%8 = alloca %struct.timespec
%9 = alloca i64
%10 = bitcast i64* %9 to %struct.timespec*
%11 = bitcast %struct.sockaddr_un* %3 to i8*
%12 = bitcast %struct.sockaddr_un* %4 to i8*
%13 = bitcast i32* %5 to i8*
%14 = getelementptr inbounds [524289 x i8], [524289 x i8]* %6, i64 0, i64 0
%15 = bitcast %struct.timespec* %7 to i8*
%16 = bitcast %struct.timespec* %8 to i8*
%17 = bitcast i64* %9 to i8*
store i64 4294967296000000, i64* %9
%18 = call i32 @bzero(%struct.sockaddr_un* %3, i32 8)
%19 = load i32, i32* @AF_UNIX
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%22 = load i32, i32* %21
%23 = tail call i32 @strcpy(i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%24 = tail call i64 (...) @fork()
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %100
28: ; preds = %2
%29 = icmp eq i64 %24, 0
%30 = load i32, i32* @AF_UNIX
%31 = load i32, i32* @SOCK_STREAM
%32 = tail call i32 @socket(i32 %30, i32 %31, i32 0)
br i1 %29, label %33, label %61
33: ; preds = %28
%34 = tail call i32 @unlink(i32 %22)
%35 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%36 = call i64 @bind(i32 %32, %struct.sockaddr* %35, i32 8)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
%41 = call i32 @listen(i32 %32, i32 128)
store i32 8, i32* %5
%42 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%43 = call i32 @accept(i32 %32, %struct.sockaddr* %42, i32* %5)
%44 = icmp sgt i32 %43, -1
br i1 %44, label %45, label %52
45: ; preds = %40
%46 = call i32 @Readn(i32 %43, i8* %14, i32 %0)
%47 = icmp ult i32 %46, %0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %0)
br label %50
50: ; preds = %48, %45
%51 = call i32 @Writen(i32 %43, i8* %14, i32 %0)
br label %54
52: ; preds = %40
%53 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %50
%55 = call i32 @close(i32 %32)
%56 = call i32 @close(i32 %43)
%57 = load i32, i32* %21
%58 = call i32 @unlink(i32 %57)
%59 = load i32, i32* @EXIT_SUCCESS
%60 = call i32 @_exit(i32 %59)
unreachable
61: ; preds = %28
%62 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%63 = call i64 @connect(i32 %32, %struct.sockaddr* %62, i32 8)
%64 = icmp eq i64 %63, 0
br i1 %64, label %69, label %65
65: ; preds = %61, %65
%66 = call i32 @nanosleep(%struct.timespec* %10, i32* null)
%67 = call i64 @connect(i32 %32, %struct.sockaddr* %62, i32 8)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %65
69: ; preds = %65, %61
%70 = load i32, i32* @CLOCK_MONOTONIC
%71 = call i32 @clock_gettime(i32 %70, %struct.timespec* %7)
%72 = call i32 @Writen(i32 %32, i8* %14, i32 %0)
%73 = call i32 @Readn(i32 %32, i8* %14, i32 %0)
%74 = icmp ult i32 %73, %0
br i1 %74, label %75, label %77
75: ; preds = %69
%76 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %73, i32 %0)
br label %77
77: ; preds = %75, %69
%78 = load i32, i32* @CLOCK_MONOTONIC
%79 = call i32 @clock_gettime(i32 %78, %struct.timespec* %8)
%80 = icmp eq i32 %1, 0
br i1 %80, label %83, label %81
81: ; preds = %77
%82 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %0)
br label %83
83: ; preds = %81, %77
%84 = call i32 @close(i32 %32)
%85 = call i32 @wait(i32* null)
%86 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 0
%87 = load i32, i32* %86
%88 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 0
%89 = load i32, i32* %88
%90 = sub nsw i32 %87, %89
%91 = mul nsw i32 %90, 1000000000
%92 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 1
%93 = load i32, i32* %92
%94 = add nsw i32 %91, %93
%95 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 1
%96 = load i32, i32* %95
%97 = sub i32 %94, %96
%98 = sdiv i32 %97, 2
%99 = sext i32 %98 to i64
br label %100
100: ; preds = %26, %83
%101 = phi i64 [ 0, %26 ], [ %99, %83 ]
ret i64 %101
}