// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x6f0, %rsp            # imm = 0x6F0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
leaq -0x5a0(%rbp), %rdi
xorl %esi, %esi
movl $0x580, %edx            # imm = 0x580
callq 0xd170
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0x5a0(%rbp), %rdx
callq 0xdf80
cmpl $0x0, %eax
jle 0xdd17
movl $0x0, -0x4(%rbp)
jmp 0xdf71
callq 0x20b50
leaq 0x18a6d(%rip), %rdi     # 0x26790
leaq 0x15491(%rip), %rsi     # 0x231bb
movb $0x0, %al
callq 0xd140
leaq -0x5a0(%rbp), %rdi
callq 0xd570
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0xdd67
movq -0x5a0(%rbp), %rsi
leaq 0x15493(%rip), %rdi     # 0x231e7
movb $0x0, %al
callq 0xd140
movl $0x0, -0x4(%rbp)
jmp 0xdf71
leaq -0x5f0(%rbp), %rsi
leaq -0x5a0(%rbp), %rdi
callq 0xe0d0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0xdd9d
leaq 0x15480(%rip), %rdi     # 0x2320a
movb $0x0, %al
callq 0xd140
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xdf71
cmpl $0x0, -0x1c(%rbp)
jge 0xddae
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xdf71
jmp 0xddb0
leaq -0x5f0(%rbp), %rsi
movl -0x1c(%rbp), %edx
leaq -0x5a0(%rbp), %rdi
callq 0xe2b0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0xdde9
leaq 0x1544d(%rip), %rdi     # 0x23223
movb $0x0, %al
callq 0xd140
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xdf71
leaq -0x670(%rbp), %rdi
leaq -0x5a0(%rbp), %rcx
addq $0x20, %rcx
leaq 0x1543e(%rip), %rsi     # 0x23240
leaq 0x1544b(%rip), %rdx     # 0x23254
movb $0x0, %al
callq 0xd3e0
leaq -0x6f0(%rbp), %rdi
leaq -0x5a0(%rbp), %rcx
addq $0x20, %rcx
leaq 0x15434(%rip), %rsi     # 0x2325d
leaq 0x15424(%rip), %rdx     # 0x23254
movb $0x0, %al
callq 0xd3e0
leaq -0x670(%rbp), %rdi
leaq -0x6f0(%rbp), %rsi
movl -0x4e4(%rbp), %r8d
movl $0x200000, %edx         # imm = 0x200000
movl $0x2, %ecx
callq 0x21860
cmpl $0x0, %eax
je 0xde7a
leaq 0x15413(%rip), %rdi     # 0x2327a
movb $0x0, %al
callq 0xd140
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xdf71
leaq -0x5a0(%rbp), %rdi
callq 0xe3c0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0xdeca
leaq 0x153fe(%rip), %rdi     # 0x23294
movb $0x0, %al
callq 0xd140
cmpl $0x0, -0x4e4(%rbp)
je 0xdebf
leaq -0x5a0(%rbp), %rsi
addq $0x20, %rsi
leaq 0x153ff(%rip), %rdi     # 0x232b7
movb $0x0, %al
callq 0xd140
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xdf71
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xdef5
movslq -0x14(%rbp), %rax
movq -0x5f0(%rbp,%rax,8), %rdi
callq 0xd030
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xded1
cmpl $0x0, -0x4e4(%rbp)
je 0xdf6b
movq -0x5a0(%rbp), %rsi
leaq -0x5a0(%rbp), %rdx
addq $0x20, %rdx
leaq 0x1573f(%rip), %rdi     # 0x23656
movb $0x0, %al
callq 0xd140
callq 0xe9a0
movq %rax, %rcx
leaq 0x2d9a3(%rip), %rax     # 0x3b8d0
movq 0x10(%rax), %r8
movl $0x2, %edi
xorl %esi, %esi
leaq 0x1539e(%rip), %rdx     # 0x232dd
movb $0x0, %al
callq 0x216e0
leaq -0x5a0(%rbp), %rsi
addq $0x20, %rsi
leaq 0x1535f(%rip), %rdi     # 0x232b7
movb $0x0, %al
callq 0xd140
leaq -0x5a0(%rbp), %rdi
callq 0x211b0
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x6f0, %rsp            # imm = 0x6F0
popq %rbp
retq
nopl (%rax)