// File: /workspace/github_c_makefile_star2_O3/baskerville[P]bspwm/src/messages.c
// Function: cmd_rule
void cmd_rule(char **args, int num, FILE *rsp)
{
	if (num < 1) {
		fail(rsp, "rule: Missing commands.\n");
		return;
	}

	while (num > 0) {
		if (streq("-a", *args) || streq("--add", *args)) {
			num--, args++;
			if (num < 2) {
				fail(rsp, "rule %s: Not enough arguments.\n", *(args - 1));
				return;
			}
			rule_t *rule = make_rule();

			struct tokenize_state state;
			char *class_name = tokenize_with_escape(&state, args[0], COL_TOK[0]);
			char *instance_name = tokenize_with_escape(&state, NULL, COL_TOK[0]);
			char *name = tokenize_with_escape(&state, NULL, COL_TOK[0]);
			if (!class_name || !instance_name || !name) {
				free(class_name);
				free(instance_name);
				free(name);
				return;
			}

			snprintf(rule->class_name, sizeof(rule->class_name), "%s", class_name);
			snprintf(rule->instance_name, sizeof(rule->instance_name), "%s",
					 instance_name[0] == '\0' ? MATCH_ANY : instance_name);
			snprintf(rule->name, sizeof(rule->name), "%s",
					 name[0] == '\0' ? MATCH_ANY : name);
			free(class_name);
			free(instance_name);
			free(name);

			num--, args++;
			size_t i = 0;
			while (num > 0) {
				if (streq("-o", *args) || streq("--one-shot", *args)) {
					rule->one_shot = true;
				} else {
					for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++) {
						rule->effect[i] = (*args)[j];
					}
					if (num > 1 && i < sizeof(rule->effect)) {
						rule->effect[i++] = ' ';
					}
				}
				num--, args++;
			}
			rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
			add_rule(rule);
		} else if (streq("-r", *args) || streq("--remove", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "rule %s: Not enough arguments.\n", *(args - 1));
				return;
			}
			uint16_t idx;
			while (num > 0) {
				if (parse_index(*args, &idx)) {
					remove_rule_by_index(idx - 1);
				} else if (streq("tail", *args)) {
					remove_rule(rule_tail);
				} else if (streq("head", *args)) {
					remove_rule(rule_head);
				} else {
					remove_rule_by_cause(*args);
				}
				num--, args++;
			}
		} else if (streq("-l", *args) || streq("--list", *args)) {
			list_rules(rsp);
		} else {
			fail(rsp, "rule: Unknown command: '%s'.\n", *args);
			return;
		}
		num--, args++;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r15
