// File: /workspace/github_c_makefile_star2_O1/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 0x254c
callq 0x3b88
cmpl $0x4, %ebx
jne 0x2588
movq 0x8(%r14), %rbp
callq 0x2080
movl $0x0, (%rax)
movq 0x10(%r14), %r15
testq %r15, %r15
jne 0x25a9
leaq 0x1bb2(%rip), %rdi      # 0x4122
leaq 0x1bb5(%rip), %rsi      # 0x412c
leaq 0x1bd0(%rip), %rcx      # 0x414e
movl $0xbb, %edx
callq 0x2150
movq (%r14), %rsi
leaq 0x1aae(%rip), %rdi      # 0x4040
xorl %eax, %eax
callq 0x3d27
callq 0x2080
movl $0x0, (%rax)
jmp 0x2661
movq %rax, %rbx
leaq 0x8(%rsp), %r13
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x2260
movq %rax, %r12
movq (%r13), %rcx
movl $0x16, %eax
cmpq %r15, %rcx
je 0x25de
cmpb $0x0, (%rcx)
jne 0x25de
movl $0x22, %eax
testq %r12, %r12
jg 0x25e0
movl %eax, (%rbx)
cmpl $0x0, (%rbx)
jne 0x264d
movl $0x0, (%rbx)
movq 0x18(%r14), %r14
testq %r14, %r14
je 0x2569
leaq 0x8(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2260
movq %rax, %r13
movq (%r15), %rcx
movl $0x16, %eax
cmpq %r14, %rcx
je 0x2629
cmpb $0x0, (%rcx)
jne 0x2629
movl $0x22, %eax
testq %r13, %r13
jne 0x262b
movl %eax, (%rbx)
cmpl $0x0, (%rbx)
jne 0x264d
movq %r12, %rdi
callq 0x2200
testq %rax, %rax
jne 0x266b
leaq 0x1a24(%rip), %rdi      # 0x4068
xorl %eax, %eax
callq 0x3d27
jmp 0x2661
leaq 0x1a0b(%rip), %rdi      # 0x405f
xorl %eax, %eax
callq 0x3c08
movl $0x0, (%rbx)
movl $0x1, %edi
callq 0x2290
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x2170
movq %rbp, %rdi
callq 0x2b60
testq %rax, %rax
jne 0x26a3
cmpl $0x0, (%rbx)
jne 0x26c2
leaq 0x19e2(%rip), %rdi      # 0x4076
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3d27
jmp 0x28bd
movq %rax, %r15
cmpq $0x0, (%rax)
jne 0x26de
leaq 0x19e6(%rip), %rdi      # 0x4099
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3d27
jmp 0x28af
leaq 0x19ad(%rip), %rdi      # 0x4076
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3c08
movl $0x0, (%rbx)
jmp 0x28bd
movq %r15, %rdi
callq 0x347d
cmpl $-0x1, %eax
jne 0x26fc
cmpl $0x0, (%rbx)
jne 0x2744
leaq 0x19bc(%rip), %rdi      # 0x40b3
jmp 0x2898
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 0x2750
cmpl $0x0, (%rbx)
jne 0x286d
leaq 0x1988(%rip), %rdi      # 0x40c0
xorl %eax, %eax
callq 0x3d27
jmp 0x2881
leaq 0x1968(%rip), %rdi      # 0x40b3
jmp 0x28a8
leaq 0x8(%rsp), %rdi
callq 0x2924
testl %eax, %eax
jne 0x285d
movq %r13, (%rsp)
testq %r13, %r13
je 0x278a
movq (%rsp), %r13
movl %ebp, %edi
movq %r14, %rsi
movq %r12, %rdx
callq 0x20e0
cmpq %r12, %rax
jne 0x28db
decq %r13
jne 0x276f
movl %ebp, %edi
movl $0x1, %esi
callq 0x20f0
testl %eax, %eax
jne 0x28ca
movl $0x1, %edx
movl %ebp, %edi
movq %r14, %rsi
callq 0x21b0
testq %rax, %rax
jne 0x28ec
leaq 0x18(%rsp), %rdi
callq 0x2924
testl %eax, %eax
jne 0x285d
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
subq 0x8(%rsp), %rax
cvtsi2sd %rax, %xmm1
subq 0x10(%rsp), %rcx
cvtsi2sd %rcx, %xmm0
mulsd 0x181a(%rip), %xmm0     # 0x4008
addsd %xmm1, %xmm0
movq (%rsp), %rdx
movq %rdx, %rax
imulq %r12, %rax
movq %rax, %xmm2
punpckldq 0x1816(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x181e(%rip), %xmm2     # 0x4030
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm0, %xmm1
divsd 0x17e6(%rip), %xmm1     # 0x4010
leaq 0x18d8(%rip), %rdi      # 0x4109
movq %r12, %rsi
movb $0x2, %al
callq 0x2120
movl %ebp, %edi
callq 0x2180
testl %eax, %eax
jne 0x288c
movq %r15, %rdi
callq 0x3277
movq %r14, %rdi
callq 0x2040
xorl %edi, %edi
callq 0x2290
leaq 0x187c(%rip), %rdi      # 0x40e0
xorl %eax, %eax
callq 0x3d27
jmp 0x287b
leaq 0x184c(%rip), %rdi      # 0x40c0
xorl %eax, %eax
callq 0x3c08
movl $0x0, (%rbx)
movl %ebp, %edi
callq 0x2180
testl %eax, %eax
je 0x28b5
cmpl $0x0, (%rbx)
jne 0x28a1
leaq 0x1884(%rip), %rdi      # 0x411c
xorl %eax, %eax
callq 0x3d27
jmp 0x28b5
leaq 0x1874(%rip), %rdi      # 0x411c
xorl %eax, %eax
callq 0x3c08
movl $0x0, (%rbx)
movq %r15, %rdi
callq 0x3277
movq %r14, %rdi
callq 0x2040
jmp 0x2661
cmpl $0x0, (%rbx)
jne 0x28fd
leaq 0x1825(%rip), %rdi      # 0x40fb
jmp 0x2738
cmpl $0x0, (%rbx)
jne 0x2909
leaq 0x1807(%rip), %rdi      # 0x40ee
jmp 0x2738
cmpl $0x0, (%rbx)
jne 0x2915
leaq 0x180c(%rip), %rdi      # 0x4104
jmp 0x2738
leaq 0x17f7(%rip), %rdi      # 0x40fb
jmp 0x2874
leaq 0x17de(%rip), %rdi      # 0x40ee
jmp 0x2874
leaq 0x17e8(%rip), %rdi      # 0x4104
jmp 0x2874
nopl (%rax)