// File: /workspace/github_c_makefile_star2_O1/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 0x48d0(%rip), %rdi      # 0x6004
xorl %esi, %esi
xorl %eax, %eax
callq 0x10e0
testl %eax, %eax
js 0x1928
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 0x1931
addq %rax, %r15
cmpq $0xc34f, %r15           # imm = 0xC34F
jbe 0x1752
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 0x5068
testl %eax, %eax
jne 0x1946
leaq 0x18(%rsp), %rsi
movl $0x2, %edi
callq 0x1040
testl %eax, %eax
js 0x194f
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 0x3388
testl %eax, %eax
js 0x1903
decq %rbp
jne 0x17e4
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x4a3c
testl %eax, %eax
js 0x1958
movl $0x8, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x51b8
movq 0x138(%rsp), %rax
decq %rax
cqto
idivq 0x128(%rsp)
imulq $0x64, %rax, %rsi
addq $0x64, %rsi
movq %rbx, %rdi
callq 0x4fbe
movl $0x64, %ebp
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5020
movl $0x8, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x51b8
decq %rbp
jne 0x1857
incq %r13
cmpq $0x32, %r13
jne 0x17df
leaq 0x8(%rsp), %rsi
movl $0x2, %edi
callq 0x1040
testl %eax, %eax
js 0x1961
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
subq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rsp)
subq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
jns 0x18ce
decq %rcx
movq %rcx, 0x8(%rsp)
addq $0x3b9aca00, %rax       # imm = 0x3B9ACA00
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x4784(%rip), %rdi      # 0x6063
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1060
movq 0x178(%rsp), %rdi
callq 0x1030
movq $0x0, 0x178(%rsp)
jmp 0x1914
leaq 0x4737(%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 0x46df(%rip), %rdi      # 0x600e
jmp 0x190a
leaq 0x46db(%rip), %rdi      # 0x6013
callq 0x10f0
movl %ebx, %edi
callq 0x1080
jmp 0x190f
leaq 0x46cb(%rip), %rdi      # 0x6018
jmp 0x190a
leaq 0x46dd(%rip), %rdi      # 0x6033
jmp 0x190a
leaq 0x46f3(%rip), %rdi      # 0x6052
jmp 0x190a
leaq 0x46cb(%rip), %rdi      # 0x6033
callq 0x10f0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x1914