// File: /workspace/github_c_makefile_star2_O1/albertito[P]libfiu/libfiu/fiu-rc.c
// Function: fiu_rc_string
int fiu_rc_string(const char *cmd, char **const error)
{
	char m_cmd[MAX_LINE] = {0};
	char command[MAX_LINE] = {0};
	char parameters[MAX_LINE] = {0};

	/* We need a version of cmd we can write to for parsing */
	strncpy(m_cmd, cmd, MAX_LINE - 1);

	/* Separate command and parameters */
	{
		char *tok = NULL, *state = NULL;

		tok = strtok_r(m_cmd, " \t", &state);
		if (tok == NULL) {
			*error = "Cannot get command";
			return -1;
		}
		strncpy(command, tok, MAX_LINE - 1);

		tok = strtok_r(NULL, " \t", &state);
		if (tok == NULL) {
			*error = "Cannot get parameters";
			return -1;
		}
		strncpy(parameters, tok, MAX_LINE - 1);
	}

	/* Parsing of parameters.
	 *
	 * To simplify the code, we parse the command parameters here. Not all
	 * commands use all the parameters, but since they're not ambiguous it
	 * makes it easier to do it this way. */
	char *fp_name = NULL;
	int failnum = 1;
	void *failinfo = NULL;
	unsigned int flags = 0;
	double probability = -1;
	char *func_name = NULL;
	int func_pos_in_stack = -1;

	{
		/* Different tokens that we accept as parameters */
		enum {
			OPT_NAME = 0,
			OPT_FAILNUM,
			OPT_FAILINFO,
			OPT_PROBABILITY,
			OPT_FUNC_NAME,
			OPT_POS_IN_STACK,
			FLAG_ONETIME,
		};
		char *const token[] = {[OPT_NAME] = "name",
		                       [OPT_FAILNUM] = "failnum",
		                       [OPT_FAILINFO] = "failinfo",
		                       [OPT_PROBABILITY] = "probability",
		                       [OPT_FUNC_NAME] = "func_name",
		                       [OPT_POS_IN_STACK] = "pos_in_stack",
		                       [FLAG_ONETIME] = "onetime",
		                       NULL};

		char *value;
		char *opts = parameters;
		while (*opts != '\0') {
			switch (getsubopt(&opts, token, &value)) {
			case OPT_NAME:
				fp_name = value;
				break;
			case OPT_FAILNUM:
				failnum = atoi(value);
				break;
			case OPT_FAILINFO:
				failinfo = (void *)strtoul(value, NULL, 10);
				break;
			case OPT_PROBABILITY:
				probability = strtod(value, NULL);
				break;
			case OPT_FUNC_NAME:
				func_name = value;
				break;
			case OPT_POS_IN_STACK:
				func_pos_in_stack = atoi(value);
				break;
			case FLAG_ONETIME:
				flags |= FIU_ONETIME;
				break;
			default:
				*error = "Unknown parameter";
				return -1;
			}
		}
	}

	/* Excecute the command */
	if (strcmp(command, "disable") == 0) {
		*error = "Error in disable";
		return fiu_disable(fp_name);
	} else if (strcmp(command, "enable") == 0) {
		*error = "Error in enable";
		return fiu_enable(fp_name, failnum, failinfo, flags);
	} else if (strcmp(command, "enable_random") == 0) {
		*error = "Error in enable_random";
		return fiu_enable_random(fp_name, failnum, failinfo, flags,
		                         probability);
	} else if (strcmp(command, "enable_stack_by_name") == 0) {
		*error = "Error in enable_stack_by_name";
		return fiu_enable_stack_by_name(fp_name, failnum, failinfo,
		                                flags, func_name,
		                                func_pos_in_stack);
	} else {
		*error = "Unknown command";
		return -1;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x688, %rsp            # imm = 0x688
movq %rsi, %r12
movq %rdi, %r15
leaq 0x480(%rsp), %r14
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
xorl %esi, %esi
callq 0x2170
leaq 0x80(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x2170
leaq 0x280(%rsp), %rbx
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2170
movl $0x1ff, %edx            # imm = 0x1FF
movq %r14, %rdi
movq %r15, %rsi
callq 0x2080
leaq 0x40(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x2590(%rip), %rsi      # 0x507c
movq %r14, %rdi
callq 0x21c0
testq %rax, %rax
je 0x2c88
leaq 0x80(%rsp), %rdi
movl $0x1ff, %edx            # imm = 0x1FF
movq %rax, %rsi
callq 0x2080
leaq 0x2563(%rip), %rsi      # 0x507c
xorl %r14d, %r14d
leaq 0x40(%rsp), %rdx
xorl %edi, %edi
callq 0x21c0
testq %rax, %rax
je 0x2c91
movl $0x1ff, %edx            # imm = 0x1FF
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2080
movaps 0x5278(%rip), %xmm0     # 0x7dc0
movaps %xmm0, 0x70(%rsp)
movaps 0x525c(%rip), %xmm0     # 0x7db0
movaps %xmm0, 0x60(%rsp)
movaps 0x5240(%rip), %xmm0     # 0x7da0
movaps %xmm0, 0x50(%rsp)
movaps 0x5224(%rip), %xmm0     # 0x7d90
movaps %xmm0, 0x40(%rsp)
movq %rbx, 0x38(%rsp)
cmpb $0x0, 0x280(%rsp)
je 0x2ca6
movq %r12, 0x20(%rsp)
movl $0x1, 0x14(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x248e(%rip), %xmm0     # 0x5030
movq %xmm0, 0x28(%rsp)
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
leaq 0x38(%rsp), %r15
leaq 0x40(%rsp), %r12
leaq 0x8(%rsp), %rbp
leaq 0x249a(%rip), %rbx      # 0x5060
movq $0x0, 0x30(%rsp)
xorl %r13d, %r13d
xorl %r14d, %r14d
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x2090
cmpl $0x6, %eax
ja 0x2da4
movl %eax, %eax
movslq (%rbx,%rax,4), %rax
addq %rbx, %rax
jmpq *%rax
movq 0x8(%rsp), %r14
jmp 0x2c5e
movq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x2c5e
movq 0x8(%rsp), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x22d0
movq %rax, %r13
jmp 0x2c5e
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x20b0
movq %xmm0, 0x28(%rsp)
jmp 0x2c5e
movq 0x8(%rsp), %rdi
callq 0x22f0
movl %eax, 0x14(%rsp)
jmp 0x2c5e
movq 0x8(%rsp), %rdi
callq 0x22f0
movl %eax, 0x4(%rsp)
jmp 0x2c5e
movl $0x1, %eax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x2bd5
xorps %xmm0, %xmm0
cvtsd2ss 0x28(%rsp), %xmm0
movq 0x20(%rsp), %r12
movl 0x14(%rsp), %esi
movq %r14, %rdi
movq 0x30(%rsp), %r14
jmp 0x2cc9
leaq 0x23f0(%rip), %rax      # 0x507f
jmp 0x2c98
leaq 0x23fa(%rip), %rax      # 0x5092
movq %rax, (%r12)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x2dd8
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movss 0x2372(%rip), %xmm0     # 0x5028
movl $0x1, %esi
xorl %edi, %edi
xorl %r13d, %r13d
movq $0x0, 0x18(%rsp)
movabsq $0x656c6261736964, %rax # imm = 0x656C6261736964
cmpq %rax, 0x80(%rsp)
jne 0x2cf2
leaq 0x2412(%rip), %rax      # 0x50f6
movq %rax, (%r12)
callq 0x2050
jmp 0x2dd8
movl $0x62616e65, %eax       # imm = 0x62616E65
xorl 0x80(%rsp), %eax
movl $0x656c62, %ecx         # imm = 0x656C62
xorl 0x83(%rsp), %ecx
orl %eax, %ecx
je 0x2d74
movabsq $0x725f656c62616e65, %rax # imm = 0x725F656C62616E65
xorq 0x80(%rsp), %rax
movabsq $0x6d6f646e61725f, %rcx # imm = 0x6D6F646E61725F
xorq 0x86(%rsp), %rcx
orq %rax, %rcx
je 0x2d8c
movdqa 0x80(%rsp), %xmm0
movdqu 0x85(%rsp), %xmm1
pcmpeqb 0x22ef(%rip), %xmm1     # 0x5040
pcmpeqb 0x22f7(%rip), %xmm0     # 0x5050
pand %xmm1, %xmm0
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x2db8
leaq 0x23dd(%rip), %rax      # 0x514c
jmp 0x2c98
leaq 0x238c(%rip), %rax      # 0x5107
movq %rax, (%r12)
movq %r13, %rdx
movl %r14d, %ecx
callq 0x2180
jmp 0x2dd8
leaq 0x2384(%rip), %rax      # 0x5117
movq %rax, (%r12)
movq %r13, %rdx
movl %r14d, %ecx
callq 0x2280
jmp 0x2dd8
leaq 0x2339(%rip), %rax      # 0x50e4
movq 0x20(%rsp), %rcx
movq %rax, (%rcx)
jmp 0x2c9c
leaq 0x236f(%rip), %rax      # 0x512e
movq %rax, (%r12)
movq %r13, %rdx
movl %r14d, %ecx
movq 0x18(%rsp), %r8
movl 0x4(%rsp), %r9d
callq 0x2358
addq $0x688, %rsp            # imm = 0x688
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq