// File: /workspace/github_c_makefile_star2_O3/maandree[P]libkeccak/benchmark.c
// Function: main
int
main(void)
{
	char message[MESSAGE_LEN];
	struct libkeccak_spec spec;
	struct libkeccak_state state;
	char hashsum[OUTPUT / 8];
#ifndef IGNORE_BEHEXING
	char hexsum[OUTPUT / 8 * 2 + 1];
#endif
	struct timespec start, end;
	long int i, r;
	int fd;
	ssize_t got;
	size_t ptr;

	/* Fill message with content from the file. */
	fd = open(MESSAGE_FILE, O_RDONLY);
	if (fd < 0) {
		perror("open");
		return 1;
	}
	for (ptr = 0; ptr < MESSAGE_LEN; ptr += (size_t)got) {
		got = read(fd, message, MESSAGE_LEN - ptr);
		if (got <= 0) {
			perror("read");
			close(fd);
			return 1;
		}
	}
	close(fd);

	/* Initialise state. */
	spec.bitrate = BITRATE;
	spec.capacity = CAPACITY;
	spec.output = OUTPUT;
	if (libkeccak_state_initialise(&state, &spec)) {
		perror("libkeccak_state_initialise");
		return 1;
	}

	/* Get start-time. */
	if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start) < 0) {
		perror("clock_gettime");
		return 1;
	}

	/* Run benchmarking loop. */
	for (r = 0; r < RERUNS; r++) {
		/* Updates. */
#if UPDATE_RUNS > 0
		for (i = 0; i < UPDATE_RUNS; i++) {
			if (libkeccak_fast_update(&state, message, MESSAGE_LEN) < 0) {
				perror("libkeccak_update");
				return 1;
			}
		}
#endif

		/* Digest. */
		if (libkeccak_fast_digest(&state, NULL, 0, 0, NULL, hashsum) < 0) {
			perror("libkeccak_digest");
			return 1;
		}
#ifndef IGNORE_BEHEXING
		libkeccak_behex_lower(hexsum, hashsum, OUTPUT / 8);
#endif

		/* Fast squeezes. */
#if FAST_SQUEEZE_RUNS > 0
		libkeccak_fast_squeeze(&state, FAST_SQUEEZE_RUNS);
#endif

		/* Slow squeezes. */
#if SLOW_SQUEEZE_RUNS > 0
		for (i = 0; i < SLOW_SQUEEZE_RUNS; i++) {
			libkeccak_squeeze(&state, hashsum);
# ifndef IGNORE_BEHEXING
			libkeccak_behex_lower(hexsum, hashsum, OUTPUT / 8);
# endif
		}
#endif
	}

	/* Get end-time. */
	if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end) < 0) {
		perror("clock_gettime");
		return -1;
	}

	/* Print execution-time. */
	end.tv_sec -= start.tv_sec;
	end.tv_nsec -= start.tv_nsec;
	if (end.tv_nsec < 0) {
		end.tv_sec--;
		end.tv_nsec += 1000000000L;
	}
	printf("%03li%09li\n", (long)(end.tv_sec), end.tv_nsec);

	/* Release resources and exit. */
	libkeccak_state_fast_destroy(&state);
	return 0;

#if (UPDATE_RUNS == 0) && (SLOW_SQUEEZE_RUNS == 0)
	(void) i;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc4d8, %rsp           # imm = 0xC4D8
leaq 0x4b60(%rip), %rdi      # 0x6004
xorl %esi, %esi
xorl %eax, %eax
callq 0x10e0
testl %eax, %eax
js 0x1684
movl %eax, %ebx
xorl %r15d, %r15d
leaq 0x180(%rsp), %r14
movl $0xc350, %edx           # imm = 0xC350
subq %r15, %rdx
movl %ebx, %edi
movq %r14, %rsi
callq 0x1090
testq %rax, %rax
jle 0x168d
addq %rax, %r15
cmpq $0xc34f, %r15           # imm = 0xC34F
jbe 0x14c2
movl %ebx, %edi
callq 0x1080
leaq 0x48(%rsp), %rsi
movq $0x80, (%rsi)
movq $0x48, 0x8(%rsi)
movq $0x40, 0x10(%rsi)
leaq 0x60(%rsp), %rdi
callq 0x5734
testl %eax, %eax
jne 0x16a2
leaq 0x10(%rsp), %rsi
movl $0x2, %edi
callq 0x1040
testl %eax, %eax
js 0x16ab
xorl %r13d, %r13d
leaq 0x60(%rsp), %rbx
leaq 0x180(%rsp), %r14
leaq 0x28(%rsp), %r15
leaq 0x30(%rsp), %r12
movl $0x64, %ebp
movl $0xc350, %edx           # imm = 0xC350
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3619
testl %eax, %eax
js 0x165f
decq %rbp
jne 0x1554
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x4fa1
testl %eax, %eax
js 0x16b4
movl $0x8, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x5898
movq 0x138(%rsp), %rax
decq %rax
cqto
idivq 0x128(%rsp)
imulq $0x64, %rax, %rsi
addq $0x64, %rsi
movq %rbx, %rdi
callq 0x568a
movl $0x64, %ebp
movq %rbx, %rdi
movq %r15, %rsi
callq 0x56ec
movl $0x8, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x5898
decq %rbp
jne 0x15c7
incq %r13
cmpq $0x32, %r13
jne 0x154f
movq %rsp, %rsi
movl $0x2, %edi
callq 0x1040
testl %eax, %eax
js 0x16bd
movdqa (%rsp), %xmm0
psubq 0x10(%rsp), %xmm0
movdqa %xmm0, (%rsp)
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
movq %xmm1, %rdx
movq %xmm0, %rsi
testq %rdx, %rdx
jns 0x1640
decq %rsi
movq %rsi, (%rsp)
addq $0x3b9aca00, %rdx       # imm = 0x3B9ACA00
movq %rdx, 0x8(%rsp)
leaq 0x4a1c(%rip), %rdi      # 0x6063
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1060
movq 0x178(%rsp), %rdi
callq 0x1030
jmp 0x1670
leaq 0x49db(%rip), %rdi      # 0x6041
callq 0x10f0
movl $0x1, %ebx
movl %ebx, %eax
addq $0xc4d8, %rsp           # imm = 0xC4D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4983(%rip), %rdi      # 0x600e
jmp 0x1666
leaq 0x497f(%rip), %rdi      # 0x6013
callq 0x10f0
movl %ebx, %edi
callq 0x1080
jmp 0x166b
leaq 0x496f(%rip), %rdi      # 0x6018
jmp 0x1666
leaq 0x4981(%rip), %rdi      # 0x6033
jmp 0x1666
leaq 0x4997(%rip), %rdi      # 0x6052
jmp 0x1666
leaq 0x496f(%rip), %rdi      # 0x6033
callq 0x10f0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x1670