// File: /workspace/github_c_makefile_star2_O2/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 $0xc4e8, %rsp           # imm = 0xC4E8
leaq 0x3ad0(%rip), %rdi      # 0x5004
xorl %esi, %esi
xorl %eax, %eax
callq 0x10e0
testl %eax, %eax
js 0x1715
movl %eax, %ebx
xorl %r15d, %r15d
leaq 0x190(%rsp), %r14
cmpq $0xc34f, %r15           # imm = 0xC34F
ja 0x158d
movl $0xc350, %edx           # imm = 0xC350
subq %r15, %rdx
movl %ebx, %edi
movq %r14, %rsi
callq 0x1090
addq %rax, %r15
testq %rax, %rax
jg 0x1552
leaq 0x3a97(%rip), %rdi      # 0x5013
callq 0x10f0
movl %ebx, %edi
callq 0x1080
jmp 0x1695
movl %ebx, %edi
callq 0x1080
leaq 0x58(%rsp), %rsi
movq $0x80, (%rsi)
movq $0x48, 0x8(%rsi)
movq $0x40, 0x10(%rsi)
leaq 0x70(%rsp), %rdi
callq 0x4280
testl %eax, %eax
jne 0x1721
pushq $0x2
popq %rdi
leaq 0x20(%rsp), %rsi
callq 0x1040
testl %eax, %eax
js 0x172d
xorl %eax, %eax
leaq 0x70(%rsp), %rbx
leaq 0x38(%rsp), %r14
leaq 0x40(%rsp), %r15
pushq $0x8
popq %r12
leaq 0x190(%rsp), %rbp
cmpq $0x32, %rax
je 0x169a
movq %rax, 0x18(%rsp)
pushq $0x65
popq %r13
decq %r13
je 0x1622
movl $0xc350, %edx           # imm = 0xC350
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x24a5
testl %eax, %eax
jns 0x1607
jmp 0x1689
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r14, %r9
callq 0x3d49
testl %eax, %eax
js 0x174c
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x43ac
movq %rbx, %rdi
pushq $0x64
popq %r13
movq %r13, %rsi
callq 0x4219
subq $0x1, %r13
jb 0x167c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4238
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x43ac
jmp 0x165b
movq 0x18(%rsp), %rax
incq %rax
jmp 0x15f4
leaq 0x39b1(%rip), %rdi      # 0x5041
callq 0x10f0
pushq $0x1
popq %rbx
jmp 0x1701
pushq $0x2
popq %rdi
movq %rsp, %rsi
callq 0x1040
testl %eax, %eax
js 0x1739
movdqa (%rsp), %xmm0
psubq 0x20(%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 0x16e4
decq %rsi
movq %rsi, (%rsp)
addq $0x3b9aca00, %rdx       # imm = 0x3B9ACA00
movq %rdx, 0x8(%rsp)
leaq 0x3978(%rip), %rdi      # 0x5063
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1060
movq 0x188(%rsp), %rdi
callq 0x1030
movl %ebx, %eax
addq $0xc4e8, %rsp           # imm = 0xC4E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x38f2(%rip), %rdi      # 0x500e
jmp 0x1690
leaq 0x38f0(%rip), %rdi      # 0x5018
jmp 0x1690
leaq 0x38ff(%rip), %rdi      # 0x5033
jmp 0x1690
leaq 0x38f3(%rip), %rdi      # 0x5033
callq 0x10f0
pushq $-0x1
jmp 0x1697
leaq 0x38ff(%rip), %rdi      # 0x5052
jmp 0x1690