// File: /workspace/github_c_makefile_star2_O0/intel[P]pf-bb-config/bb_acc_vfio.c
// Function: vfio_set_token
static int vfio_set_token(hw_device *hwd, int vfio_dev_fd)
{
#ifdef VFIO_DEVICE_FEATURE
	int ret;
	char uuid_string[VFIO_VF_TOKEN_STR_LEN+1];
	struct vfio_device_feature *device_feature;

	device_feature = (struct vfio_device_feature *)
			malloc(sizeof(struct vfio_device_feature) + VFIO_VF_TOKEN_LEN);
	if (device_feature == NULL) {
		LOG(ERR, "memory allocaton failed");
		return -1;
	}

	/* Set the secret token shared between PF and VF */
	LOG(DEBUG, "Setting VFIO_DEVICE_FEATURE with UUID token");

	device_feature->argsz = sizeof(device_feature) + VFIO_VF_TOKEN_LEN;
	device_feature->flags = VFIO_DEVICE_FEATURE_SET |
			VFIO_DEVICE_FEATURE_PCI_VF_TOKEN;
	memcpy(device_feature->data, hwd->vfio_vf_token, VFIO_VF_TOKEN_LEN);
	uuid_unparse(device_feature->data, uuid_string);
	LOG(DEBUG, "[%s]", uuid_string);

	ret = ioctl(vfio_dev_fd, VFIO_DEVICE_FEATURE, device_feature);
	free(device_feature);
	if (ret) {
		LOG(ERR, "Fail to set VFIO_DEVICE_FEATURE with UUID token");
		return -1;
	}
	LOG(DEBUG, "Done");
	return 0;
#else
	LOG(ERR, "VFIO_DEVICE_FEATURE IOCTL is not supported in OS");
	return -1;
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x18, %edi
callq 0xd280
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x20074
callq 0x20230
movq %rax, %rcx
leaq 0x1b87d(%rip), %rax     # 0x3b8d0
movq (%rax), %r8
xorl %esi, %esi
leaq 0x61c6(%rip), %rdx      # 0x26225
movl %esi, %edi
movb $0x0, %al
callq 0x216e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x201a6
callq 0x20230
movq %rax, %rcx
leaq 0x1b84d(%rip), %rax     # 0x3b8d0
movq 0x18(%rax), %r8
movl $0x3, %edi
xorl %esi, %esi
leaq 0x61af(%rip), %rdx      # 0x26244
leaq 0x61e1(%rip), %r9       # 0x2627d
movb $0x0, %al
callq 0x216e0
movq -0x48(%rbp), %rax
movl $0x18, (%rax)
movq -0x48(%rbp), %rax
movl $0x20000, 0x4(%rax)     # imm = 0x20000
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0xdc(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0xe4(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq -0x48(%rbp), %rdi
addq $0x8, %rdi
leaq -0x40(%rbp), %rsi
callq 0x202c0
callq 0x20230
movq %rax, %rcx
leaq 0x1b7da(%rip), %rax     # 0x3b8d0
movq 0x18(%rax), %r8
leaq -0x40(%rbp), %rax
movl $0x3, %edi
xorl %esi, %esi
leaq 0x6180(%rip), %rdx      # 0x2628c
leaq 0x616a(%rip), %r9       # 0x2627d
movq %rax, (%rsp)
movb $0x0, %al
callq 0x216e0
movl -0x14(%rbp), %edi
movq -0x48(%rbp), %rdx
movl $0x3b75, %esi           # imm = 0x3B75
movb $0x0, %al
callq 0xd180
movl %eax, -0x18(%rbp)
movq -0x48(%rbp), %rdi
callq 0xd030
cmpl $0x0, -0x18(%rbp)
je 0x20170
callq 0x20230
movq %rax, %rcx
leaq 0x1b77e(%rip), %rax     # 0x3b8d0
movq (%rax), %r8
xorl %esi, %esi
leaq 0x5da1(%rip), %rdx      # 0x25eff
movl %esi, %edi
movb $0x0, %al
callq 0x216e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x201a6
callq 0x20230
movq %rax, %rcx
leaq 0x1b751(%rip), %rax     # 0x3b8d0
movq 0x18(%rax), %r8
movl $0x3, %edi
xorl %esi, %esi
leaq 0x3531(%rip), %rdx      # 0x236c2
leaq 0x60e5(%rip), %r9       # 0x2627d
movb $0x0, %al
callq 0x216e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop