// File: /workspace/github_c_makefile_star2_O2/intel[P]pf-bb-config/config_app.c
// Function: main
int
main(int argc, char *argv[])
{
	int i, ret = 0, num_devices;
	hw_device device;
	char *found_devices[10];
	char log_file_main[BB_ACC_LOG_FILE_LEN];
	char log_file_resp[BB_ACC_LOG_FILE_LEN];

	memset(&device, 0, sizeof(device));

	if (bbdev_parse_args(argc, argv, &device) > 0)
		return 0;

	event_init_fd();
	printf("%s\n", PF_BB_VERSION);

	/* Set Device Info */
	ret = set_device(&device);
	if (ret != 0) {
		printf("ERR: Device '%s' is not supported\n", device.device_name);
		return 0;
	}

	/* Check if device is installed */
	num_devices = probe_pci_bus(&device, found_devices);
	if (num_devices == 0) {
		printf("ERR: No devices found!!\n");
		return -1;
	} else if (num_devices < 0) {
		return num_devices;
	}

	ret = select_device(&device, found_devices, num_devices);
	if (ret != 0) {
		printf("ERR: Need to select device.\n");
		return -1;
	}

	sprintf(log_file_main, "%s/pf_bb_cfg_%s.log", BB_ACC_DEFAULT_LOG_PATH,
			device.pci_address);
	sprintf(log_file_resp, "%s/pf_bb_cfg_%s_response.log", BB_ACC_DEFAULT_LOG_PATH,
			device.pci_address);
	if (bb_acc_logInit(log_file_main, log_file_resp, BB_ACC_MAX_LOG_FILE_SIZE,
			INFO, device.vfio_mode)) {
		printf("ERR: Logfile init failed\n");
		return -1;
	}

	/* Configure Device */
	ret = configure_device(&device);
	if (ret != 0) {
		printf("ERR: Device configuration failed!\n");
		if (device.vfio_mode)
			printf("Log file = /var/log/pf_bb_cfg_%s.log\n", device.pci_address);
		return ret;
	}

	/* Free memory for stored PCI slots */
	for (i = 0; i < num_devices; i++)
		free(found_devices[i]);

	if (device.vfio_mode) {
		printf("%s PF [%s] configuration complete!\n",
				device.device_name, device.pci_address);
		LOG(INFO, "Running in daemon mode for VFIO VF token");
		printf("Log file = /var/log/pf_bb_cfg_%s.log\n", device.pci_address);
		daemonize(&device);
	}

	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x6e8, %rsp            # imm = 0x6E8
movq %rsi, %r15
movl %edi, %ebp
leaq 0xe0(%rsp), %rdi
xorl %r13d, %r13d
movl $0x580, %edx            # imm = 0x580
xorl %esi, %esi
callq 0xd190
movq (%r15), %rdx
cmpl $0x1, %ebp
je 0xdbc7
movq %rdx, 0x8(%rsp)
movq 0x8(%r15), %rax
leaq 0x1bc(%rsp), %r13
movq %rax, -0xdc(%r13)
leaq 0xd75c(%rip), %rbx      # 0x1b250
movq 0x264dd(%rip), %r12     # 0x33fd8
pushq $0xd
popq %r14
movl %ebp, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xd370
cmpl $0x63, %eax
je 0xdb6c
cmpl $0x66, %eax
je 0xdb40
cmpl $0x70, %eax
je 0xdb4e
cmpl $0x76, %eax
jne 0xdb7a
movl $0x1, 0x19c(%rsp)
movq (%r12), %rdi
movq %r13, %rsi
callq 0x17e31
testl %eax, %eax
jns 0xdaff
jmp 0xe065
movq (%r12), %rax
movq %rax, 0xf0(%rsp)
jmp 0xdaff
movq (%r12), %rsi
leaq 0x100(%rsp), %rdi
movq %r14, %rdx
callq 0xd090
movb $0x0, 0x10e(%rsp)
jmp 0xdaff
movq (%r12), %rax
movq %rax, 0xe8(%rsp)
jmp 0xdaff
cmpl $-0x1, %eax
movl $0x0, %r13d
movq 0x8(%rsp), %rdx
jne 0xdbc7
callq 0x18c8f
leaq 0xd596(%rip), %rdi      # 0x1b12c
callq 0xd0c0
leaq 0xe0(%rsp), %rdi
callq 0xd57c
testl %eax, %eax
je 0xdbf1
movq 0xe0(%rsp), %rsi
leaq 0xd59d(%rip), %rdi      # 0x1b158
xorl %r13d, %r13d
xorl %eax, %eax
callq 0xd160
jmp 0xdbdc
leaq 0xd68c(%rip), %rdi      # 0x1b25a
leaq 0xd557(%rip), %rsi      # 0x1b12c
xorl %eax, %eax
callq 0xd160
movl %r13d, %eax
addq $0x6e8, %rsp            # imm = 0x6E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd61c(%rip), %rdi      # 0x1b214
callq 0xd100
pushq $-0x1
popq %r13
testq %rax, %rax
je 0xdbdc
movq %rax, %r15
cmpb $0x0, 0x100(%rsp)
je 0xdc8f
leaq 0x100(%rsp), %rbp
movq %rbp, %rdi
callq 0xd110
cmpq $0x7, %rax
jne 0xdc50
leaq 0x60(%rsp), %rbx
movw $0x3a, 0x4(%rbx)
movl $0x30303030, (%rbx)     # imm = 0x30303030
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xd3d0
movq %rbp, %rdi
movq %rbx, %rsi
callq 0xd0b0
leaq 0xe0(%rsp), %rdi
movq %rbp, %rsi
callq 0xe06d
xorl %r14d, %r14d
testb %al, %al
je 0xdd26
pushq $0xf
popq %rdi
callq 0xd280
movq %rax, 0x10(%rsp)
pushq $0xd
popq %rdx
movq %rax, %rdi
movq %rbp, %rsi
callq 0xd090
pushq $0x1
popq %r14
jmp 0xdd26
xorl %r14d, %r14d
leaq 0xd9ef(%rip), %r12      # 0x1b688
leaq 0xd9e7(%rip), %r13      # 0x1b687
movq %r15, %rdi
callq 0xd270
testq %rax, %rax
je 0xdd1a
movq %rax, %rbp
addq $0x13, %rbp
movq %rbp, %rdi
callq 0xd110
movq %rax, %rbx
movq %rbp, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0xd0a0
testl %eax, %eax
je 0xdca0
movq %rbp, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xd0a0
testl %eax, %eax
je 0xdca0
leaq 0xe0(%rsp), %rdi
movq %rbp, %rsi
callq 0xe06d
testb %al, %al
je 0xdca0
pushq $0xf
popq %rdi
callq 0xd280
movl %r14d, %ecx
movq %rax, 0x10(%rsp,%rcx,8)
movq %rax, %rdi
movq %rbp, %rsi
pushq $0xd
popq %rdx
callq 0xd090
incl %r14d
jmp 0xdca0
pushq $-0x1
popq %r13
leaq 0x100(%rsp), %rbp
movq %r15, %rdi
callq 0xd1d0
testl %r14d, %r14d
je 0xdd46
movl %r14d, %r12d
cmpl $0x1, %r12d
jne 0xdd52
leaq 0x10(%rsp), %rax
jmp 0xddce
leaq 0xd8a6(%rip), %rdi      # 0x1b5f3
jmp 0xde59
leaq 0xd8b2(%rip), %rdi      # 0x1b60b
callq 0xd0c0
leaq 0xd722(%rip), %rbx      # 0x1b487
xorl %r14d, %r14d
cmpq %r14, %r12
je 0xdd84
movq 0x10(%rsp,%r14,8), %rdx
incq %r14
movq %rbx, %rdi
movl %r14d, %esi
xorl %eax, %eax
callq 0xd160
jmp 0xdd68
leaq 0xd706(%rip), %rdi      # 0x1b491
xorl %eax, %eax
callq 0xd160
leaq 0xe481(%rip), %rdi      # 0x1c21a
leaq 0x60(%rsp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0xd3b0
movslq (%rbx), %rcx
testq %rcx, %rcx
jle 0xde46
cmpl $0x1, %eax
jne 0xde46
cmpl %r12d, %ecx
jg 0xde46
leaq (%rsp,%rcx,8), %rax
addq $0x8, %rax
movq (%rax), %rsi
pushq $0xd
popq %rdx
movq %rbp, %rdi
callq 0xd090
leaq 0xd398(%rip), %rsi      # 0x1b17b
leaq 0xd3a5(%rip), %rbx      # 0x1b18f
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xd3e0
leaq 0xd392(%rip), %rsi      # 0x1b198
leaq 0x660(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xd3e0
movl 0x19c(%rsp), %r8d
pushq $0x2
popq %rcx
movl $0x200000, %edx         # imm = 0x200000
movq %r14, %rdi
movq %r15, %rsi
callq 0x19508
testl %eax, %eax
je 0xde63
leaq 0xd77a(%rip), %rdi      # 0x1b5be
jmp 0xde59
leaq 0xd81a(%rip), %rdi      # 0x1b667
callq 0xd0c0
leaq 0xd77e(%rip), %rdi      # 0x1b5d7
callq 0xd0c0
jmp 0xdbdc
movq 0x110(%rsp), %rax
testq %rax, %rax
je 0xde9e
leaq 0xe0(%rsp), %rdi
callq *%rax
testl %eax, %eax
je 0xde9e
callq 0xe2eb
leaq 0x27046(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
movq 0xe0(%rsp), %r9
leaq 0xd5f8(%rip), %rdx      # 0x1b494
jmp 0xdf10
movq 0x158(%rsp), %rax
testq %rax, %rax
je 0xdf1e
leaq 0xe0(%rsp), %rbx
movl 0xb8(%rbx), %esi
movq %rbp, %rdi
movq %rbx, %rdx
callq *%rax
movq %rax, 0xb0(%rbx)
testq %rax, %rax
je 0xdf1e
leaq 0xe0(%rsp), %rbx
movq 0x8(%rbx), %rdx
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x38(%rbx)
movl %eax, %ebp
callq 0xe2eb
movq (%rbx), %r9
testl %ebp, %ebp
je 0xdf47
leaq 0x26fd6(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
leaq 0x100(%rsp), %rbp
movq %rbp, (%rsp)
leaq 0xd5cc(%rip), %rdx      # 0x1b4dc
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
leaq 0xd677(%rip), %rdi      # 0x1b59c
callq 0xd0c0
cmpl $0x0, 0x19c(%rsp)
je 0xdbdc
leaq 0xd276(%rip), %rdi      # 0x1b1b5
movq %rbp, %rsi
jmp 0xdbbe
leaq 0x26f82(%rip), %r14     # 0x34ed0
movq 0x10(%r14), %r8
leaq 0x100(%rsp), %rbp
movq %rbp, (%rsp)
leaq 0xd54d(%rip), %rdx      # 0x1b4b2
pushq $0x2
popq %rdi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
movq 0x120(%rsp), %rax
testq %rax, %rax
je 0xdfb1
leaq 0xe0(%rsp), %rdi
callq *%rax
testl %eax, %eax
je 0xdfb1
callq 0xe2eb
movq (%r14), %r8
leaq 0xd566(%rip), %rdx      # 0x1b504
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
jmp 0xdf1e
leaq 0xe0(%rsp), %rdi
pushq $0x3
popq %rbx
movl %ebx, %esi
callq 0x19a78
callq 0xe2eb
movq 0x18(%r14), %r8
leaq 0xd551(%rip), %rdx      # 0x1b524
leaq 0xd55c(%rip), %r9       # 0x1b536
xorl %r15d, %r15d
movl %ebx, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
cmpq %r15, %r12
je 0xdfff
movq 0x10(%rsp,%r15,8), %rdi
callq 0xd030
incq %r15
jmp 0xdfeb
cmpl $0x0, 0x19c(%rsp)
je 0xe065
leaq 0xe0(%rsp), %rbx
movq (%rbx), %rsi
leaq 0xd49d(%rip), %rdi      # 0x1b4b8
xorl %r13d, %r13d
movq %rbp, %rdx
xorl %eax, %eax
callq 0xd160
callq 0xe2eb
movq 0x10(%r14), %r8
leaq 0xd1a3(%rip), %rdx      # 0x1b1db
pushq $0x2
popq %rdi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
leaq 0xd167(%rip), %rdi      # 0x1b1b5
movq %rbp, %rsi
xorl %eax, %eax
callq 0xd160
movq %rbx, %rdi
callq 0x1908d
jmp 0xdbdc
xorl %r13d, %r13d
jmp 0xdbdc