// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]spiped/perftests/send-zeros/main.c
// Function: main
int
main(int argc, char ** argv)
{
	/* Command-line parameters. */
	const char * addr;
	size_t buflen;
	size_t count;

	/* Working variables. */
	struct sock_addr ** sas_t;
	struct timeval begin, end;
	double duration_s;
	char * buffer;
	int socket;
	size_t to_send;

	WARNP_INIT;

	/* Parse command-line arguments. */
	if (argc != 4) {
		warn0("usage: %s ADDRESS BUFLEN COUNT", argv[0]);
		goto err0;
	}
	addr = argv[1];
	if (PARSENUM(&buflen, argv[2], 1, SSIZE_MAX)) {
		warnp("parsenum");
		goto err0;
	}
	if (PARSENUM(&count, argv[3], 1, SIZE_MAX)) {
		warnp("parsenum");
		goto err0;
	}

	/* Allocate and fill buffer to send. */
	if ((buffer = malloc(buflen)) == NULL) {
		warnp("Out of memory");
		goto err0;
	}
	memset(buffer, 0, buflen);

	/* Initialize count. */
	to_send = count;

	/* Resolve target address. */
	if ((sas_t = sock_resolve(addr)) == NULL) {
		warnp("Error resolving socket address: %s", addr);
		goto err1;
	}
	if (sas_t[0] == NULL) {
		warn0("No addresses found for %s", addr);
		goto err2;
	}

	/* Connect to target. */
	if ((socket = sock_connect(sas_t)) == -1) {
		warnp("sock_connect");
		goto err2;
	}

	/* Make it blocking. */
	if (fcntl(socket, F_SETFL,
	    fcntl(socket, F_GETFL, 0) & (~O_NONBLOCK)) == -1) {
		warnp("Cannot make connection blocking");
		goto err3;
	}

	/* Get beginning time. */
	if (monoclock_get(&begin)) {
		warn0("monoclock_get");
		goto err3;
	}

	/* Send data. */
	while (to_send > 0) {
		if (write(socket, buffer, buflen) != (ssize_t)buflen) {
			warnp("write failed");
			goto err3;
		}
		to_send--;
	}

	/* We're not going to send anything else. */
	if (shutdown(socket, SHUT_WR)) {
		warnp("shutdown");
		goto err3;
	}

	/*
	 * The server should not send any data back, but attempting to read
	 * will detect when the other end of the socket is closed.
	 */
	if (read(socket, buffer, 1) != 0) {
		warnp("read");
		goto err3;
	}

	/* Get ending time. */
	if (monoclock_get(&end)) {
		warn0("monoclock_get");
		goto err3;
	}

	/* Print duration and speed. */
	duration_s = timeval_diff(begin, end);
	printf("%zu\t%zu\t%.4f\t%.2f\n", buflen, count, duration_s,
	    (double)(buflen * count) / duration_s / 1e6);

	/* Clean up. */
	if (close(socket)) {
		warnp("close");
		goto err2;
	}
	sock_addr_freelist(sas_t);
	free(buffer);

	/* Success! */
	exit(0);

err3:
	if (close(socket))
		warnp("close");
err2:
	sock_addr_freelist(sas_t);
err1:
	free(buffer);
err0:
	/* Failure! */
	exit(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movl %edi, %ebx
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x253c
callq 0x3b44
cmpl $0x4, %ebx
jne 0x2578
movq 0x8(%r14), %rbp
callq 0x2080
movl $0x0, (%rax)
movq 0x10(%r14), %r15
testq %r15, %r15
jne 0x2599
leaq 0x1bc2(%rip), %rdi      # 0x4122
leaq 0x1bc5(%rip), %rsi      # 0x412c
leaq 0x1be0(%rip), %rcx      # 0x414e
movl $0xbb, %edx
callq 0x2150
movq (%r14), %rsi
leaq 0x1abe(%rip), %rdi      # 0x4040
xorl %eax, %eax
callq 0x3ce3
callq 0x2080
movl $0x0, (%rax)
jmp 0x2650
movq %rax, %rbx
leaq 0x8(%rsp), %r13
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x2250
movq %rax, %r12
movq (%r13), %rcx
movl $0x16, %eax
cmpq %r15, %rcx
je 0x25ce
cmpb $0x0, (%rcx)
jne 0x25ce
movl $0x22, %eax
testq %r12, %r12
jg 0x25d0
movl %eax, (%rbx)
cmpl $0x0, (%rbx)
jne 0x263c
movq 0x18(%r14), %r14
testq %r14, %r14
je 0x2559
leaq 0x8(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2250
movq %rax, %r13
movq (%r15), %rcx
movl $0x16, %eax
cmpq %r14, %rcx
je 0x2613
cmpb $0x0, (%rcx)
jne 0x2613
movl $0x22, %eax
testq %r13, %r13
jne 0x2615
movl %eax, (%rbx)
cmpl $0x0, (%rbx)
jne 0x263c
movl $0x1, %edi
movq %r12, %rsi
callq 0x21b0
testq %rax, %rax
jne 0x265a
leaq 0x1a35(%rip), %rdi      # 0x4068
xorl %eax, %eax
callq 0x3ce3
jmp 0x2650
leaq 0x1a1c(%rip), %rdi      # 0x405f
xorl %eax, %eax
callq 0x3bc4
movl $0x0, (%rbx)
movl $0x1, %edi
callq 0x2280
movq %rax, %r14
movq %rbp, %rdi
callq 0x2b40
testq %rax, %rax
jne 0x2685
cmpl $0x0, (%rbx)
jne 0x26a4
leaq 0x1a00(%rip), %rdi      # 0x4076
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3ce3
jmp 0x289f
movq %rax, %r15
cmpq $0x0, (%rax)
jne 0x26c0
leaq 0x1a04(%rip), %rdi      # 0x4099
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3ce3
jmp 0x2891
leaq 0x19cb(%rip), %rdi      # 0x4076
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3bc4
movl $0x0, (%rbx)
jmp 0x289f
movq %r15, %rdi
callq 0x3458
cmpl $-0x1, %eax
jne 0x26de
cmpl $0x0, (%rbx)
jne 0x2726
leaq 0x19da(%rip), %rdi      # 0x40b3
jmp 0x287a
movl %eax, %ebp
movl %eax, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x20c0
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
movl %ebp, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x20c0
cmpl $-0x1, %eax
jne 0x2732
cmpl $0x0, (%rbx)
jne 0x284f
leaq 0x19a6(%rip), %rdi      # 0x40c0
xorl %eax, %eax
callq 0x3ce3
jmp 0x2863
leaq 0x1986(%rip), %rdi      # 0x40b3
jmp 0x288a
leaq 0x8(%rsp), %rdi
callq 0x2904
testl %eax, %eax
jne 0x283f
movq %r13, (%rsp)
testq %r13, %r13
je 0x276c
movq (%rsp), %r13
movl %ebp, %edi
movq %r14, %rsi
movq %r12, %rdx
callq 0x20e0
cmpq %r12, %rax
jne 0x28bd
decq %r13
jne 0x2751
movl %ebp, %edi
movl $0x1, %esi
callq 0x20f0
testl %eax, %eax
jne 0x28ac
movl $0x1, %edx
movl %ebp, %edi
movq %r14, %rsi
callq 0x21a0
testq %rax, %rax
jne 0x28ce
leaq 0x18(%rsp), %rdi
callq 0x2904
testl %eax, %eax
jne 0x283f
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
subq 0x8(%rsp), %rax
cvtsi2sd %rax, %xmm1
subq 0x10(%rsp), %rcx
cvtsi2sd %rcx, %xmm0
mulsd 0x1838(%rip), %xmm0     # 0x4008
addsd %xmm1, %xmm0
movq (%rsp), %rdx
movq %rdx, %rax
imulq %r12, %rax
movq %rax, %xmm2
punpckldq 0x1834(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x183c(%rip), %xmm2     # 0x4030
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm0, %xmm1
divsd 0x1804(%rip), %xmm1     # 0x4010
leaq 0x18f6(%rip), %rdi      # 0x4109
movq %r12, %rsi
movb $0x2, %al
callq 0x2120
movl %ebp, %edi
callq 0x2170
testl %eax, %eax
jne 0x286e
movq %r15, %rdi
callq 0x3252
movq %r14, %rdi
callq 0x2040
xorl %edi, %edi
callq 0x2280
leaq 0x189a(%rip), %rdi      # 0x40e0
xorl %eax, %eax
callq 0x3ce3
jmp 0x285d
leaq 0x186a(%rip), %rdi      # 0x40c0
xorl %eax, %eax
callq 0x3bc4
movl $0x0, (%rbx)
movl %ebp, %edi
callq 0x2170
testl %eax, %eax
je 0x2897
cmpl $0x0, (%rbx)
jne 0x2883
leaq 0x18a2(%rip), %rdi      # 0x411c
xorl %eax, %eax
callq 0x3ce3
jmp 0x2897
leaq 0x1892(%rip), %rdi      # 0x411c
xorl %eax, %eax
callq 0x3bc4
movl $0x0, (%rbx)
movq %r15, %rdi
callq 0x3252
movq %r14, %rdi
callq 0x2040
jmp 0x2650
cmpl $0x0, (%rbx)
jne 0x28df
leaq 0x1843(%rip), %rdi      # 0x40fb
jmp 0x271a
cmpl $0x0, (%rbx)
jne 0x28eb
leaq 0x1825(%rip), %rdi      # 0x40ee
jmp 0x271a
cmpl $0x0, (%rbx)
jne 0x28f7
leaq 0x182a(%rip), %rdi      # 0x4104
jmp 0x271a
leaq 0x1815(%rip), %rdi      # 0x40fb
jmp 0x2856
leaq 0x17fc(%rip), %rdi      # 0x40ee
jmp 0x2856
leaq 0x1806(%rip), %rdi      # 0x4104
jmp 0x2856
nop