testl %esi, %esi
jle 0x14c2a
movl %esi, %r14d
movq %rdi, %rbx
incl %r14d
addq $0x8, %rbx
movq -0x8(%rbx), %r12
movzbl (%r12), %r13d
leal -0x2d(%r13), %ebp
negl %ebp
movl %ebp, %eax
cmpl $0x2d, %r13d
jne 0x14b7f
movzbl 0x1(%r12), %eax
subl $0x61, %eax
jne 0x14b7d
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x14c49
leaq 0xb779(%rip), %rdi      # 0x20307
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x14c49
movl %ebp, %eax
cmpb $0x2d, %r13b
jne 0x14bb9
movzbl 0x1(%r12), %eax
subl $0x72, %eax
jne 0x14bb7
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x14e3b
leaq 0xb450(%rip), %rdi      # 0x20018
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x14e3b
cmpb $0x2d, %r13b
jne 0x14bf1
movzbl 0x1(%r12), %ebp
subl $0x6c, %ebp
jne 0x14bef
movzbl 0x2(%r12), %ebp
negl %ebp
testl %ebp, %ebp
je 0x14c0c
leaq 0xb748(%rip), %rdi      # 0x20344
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
jne 0x14ecf
movq %r15, %rdi
callq 0x1d9bd
decl %r14d
addq $0x8, %rbx
cmpl $0x1, %r14d
jg 0x14b55
jmp 0x14f09
leaq 0xb6bd(%rip), %rsi      # 0x202ee
movq %r15, %rdi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x117fd
leal -0x1(%r14), %eax
cmpl $0x2, %eax
jbe 0x14e41
callq 0x1cac0
movq %rax, %r15
movq (%rbx), %rsi
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
movl $0x3a, %edx
callq 0x6047
movq %rax, %r12
movq %rbp, %rdi
xorl %esi, %esi
movl $0x3a, %edx
callq 0x6047
movq %rax, %r13
movq %rbp, %rdi
xorl %esi, %esi
movl $0x3a, %edx
callq 0x6047
movq %rax, %rbp
testq %r12, %r12
setne %al
testq %r13, %r13
setne %cl
andb %al, %cl
testq %rbp, %rbp
setne %al
testb %al, %cl
je 0x14ef1
leaq 0xa38a(%rip), %rdx      # 0x1f047
movq %r12, %rcx
movq %r12, 0x8(%rsp)
xorl %r12d, %r12d
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
xorl %eax, %eax
callq 0x4110
leaq 0x100(%r15), %rdi
cmpb $0x0, (%r13)
leaq 0xb643(%rip), %rax      # 0x2032d
movq %r13, %rcx
cmoveq %rax, %rcx
movl $0x100, %esi            # imm = 0x100
leaq 0xa34a(%rip), %rdx      # 0x1f047
xorl %eax, %eax
callq 0x4110
movq %r15, %rdi
addq $0x200, %rdi            # imm = 0x200
cmpb $0x0, (%rbp)
movq %rbp, %rcx
leaq 0xb611(%rip), %rax      # 0x2032d
cmoveq %rax, %rcx
movl $0x100, %esi            # imm = 0x100
leaq 0xa31b(%rip), %rdx      # 0x1f047
xorl %eax, %eax
callq 0x4110
movq 0x8(%rsp), %rdi
callq 0x4460
movq %r13, %rdi
callq 0x4460
movq %rbp, %rdi
callq 0x4460
addq $0x8, %rbx
addl $-0x3, %r14d
leaq 0xb5d3(%rip), %rbp      # 0x2032f
movq %r15, %r13
movq (%rbx), %rsi
movzbl (%rsi), %eax
subl $0x2d, %eax
jne 0x14d77
movzbl 0x1(%rsi), %eax
subl $0x6f, %eax
jne 0x14d77
movzbl 0x2(%rsi), %eax
negl %eax
testl %eax, %eax
je 0x14dda
movq %rbp, %rdi
callq 0x4820
testl %eax, %eax
je 0x14dda
cmpq $0xff, %r12
ja 0x14e04
movl $0x100, %eax            # imm = 0x100
subq %r12, %rax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
movq %r13, %rbp
movq (%rbx), %r13
movq %r13, %rdi
callq 0x4470
cmpq %rax, %r15
jae 0x14de4
movb (%r13,%r15), %al
movq %rbp, %r13
movb %al, 0x300(%rbp,%r12)
incq %r12
incq %r15
cmpq 0x8(%rsp), %r15
jne 0x14da2
movl $0x100, %r12d           # imm = 0x100
jmp 0x14dfd
movb $0x1, 0x400(%r13)
jmp 0x14e04
cmpl $0x1, %r14d
je 0x14f18
movq %rbp, %r13
movb $0x20, 0x300(%rbp,%r12)
incq %r12
leaq 0xb52b(%rip), %rbp      # 0x2032f
leal -0x1(%r14), %eax
addq $0x8, %rbx
cmpl $0x1, %r14d
movl %eax, %r14d
jg 0x14d5f
movl $0xff, %eax
cmpq %rax, %r12
cmovbq %r12, %rax
movb $0x0, 0x300(%r13,%rax)
movq %r13, %rdi
callq 0x1cacf
jmp 0x14f09
cmpl $0x2, %r14d
jne 0x14e4d
leaq 0xb4c5(%rip), %rsi      # 0x2030d
jmp 0x14ed6
leaq 0x10(%rsp), %r15
leaq 0xb4e1(%rip), %r12      # 0x2033a
leaq 0xb4df(%rip), %r13      # 0x2033f
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x172c5
testb %al, %al
je 0x14e7d
movzwl 0x10(%rsp), %edi
decl %edi
callq 0x1cc5f
jmp 0x14ec0
movq (%rbx), %rbp
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4820
testl %eax, %eax
je 0x14ea8
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4820
testl %eax, %eax
je 0x14eb1
movq %rbp, %rdi
callq 0x1cb57
jmp 0x14ec0
leaq 0x14881(%rip), %rax     # 0x29730
jmp 0x14eb8
leaq 0x14880(%rip), %rax     # 0x29738
movq (%rax), %rdi
callq 0x1cb04
decl %r14d
addq $0x8, %rbx
cmpl $0x2, %r14d
jg 0x14e60
jmp 0x14f09
leaq 0xb475(%rip), %rsi      # 0x2034b
movq %r15, %rdi
movq %r12, %rdx
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x117fd
movq %r12, %rdi
callq 0x4460
movq %r13, %rdi
callq 0x4460
movq %rbp, %rdi
callq 0x4460
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %r13
jmp 0x14e19