// File: /workspace/github_c_makefile_star2_O3/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
movl $0x580, %edx            # imm = 0x580
xorl %esi, %esi
callq 0xd180
movq (%r15), %r12
cmpl $0x1, %ebp
jne 0xdaec
leaq 0xd797(%rip), %rdi      # 0x1b25a
leaq 0xd662(%rip), %rsi      # 0x1b12c
movq %r12, %rdx
xorl %eax, %eax
callq 0xd150
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x6e8, %rsp            # imm = 0x6E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r15), %rax
leaq 0x1bc(%rsp), %r13
movq %rax, -0xdc(%r13)
leaq 0xd74a(%rip), %rbx      # 0x1b250
movq 0x254cb(%rip), %r14     # 0x32fd8
movl %ebp, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xd360
cmpl $0x6f, %eax
jg 0xdb36
cmpl $0x63, %eax
je 0xdb63
cmpl $0x66, %eax
jne 0xdb92
movq (%r14), %rax
movq %rax, 0xf0(%rsp)
jmp 0xdb0d
cmpl $0x70, %eax
je 0xdb70
cmpl $0x76, %eax
jne 0xdabc
movl $0x1, 0x19c(%rsp)
movq (%r14), %rdi
movq %r13, %rsi
callq 0x182ef
testl %eax, %eax
jns 0xdb0d
jmp 0xdad4
movq (%r14), %rax
movq %rax, 0xe8(%rsp)
jmp 0xdb0d
movq (%r14), %rsi
movl $0xd, %edx
leaq 0x100(%rsp), %rdi
callq 0xd090
movb $0x0, 0x10e(%rsp)
jmp 0xdb0d
cmpl $-0x1, %eax
jne 0xdabc
callq 0x191a7
leaq 0xd585(%rip), %rdi      # 0x1b12c
callq 0xd0c0
leaq 0xe0(%rsp), %rdi
callq 0xd56c
testl %eax, %eax
je 0xdbdb
movq 0xe0(%rsp), %rsi
leaq 0xd58c(%rip), %rdi      # 0x1b158
xorl %r14d, %r14d
xorl %eax, %eax
callq 0xd150
jmp 0xdad7
leaq 0xd632(%rip), %rdi      # 0x1b214
callq 0xd100
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0xdad7
movq %rax, %r15
cmpb $0x0, 0x100(%rsp)
je 0xdd17
leaq 0x100(%rsp), %r12
movq %r12, %rdi
callq 0xd110
cmpq $0x7, %rax
jne 0xdc44
leaq 0x60(%rsp), %rbx
movw $0x3a, 0x4(%rbx)
movl $0x30303030, (%rbx)     # imm = 0x30303030
movq %rbx, %rdi
movq %r12, %rsi
callq 0xd3c0
movq %r12, %rdi
movq %rbx, %rsi
callq 0xd0b0
leaq 0xe0(%rsp), %rdi
movq %r12, %rsi
callq 0xe0c0
testb %al, %al
je 0xddcb
movl $0xf, %edi
callq 0xd270
movq %rax, %rbx
movq %rax, 0x10(%rsp)
movl $0xd, %edx
movq %rax, %rdi
leaq 0x100(%rsp), %rbp
movq %rbp, %rsi
callq 0xd090
movq %r15, %rdi
callq 0xd1c0
movl $0x1, %r13d
movl $0xd, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0xd090
leaq 0xd4d0(%rip), %rsi      # 0x1b17b
leaq 0xd4dd(%rip), %rbx      # 0x1b18f
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xd3d0
leaq 0xd4ca(%rip), %rsi      # 0x1b198
leaq 0x660(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xd3d0
movl 0x19c(%rsp), %r8d
movl $0x200000, %edx         # imm = 0x200000
movq %r15, %rdi
movq %r12, %rsi
movl $0x2, %ecx
callq 0x19abe
testl %eax, %eax
je 0xde18
leaq 0xd8ac(%rip), %rdi      # 0x1b5be
jmp 0xddda
movq %r15, %rdi
callq 0xd260
testq %rax, %rax
je 0xddcb
movq %rax, %rbp
movq $0x0, 0x8(%rsp)
leaq 0xd94d(%rip), %r12      # 0x1b688
leaq 0xd945(%rip), %r13      # 0x1b687
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 0xdd75
movq %rbp, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xd0a0
testl %eax, %eax
jne 0xdd87
movq %r15, %rdi
callq 0xd260
movq %rax, %rbp
testq %rax, %rax
jne 0xdd42
jmp 0xdde4
leaq 0xe0(%rsp), %rdi
movq %rbp, %rsi
callq 0xe0c0
testb %al, %al
je 0xdd75
movl $0xf, %edi
callq 0xd270
movq 0x8(%rsp), %rbx
movslq %ebx, %rbx
movq %rax, 0x10(%rsp,%rbx,8)
movl $0xd, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0xd090
incl %ebx
movq %rbx, 0x8(%rsp)
jmp 0xdd75
movq %r15, %rdi
callq 0xd1c0
leaq 0xd819(%rip), %rdi      # 0x1b5f3
callq 0xd0c0
jmp 0xdad7
movq %r15, %rdi
callq 0xd1c0
movq 0x8(%rsp), %rax
testl %eax, %eax
je 0xddd3
js 0xde52
cmpl $0x1, %eax
jne 0xdee1
movl $0x1, %r13d
movq 0x10(%rsp), %rbx
leaq 0x100(%rsp), %rbp
jmp 0xdc94
leaq 0xe0(%rsp), %rdi
callq 0xdf74
testl %eax, %eax
je 0xde5a
leaq 0xd76c(%rip), %rdi      # 0x1b59c
callq 0xd0c0
cmpl $0x0, 0x19c(%rsp)
je 0xdad7
leaq 0xd36b(%rip), %rdi      # 0x1b1b5
movq %rbp, %rsi
jmp 0xdbcf
movl %eax, %r14d
jmp 0xdad7
xorl %ebx, %ebx
movq 0x10(%rsp,%rbx,8), %rdi
callq 0xd030
incq %rbx
cmpq %rbx, %r13
jne 0xde5c
cmpl $0x0, 0x19c(%rsp)
je 0xdad4
leaq 0xe0(%rsp), %rbx
movq (%rbx), %rsi
leaq 0xd62a(%rip), %rdi      # 0x1b4b8
xorl %r14d, %r14d
movq %rbp, %rdx
xorl %eax, %eax
callq 0xd150
callq 0xe36f
leaq 0x26029(%rip), %rcx     # 0x33ed0
movq 0x10(%rcx), %r8
leaq 0xd329(%rip), %rdx      # 0x1b1db
movl $0x2, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
leaq 0xd2eb(%rip), %rdi      # 0x1b1b5
movq %rbp, %rsi
xorl %eax, %eax
callq 0xd150
movq %rbx, %rdi
callq 0x19606
jmp 0xdad7
movl %eax, %r13d
leaq 0xd720(%rip), %rdi      # 0x1b60b
callq 0xd0c0
leaq 0xd590(%rip), %rbx      # 0x1b487
xorl %r15d, %r15d
leaq 0x100(%rsp), %rbp
movq 0x10(%rsp,%r15,8), %rdx
incq %r15
movq %rbx, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0xd150
cmpq %r15, %r13
jne 0xdf02
leaq 0xd56e(%rip), %rdi      # 0x1b491
xorl %eax, %eax
callq 0xd150
leaq 0xe32d(%rip), %rdi      # 0x1c25e
leaq 0x60(%rsp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0xd3a0
movslq (%rbx), %rcx
testq %rcx, %rcx
jle 0xdf5c
cmpl $0x1, %eax
jne 0xdf5c
cmpl %r13d, %ecx
jg 0xdf5c
movq 0x8(%rsp,%rcx,8), %rbx
jmp 0xdc94
leaq 0xd704(%rip), %rdi      # 0x1b667
callq 0xd0c0
leaq 0xd668(%rip), %rdi      # 0x1b5d7
jmp 0xddda