#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;
int Readn(int, char *, 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_throughput(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);
      buf[0] = 'F';
      Writen(connfd, buf, 1);
    } 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 (!(Readn(connfd, buf, 1) == 1 && buf[0] == 'F')) {
      perror("Readn ack");
    }
    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;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tcp_throughput>:
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_throughput+0x76>
lea    0xd91(%rip),%rdi
call   10d0 <perror@plt>
jmp    14b7 <tcp_throughput+0x297>
cmpq   $0x0,-0x38(%rbp)
jne    13a1 <tcp_throughput+0x181>
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_throughput+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     136f <tcp_throughput+0x14f>
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_throughput+0x12f>
mov    -0x3c(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xcdf(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movb   $0x46,-0x80040(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x80040(%rbp),%rsi
mov    $0x1,%edx
call   1100 <Writen@plt>
jmp    137b <tcp_throughput+0x15b>
lea    0xccb(%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    0x2c2e(%rip),%rax
mov    (%rax),%edi
call   1040 <_exit@plt>
mov    0x2c40(%rip),%rax
mov    (%rax),%edi
mov    0x2c1f(%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     13ed <tcp_throughput+0x1cd>
lea    -0x80058(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <nanosleep@plt>
jmp    13bd <tcp_throughput+0x19d>
mov    0x2bec(%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    $0x1,%edx
call   1070 <Readn@plt>
cmp    $0x1,%eax
jne    1441 <tcp_throughput+0x221>
movsbl -0x80040(%rbp),%eax
cmp    $0x46,%eax
je     144d <tcp_throughput+0x22d>
lea    0xc00(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
lea    -0x80050(%rbp),%rsi
call   1060 <clock_gettime@plt>
cmpl   $0x0,-0x10(%rbp)
je     147d <tcp_throughput+0x25d>
mov    -0xc(%rbp),%esi
lea    0xbdc(%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
cltq
mov    %rax,-0x8(%rbp)
jmp    14bf <tcp_throughput+0x29f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_throughput>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80030,%rsp
mov    %esi,%r15d
mov    %edi,%r14d
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     138c <tcp_throughput+0x16c>
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     13aa <tcp_throughput+0x18a>
mov    %rsp,%rsi
mov    %r12d,%edi
mov    $0x8,%edx
call   1110 <connect@plt>
test   %rax,%rax
je     12ef <tcp_throughput+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_throughput+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    %r14d,%edx
call   1100 <Writen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <Readn@plt>
cmp    $0x1,%eax
jne    139c <tcp_throughput+0x17c>
cmpb   $0x46,0x20(%rsp)
jne    139c <tcp_throughput+0x17c>
mov    0x0(%rbp),%edi
lea    0x8(%rsp),%rsi
call   1060 <clock_gettime@plt>
test   %r15d,%r15d
je     1355 <tcp_throughput+0x135>
lea    0xcff(%rip),%rdi
mov    %r14d,%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
cltq
add    $0x80030,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc82(%rip),%rdi
call   10d0 <perror@plt>
xor    %eax,%eax
jmp    137c <tcp_throughput+0x15c>
lea    0xc9d(%rip),%rdi
call   10d0 <perror@plt>
jmp    1332 <tcp_throughput+0x112>
mov    %ebx,%edi
call   1030 <unlink@plt>
mov    %rsp,%rsi
mov    %r12d,%edi
mov    $0x8,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jns    13d2 <tcp_throughput+0x1b2>
lea    0xc4d(%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,%ebx
test   %eax,%eax
jns    1430 <tcp_throughput+0x210>
lea    0xc33(%rip),%rdi
call   10d0 <perror@plt>
mov    %r12d,%edi
call   10a0 <close@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
mov    (%rsp),%edi
call   1030 <unlink@plt>
mov    0x2b9f(%rip),%rax
mov    (%rax),%edi
call   1040 <_exit@plt>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    %r14d,%edx
call   1070 <Readn@plt>
cmp    %r14d,%eax
jae    1457 <tcp_throughput+0x237>
lea    0xbd4(%rip),%rdi
mov    %eax,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
movb   $0x46,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1100 <Writen@plt>
jmp    140b <tcp_throughput+0x1eb>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.tcp_throughput.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 = [10 x i8] c"Readn ack\00"
@.str.6 = [24 x i8] c"child is sending %u...\0A\00"
define i64 @tcp_throughput(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 = getelementptr inbounds [524289 x i8], [524289 x i8]* %13, i64 0, i64 0
store i8 70, i8* %65
%66 = load i32, i32* %7
%67 = getelementptr inbounds [524289 x i8], [524289 x i8]* %13, i64 0, i64 0
%68 = call i32 @Writen(i32 %66, i8* %67, i32 1)
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 = call i32 @Readn(i32 %99, i8* %100, i32 1)
%102 = icmp eq i32 %101, 1
br i1 %102, label %103, label %108
103: ; preds = %92
%104 = getelementptr inbounds [524289 x i8], [524289 x i8]* %13, i64 0, i64 0
%105 = load i8, i8* %104
%106 = sext i8 %105 to i32
%107 = icmp eq i32 %106, 70
br i1 %107, label %110, label %108
108: ; preds = %103, %92
%109 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %110
110: ; preds = %108, %103
%111 = load i32, i32* @CLOCK_MONOTONIC
%112 = call i32 @clock_gettime(i32 %111, %struct.timespec* %15)
%113 = load i32, i32* %5
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %118
115: ; preds = %110
%116 = load i32, i32* %4
%117 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %116)
br label %118
118: ; preds = %115, %110
%119 = load i32, i32* %7
%120 = call i32 @close(i32 %119)
%121 = call i32 @wait(i32* null)
%122 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 0
%123 = load i32, i32* %122
%124 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 0
%125 = load i32, i32* %124
%126 = sub nsw i32 %123, %125
%127 = mul nsw i32 %126, 1000000000
%128 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 1
%129 = load i32, i32* %128
%130 = add nsw i32 %127, %129
%131 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 1
%132 = load i32, i32* %131
%133 = sub nsw i32 %130, %132
%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, %118
%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 = [10 x i8] c"Readn ack\00"
@.str.6 = [24 x i8] c"child is sending %u...\0A\00"
define i64 @tcp_throughput(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 %102
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
store i8 70, i8* %14
%51 = call i32 @Writen(i32 %43, i8* %14, i32 1)
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 1)
%74 = icmp eq i32 %73, 1
%75 = load i8, i8* %14
%76 = icmp eq i8 %75, 70
%77 = select i1 %74, i1 %76, i1 false
br i1 %77, label %80, label %78
78: ; preds = %69
%79 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %80
80: ; preds = %69, %78
%81 = load i32, i32* @CLOCK_MONOTONIC
%82 = call i32 @clock_gettime(i32 %81, %struct.timespec* %8)
%83 = icmp eq i32 %1, 0
br i1 %83, label %86, label %84
84: ; preds = %80
%85 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %0)
br label %86
86: ; preds = %84, %80
%87 = call i32 @close(i32 %32)
%88 = call i32 @wait(i32* null)
%89 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 0
%90 = load i32, i32* %89
%91 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 0
%92 = load i32, i32* %91
%93 = sub nsw i32 %90, %92
%94 = mul nsw i32 %93, 1000000000
%95 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 1
%96 = load i32, i32* %95
%97 = add nsw i32 %94, %96
%98 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 1
%99 = load i32, i32* %98
%100 = sub i32 %97, %99
%101 = sext i32 %100 to i64
br label %102
102: ; preds = %26, %86
%103 = phi i64 [ 0, %26 ], [ %101, %86 ]
ret i64 %103
}