// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x6c8, %rsp            # imm = 0x6C8
movq %rdi, 0x6b8(%rsp)
movq %rsi, 0x6b0(%rsp)
leaq 0x4b0(%rsp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x2180
leaq 0x2b0(%rsp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x2180
leaq 0xb0(%rsp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x2180
leaq 0x4b0(%rsp), %rdi
movq 0x6b8(%rsp), %rsi
movl $0x1ff, %edx            # imm = 0x1FF
callq 0x2080
movq $0x0, 0xa8(%rsp)
movq $0x0, 0xa0(%rsp)
leaq 0x4b0(%rsp), %rdi
leaq 0x30a8(%rip), %rsi      # 0x604c
leaq 0xa0(%rsp), %rdx
callq 0x21d0
movq %rax, 0xa8(%rsp)
cmpq $0x0, 0xa8(%rsp)
jne 0x2fe6
movq 0x6b0(%rsp), %rax
leaq 0x307c(%rip), %rcx      # 0x604f
movq %rcx, (%rax)
movl $0xffffffff, 0x6c4(%rsp) # imm = 0xFFFFFFFF
jmp 0x334f
leaq 0x2b0(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movl $0x1ff, %edx            # imm = 0x1FF
callq 0x2080
xorl %eax, %eax
movl %eax, %edi
leaq 0x3041(%rip), %rsi      # 0x604c
leaq 0xa0(%rsp), %rdx
callq 0x21d0
movq %rax, 0xa8(%rsp)
cmpq $0x0, 0xa8(%rsp)
jne 0x304d
movq 0x6b0(%rsp), %rax
leaq 0x3028(%rip), %rcx      # 0x6062
movq %rcx, (%rax)
movl $0xffffffff, 0x6c4(%rsp) # imm = 0xFFFFFFFF
jmp 0x334f
leaq 0xb0(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movl $0x1ff, %edx            # imm = 0x1FF
callq 0x2080
movq $0x0, 0x98(%rsp)
movl $0x1, 0x94(%rsp)
movq $0x0, 0x88(%rsp)
movl $0x0, 0x84(%rsp)
movsd 0x2f8b(%rip), %xmm0     # 0x6028
movsd %xmm0, 0x78(%rsp)
movq $0x0, 0x70(%rsp)
movl $0xffffffff, 0x6c(%rsp) # imm = 0xFFFFFFFF
leaq 0x20(%rsp), %rdi
leaq 0x4cd0(%rip), %rsi      # 0x7d90
movl $0x40, %edx
callq 0x2230
leaq 0xb0(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x31d2
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x2090
movl %eax, %ecx
movq %rcx, 0x8(%rsp)
subl $0x6, %eax
ja 0x31ab
movq 0x8(%rsp), %rax
leaq 0x2f18(%rip), %rcx      # 0x6030
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x18(%rsp), %rax
movq %rax, 0x98(%rsp)
jmp 0x31cd
movq 0x18(%rsp), %rdi
callq 0x2310
movl %eax, 0x94(%rsp)
jmp 0x31cd
movq 0x18(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x22f0
movq %rax, 0x88(%rsp)
jmp 0x31cd
movq 0x18(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x20b0
movsd %xmm0, 0x78(%rsp)
jmp 0x31cd
movq 0x18(%rsp), %rax
movq %rax, 0x70(%rsp)
jmp 0x31cd
movq 0x18(%rsp), %rdi
callq 0x2310
movl %eax, 0x6c(%rsp)
jmp 0x31cd
movl 0x84(%rsp), %eax
orl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x31cd
movq 0x6b0(%rsp), %rax
leaq 0x2efa(%rip), %rcx      # 0x60b4
movq %rcx, (%rax)
movl $0xffffffff, 0x6c4(%rsp) # imm = 0xFFFFFFFF
jmp 0x334f
jmp 0x30d7
leaq 0x2b0(%rsp), %rdi
leaq 0x2eee(%rip), %rsi      # 0x60cf
callq 0x2200
cmpl $0x0, %eax
jne 0x3216
movq 0x6b0(%rsp), %rax
leaq 0x2ecc(%rip), %rcx      # 0x60c6
movq %rcx, (%rax)
movq 0x98(%rsp), %rdi
callq 0x2050
movl %eax, 0x6c4(%rsp)
jmp 0x334f
leaq 0x2b0(%rsp), %rdi
leaq 0x2ebb(%rip), %rsi      # 0x60e0
callq 0x2200
cmpl $0x0, %eax
jne 0x3270
movq 0x6b0(%rsp), %rax
leaq 0x2e99(%rip), %rcx      # 0x60d7
movq %rcx, (%rax)
movq 0x98(%rsp), %rdi
movl 0x94(%rsp), %esi
movq 0x88(%rsp), %rdx
movl 0x84(%rsp), %ecx
callq 0x2190
movl %eax, 0x6c4(%rsp)
jmp 0x334f
leaq 0x2b0(%rsp), %rdi
leaq 0x2e71(%rip), %rsi      # 0x60f0
callq 0x2200
cmpl $0x0, %eax
jne 0x32d1
movq 0x6b0(%rsp), %rax
leaq 0x2e4f(%rip), %rcx      # 0x60e7
movq %rcx, (%rax)
movq 0x98(%rsp), %rdi
movl 0x94(%rsp), %esi
movq 0x88(%rsp), %rdx
movl 0x84(%rsp), %ecx
movsd 0x78(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x22a0
movl %eax, 0x6c4(%rsp)
jmp 0x334f
leaq 0x2b0(%rsp), %rdi
leaq 0x2e27(%rip), %rsi      # 0x6107
callq 0x2200
cmpl $0x0, %eax
jne 0x3332
movq 0x6b0(%rsp), %rax
leaq 0x2e05(%rip), %rcx      # 0x60fe
movq %rcx, (%rax)
movq 0x98(%rsp), %rdi
movl 0x94(%rsp), %esi
movq 0x88(%rsp), %rdx
movl 0x84(%rsp), %ecx
movq 0x70(%rsp), %r8
movl 0x6c(%rsp), %r9d
callq 0x2368
movl %eax, 0x6c4(%rsp)
jmp 0x334f
movq 0x6b0(%rsp), %rax
leaq 0x2ddb(%rip), %rcx      # 0x611c
movq %rcx, (%rax)
movl $0xffffffff, 0x6c4(%rsp) # imm = 0xFFFFFFFF
movl 0x6c4(%rsp), %eax
addq $0x6c8, %rsp            # imm = 0x6C8
retq
nop