// File: /workspace/github_c_makefile_star2_O0/sguerrini97[P]ps3linux-ps3vuart-tools/ps3dm/sm/cmd_sm_set_encdec_key.c
// Function: cmd_sm_set_encdec_key_exec
int
cmd_sm_set_encdec_key_exec(int cmdc, struct cmd **cmdv, int argc, char **argv)
{
	struct ps3dm_sm_set_encdec_key set_encdec_key;
	uint64_t laid, paid;
	uint8_t key[24];
	int key_length;
	int ret;

	key_length = parse_hex(argv[0], key, sizeof(key));
	if (key_length <= 0)
		return (CMD_EINVAL);

	laid = opts.laid_valid ? opts.laid : 0x1070000002000001ull;
	paid = opts.paid_valid ? opts.paid : 0x10700003ff000001ull;

	ps3dm_init_header(&set_encdec_key.dm_hdr, 1, PS3DM_FID_SM,
	    sizeof(set_encdec_key) - sizeof(struct ps3dm_header),
	    sizeof(set_encdec_key) - sizeof(struct ps3dm_header));
	ps3dm_init_ss_header(&set_encdec_key.ss_hdr, PS3DM_PID_SM_SET_ENCDEC_KEY,
	    laid, paid);
	memset(set_encdec_key.key, 0, sizeof(set_encdec_key.key));
	memcpy(set_encdec_key.key, key, key_length);
	set_encdec_key.key_length = key_length;

	ret = dev_write(&set_encdec_key, sizeof(set_encdec_key));
	if (ret != sizeof(set_encdec_key))
		return (CMD_EIO);

	ret = dev_read(&set_encdec_key, sizeof(set_encdec_key));
	if (ret != sizeof(set_encdec_key))
		return (CMD_EIO);

	if (opts.do_verbose > 0)
		fprintf(stderr, "ss status %d\n", set_encdec_key.ss_hdr.status);

	if (set_encdec_key.ss_hdr.status)
		return (CMD_EIO);

	fprintf(stdout, "%llx\n", set_encdec_key.key_index);

	return (CMD_EOK);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0xb0(%rbp), %rsi
movl $0x18, %edx
callq 0x54f0
movl %eax, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
jg 0x30ec
movl $0x2, -0x4(%rbp)
jmp 0x3297
leaq 0x5fcd(%rip), %rax      # 0x90c0
cmpl $0x0, 0x20(%rax)
je 0x310d
leaq 0x5fc0(%rip), %rax      # 0x90c0
movq 0x18(%rax), %rax
movq %rax, -0xc0(%rbp)
jmp 0x3120
movabsq $0x1070000002000001, %rax # imm = 0x1070000002000001
movq %rax, -0xc0(%rbp)
jmp 0x3120
movq -0xc0(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq 0x5f8b(%rip), %rax      # 0x90c0
cmpl $0x0, 0x30(%rax)
je 0x314f
leaq 0x5f7e(%rip), %rax      # 0x90c0
movq 0x28(%rax), %rax
movq %rax, -0xc8(%rbp)
jmp 0x3162
movabsq $0x10700003ff000001, %rax # imm = 0x10700003FF000001
movq %rax, -0xc8(%rbp)
jmp 0x3162
movq -0xc8(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x80(%rbp), %rdi
movl $0x1, %esi
movl $0x5000, %edx           # imm = 0x5000
movl $0x50, %r8d
movl %r8d, %ecx
callq 0x32b0
leaq -0x80(%rbp), %rdi
addq $0x10, %rdi
movq -0x88(%rbp), %rdx
movq -0x90(%rbp), %rcx
movl $0x5001, %esi           # imm = 0x5001
callq 0x32f0
leaq -0x80(%rbp), %rdi
addq $0x38, %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2070
leaq -0x80(%rbp), %rdi
addq $0x38, %rdi
leaq -0xb0(%rbp), %rsi
movslq -0xb4(%rbp), %rdx
callq 0x20d0
movslq -0xb4(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x80(%rbp), %rdi
movl $0x60, %esi
callq 0x2620
movl %eax, -0xb8(%rbp)
movslq -0xb8(%rbp), %rax
cmpq $0x60, %rax
je 0x3213
movl $0x3, -0x4(%rbp)
jmp 0x3297
leaq -0x80(%rbp), %rdi
movl $0x60, %esi
callq 0x2670
movl %eax, -0xb8(%rbp)
movslq -0xb8(%rbp), %rax
cmpq $0x60, %rax
je 0x323d
movl $0x3, -0x4(%rbp)
jmp 0x3297
leaq 0x5e7c(%rip), %rax      # 0x90c0
cmpl $0x0, 0x8(%rax)
jle 0x3265
movq 0x5da7(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movl -0x60(%rbp), %edx
leaq 0x2fc6(%rip), %rsi      # 0x6224
movb $0x0, %al
callq 0x20c0
cmpl $0x0, -0x60(%rbp)
je 0x3274
movl $0x3, -0x4(%rbp)
jmp 0x3297
movq 0x5d4d(%rip), %rax      # 0x8fc8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x3067(%rip), %rsi      # 0x62f0
movb $0x0, %al
callq 0x20c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)