// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rdi, %rsi
pxor %xmm0, %xmm0
leaq 0x480(%rsp), %rbx
movdqa %xmm0, 0x1f0(%rbx)
movdqa %xmm0, 0x270(%rsp)
movdqa %xmm0, 0x470(%rsp)
movl $0x1ff, %edx            # imm = 0x1FF
movq %rbx, %rdi
callq 0x2080
leaq 0x40(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x25a3(%rip), %rsi      # 0x507c
movq %rbx, %rdi
callq 0x21c0
testq %rax, %rax
je 0x2c78
leaq 0x80(%rsp), %rdi
movl $0x1ff, %edx            # imm = 0x1FF
movq %rax, %rsi
callq 0x2080
leaq 0x2576(%rip), %rsi      # 0x507c
xorl %r14d, %r14d
leaq 0x40(%rsp), %rdx
xorl %edi, %edi
callq 0x21c0
testq %rax, %rax
je 0x2c81
leaq 0x280(%rsp), %rbx
movl $0x1ff, %edx            # imm = 0x1FF
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2080
movaps 0x5283(%rip), %xmm0     # 0x7dc0
movaps %xmm0, 0x70(%rsp)
movaps 0x5267(%rip), %xmm0     # 0x7db0
movaps %xmm0, 0x60(%rsp)
movaps 0x524b(%rip), %xmm0     # 0x7da0
movaps %xmm0, 0x50(%rsp)
movaps 0x522f(%rip), %xmm0     # 0x7d90
movaps %xmm0, 0x40(%rsp)
movq %rbx, 0x38(%rsp)
cmpb $0x0, (%rbx)
je 0x2c95
movq %r15, 0x20(%rsp)
movl $0x1, 0x14(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x249e(%rip), %xmm0     # 0x5030
movq %xmm0, 0x28(%rsp)
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
leaq 0x38(%rsp), %r12
leaq 0x40(%rsp), %rbx
leaq 0x8(%rsp), %rbp
leaq 0x24aa(%rip), %r15      # 0x5060
movq $0x0, 0x30(%rsp)
xorl %r13d, %r13d
xorl %r14d, %r14d
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2090
cmpl $0x6, %eax
ja 0x2d90
movl %eax, %eax
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movq 0x8(%rsp), %r14
jmp 0x2c4e
movq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x2c4e
movq 0x8(%rsp), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x22e0
movq %rax, %r13
jmp 0x2c4e
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x20b0
movq %xmm0, 0x28(%rsp)
jmp 0x2c4e
movq 0x8(%rsp), %rdi
callq 0x2300
movl %eax, 0x14(%rsp)
jmp 0x2c4e
movq 0x8(%rsp), %rdi
callq 0x2300
movl %eax, 0x4(%rsp)
jmp 0x2c4e
movl $0x1, %eax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x2bc5
xorps %xmm0, %xmm0
cvtsd2ss 0x28(%rsp), %xmm0
movq 0x20(%rsp), %r15
movl 0x14(%rsp), %esi
movq %r14, %rdi
movq 0x30(%rsp), %r14
jmp 0x2cb8
leaq 0x2400(%rip), %rax      # 0x507f
jmp 0x2c88
leaq 0x240a(%rip), %rax      # 0x5092
movq %rax, (%r15)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x2dc3
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movss 0x2383(%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 0x2ce0
leaq 0x2423(%rip), %rax      # 0x50f6
movq %rax, (%r15)
callq 0x2050
jmp 0x2dc3
movl $0x62616e65, %eax       # imm = 0x62616E65
xorl 0x80(%rsp), %eax
movl $0x656c62, %ecx         # imm = 0x656C62
xorl 0x83(%rsp), %ecx
orl %eax, %ecx
je 0x2d62
movabsq $0x725f656c62616e65, %rax # imm = 0x725F656C62616E65
xorq 0x80(%rsp), %rax
movabsq $0x6d6f646e61725f, %rcx # imm = 0x6D6F646E61725F
xorq 0x86(%rsp), %rcx
orq %rax, %rcx
je 0x2d79
movdqa 0x80(%rsp), %xmm0
movdqu 0x85(%rsp), %xmm1
pcmpeqb 0x2301(%rip), %xmm1     # 0x5040
pcmpeqb 0x2309(%rip), %xmm0     # 0x5050
pand %xmm1, %xmm0
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x2da4
leaq 0x23ef(%rip), %rax      # 0x514c
jmp 0x2c88
leaq 0x239e(%rip), %rax      # 0x5107
movq %rax, (%r15)
movq %r13, %rdx
movl %r14d, %ecx
callq 0x2180
jmp 0x2dc3
leaq 0x2397(%rip), %rax      # 0x5117
movq %rax, (%r15)
movq %r13, %rdx
movl %r14d, %ecx
callq 0x2290
jmp 0x2dc3
leaq 0x234d(%rip), %rax      # 0x50e4
movq 0x20(%rsp), %rcx
movq %rax, (%rcx)
jmp 0x2c8b
leaq 0x2383(%rip), %rax      # 0x512e
movq %rax, (%r15)
movq %r13, %rdx
movl %r14d, %ecx
movq 0x18(%rsp), %r8
movl 0x4(%rsp), %r9d
callq 0x2368
addq $0x688, %rsp            # imm = 0x688
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq