// File: /workspace/github_c_makefile_star2_O0/WereCatf[P]Gonzales/bench.c
// Function: main
int main(int argc, char* argv[])
{
	struct timespec timeStart, timeEnd;
	uint32_t counter;
	double accum;

	int error=initGpio();
	if(error==1){
		printf("Error opening /dev/mem!\n");
		return 1;
	} else if(error==2){
		printf("Error mmapping memory!\n");
		return 2;
	}

	int origMux, origValue;
	origMux = readMux(3, 25);
	origValue = readPin(3, 25);
	writeMux(3, 25, _GPIO_MUX_OUT);

#ifdef _WITH_LIBSOC
	gpio *testPin;
	int libsocOrigMux;
	testPin = libsoc_gpio_request(121, LS_SHARED);
	if(testPin == NULL)
	{
			printf("Error setting up libsoc!\n");
			return 1;
	}
	libsocOrigMux = libsoc_gpio_get_direction(testPin);
	libsoc_gpio_set_direction(testPin, OUTPUT);
	printf("Test 10 million pin-togglings using libsoc on PD25...\n");
	clock_gettime(CLOCK_MONOTONIC, &timeStart);
	for(counter=0; counter<5000000; counter++){
		libsoc_gpio_set_level(testPin, LOW);
		libsoc_gpio_set_level(testPin, HIGH);
	}
	clock_gettime(CLOCK_MONOTONIC, &timeEnd);
	accum = ( timeEnd.tv_sec - timeStart.tv_sec )
		+ ( timeEnd.tv_nsec - timeStart.tv_nsec )
		/ 1E9;
	printf( "That took %.02lf seconds at ~%.02lfMbps\n", accum,  1E7 / accum / 1E6);
#endif

	printf("Test 10 million pin-togglings using writePin on PD25...\n");
	clock_gettime(CLOCK_MONOTONIC, &timeStart);
	for(counter=0; counter<5000000; counter++){
		writePin(3, 25, _GPIO_LOW);
		writePin(3, 25, _GPIO_HIGH);
	}
	clock_gettime(CLOCK_MONOTONIC, &timeEnd);
	accum = ( timeEnd.tv_sec - timeStart.tv_sec )
		+ ( timeEnd.tv_nsec - timeStart.tv_nsec )
		/ 1E9;
	printf( "That took %.02lf seconds at ~%.02lfMbps\n", accum,  1E7 / accum / 1E6);

	printf("Test 10 million pin-togglings using clearPort and setPort on PD25...\n");
	uint32_t mask = 1 << 25;
	clock_gettime(CLOCK_MONOTONIC, &timeStart);
	for(counter=0; counter<5000000; counter++){
		clearPort(3, mask); //Toggle pin LOW
		setPort(3, mask); //Toggle pin HIGH
	}
	clock_gettime(CLOCK_MONOTONIC, &timeEnd);
	accum = ( timeEnd.tv_sec - timeStart.tv_sec )
		+ ( timeEnd.tv_nsec - timeStart.tv_nsec )
		/ 1E9;
	printf( "That took %.02lf seconds at ~%.02lfMbps\n", accum,  1E7 / accum / 1E6);

#ifdef _WITH_LIBSOC
	libsoc_gpio_set_direction(testPin, libsocOrigMux);
	libsoc_gpio_free(testPin);
#endif

	writeMux(3, 25, origMux);
	writePin(3, 25, origValue);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, %al
callq 0x2590
movl %eax, -0x44(%rbp)
cmpl $0x1, -0x44(%rbp)
jne 0x21d0
leaq 0xe63(%rip), %rdi       # 0x3020
movb $0x0, %al
callq 0x2050
movl $0x1, -0x4(%rbp)
jmp 0x23da
cmpl $0x2, -0x44(%rbp)
jne 0x21f0
leaq 0xe5c(%rip), %rdi       # 0x3039
movb $0x0, %al
callq 0x2050
movl $0x2, -0x4(%rbp)
jmp 0x23da
jmp 0x21f2
movl $0x3, %edi
movl $0x19, %esi
callq 0x2630
movl %eax, -0x48(%rbp)
movl $0x3, %edi
movl $0x19, %esi
callq 0x2930
movl %eax, -0x4c(%rbp)
movl $0x3, %edi
movl $0x19, %esi
movl $0x1, %edx
callq 0x2680
leaq 0xe20(%rip), %rdi       # 0x3051
movb $0x0, %al
callq 0x2050
movl $0x1, %edi
leaq -0x20(%rbp), %rsi
callq 0x2030
movl $0x0, -0x34(%rbp)
cmpl $0x4c4b40, -0x34(%rbp)  # imm = 0x4C4B40
jae 0x2286
movl $0x3, %edi
movl $0x19, %esi
xorl %edx, %edx
callq 0x2970
movl $0x3, %edi
movl $0x19, %esi
movl $0x1, %edx
callq 0x2970
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x224d
movl $0x1, %edi
leaq -0x30(%rbp), %rsi
callq 0x2030
movq -0x30(%rbp), %rax
subq -0x20(%rbp), %rax
cvtsi2sd %rax, %xmm0
movq -0x28(%rbp), %rax
subq -0x18(%rbp), %rax
cvtsi2sd %rax, %xmm1
movsd 0xd62(%rip), %xmm2      # 0x3018
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movsd 0xd40(%rip), %xmm1      # 0x3010
divsd -0x40(%rbp), %xmm1
movsd 0xd2b(%rip), %xmm2      # 0x3008
divsd %xmm2, %xmm1
leaq 0xda2(%rip), %rdi       # 0x308a
movb $0x2, %al
callq 0x2050
leaq 0xdbd(%rip), %rdi       # 0x30b3
movb $0x0, %al
callq 0x2050
movl $0x2000000, -0x50(%rbp) # imm = 0x2000000
movl $0x1, %edi
leaq -0x20(%rbp), %rsi
callq 0x2030
movl $0x0, -0x34(%rbp)
cmpl $0x4c4b40, -0x34(%rbp)  # imm = 0x4C4B40
jae 0x2347
movl -0x50(%rbp), %esi
movl $0x3, %edi
callq 0x28b0
movl -0x50(%rbp), %esi
movl $0x3, %edi
callq 0x28f0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2319
movl $0x1, %edi
leaq -0x30(%rbp), %rsi
callq 0x2030
movq -0x30(%rbp), %rax
subq -0x20(%rbp), %rax
cvtsi2sd %rax, %xmm0
movq -0x28(%rbp), %rax
subq -0x18(%rbp), %rax
cvtsi2sd %rax, %xmm1
movsd 0xca1(%rip), %xmm2      # 0x3018
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movsd 0xc7f(%rip), %xmm1      # 0x3010
divsd -0x40(%rbp), %xmm1
movsd 0xc6a(%rip), %xmm2      # 0x3008
divsd %xmm2, %xmm1
leaq 0xce1(%rip), %rdi       # 0x308a
movb $0x2, %al
callq 0x2050
movl -0x48(%rbp), %eax
movl $0x3, %edi
movl $0x19, %esi
movzbl %al, %edx
callq 0x2680
movl -0x4c(%rbp), %eax
movl $0x3, %edi
movl $0x19, %esi
movzbl %al, %edx
callq 0x2970
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)