// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
testl %esi, %esi
jle 0x14f91
movl %esi, %ebx
movq %rdi, %r14
movq %rdx, 0x10(%rsp)
leaq 0x20(%rsp), %r13
leaq 0x14b0d(%rip), %rbp     # 0x29730
movq (%r14), %r12
leaq 0xb0c6(%rip), %rdi      # 0x1fcf3
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x14cb3
leaq 0xb70d(%rip), %rdi      # 0x2034d
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x14cb3
leaq 0xb288(%rip), %rdi      # 0x1fedb
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x14ef9
leaq 0xb3f1(%rip), %rdi      # 0x2005b
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x14ef9
leaq 0xb0e9(%rip), %rdi      # 0x1fd6a
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x14ca4
leaq 0xb6f6(%rip), %rdi      # 0x2038a
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
jne 0x14fd5
movq 0x10(%rsp), %rdi
callq 0x1dd2c
jmp 0x14f7d
cmpl $0x2, %ebx
jbe 0x14fb0
leaq 0x8(%r14), %rbp
callq 0x1cd74
movq %rax, 0x8(%rsp)
movq (%rbp), %rsi
movq %r13, %rdi
movl $0x3a, %edx
callq 0x60a5
movq %rax, %r12
movq %r13, %rdi
xorl %esi, %esi
movl $0x3a, %edx
callq 0x60a5
movq %rax, %r15
movq %r13, %rdi
xorl %esi, %esi
movl $0x3a, %edx
callq 0x60a5
movq %r12, %rcx
movq %rax, %r13
testq %r12, %r12
setne %al
testq %r15, %r15
setne %sil
testq %r13, %r13
setne %dl
andb %sil, %dl
andb %al, %dl
movb %dl, 0x7(%rsp)
je 0x14ec0
movl $0x100, %esi            # imm = 0x100
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
leaq 0xa30c(%rip), %r12      # 0x1f047
movq %r12, %rdx
xorl %eax, %eax
movq %rcx, 0x18(%rsp)
callq 0x4110
cmpb $0x0, (%r15)
leaq 0x100(%rbp), %rdi
movq %r15, %rcx
leaq 0xb614(%rip), %rax      # 0x20373
cmoveq %rax, %rcx
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdx
xorl %eax, %eax
callq 0x4110
addq $0x200, %rbp            # imm = 0x200
cmpb $0x0, (%r13)
movq %r13, %rcx
leaq 0xb5eb(%rip), %rax      # 0x20373
cmoveq %rax, %rcx
movl $0x100, %esi            # imm = 0x100
movq %rbp, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x4110
movq 0x18(%rsp), %rdi
callq 0x4460
movq %r15, %rdi
callq 0x4460
movq %r13, %rdi
callq 0x4460
addq $0x10, %r14
addl $-0x2, %ebx
xorl %r15d, %r15d
movq %r14, %rbp
leaq 0xa370(%rip), %r12      # 0x1f13c
leaq 0xb5a2(%rip), %r13      # 0x20375
movq (%rbp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x4820
testl %eax, %eax
je 0x14e45
movq %r13, %rdi
movq %r14, %rsi
callq 0x4820
testl %eax, %eax
je 0x14e45
cmpq $0x100, %r15            # imm = 0x100
setb %al
jae 0x14e71
movq (%rbp), %r14
cmpb $0x0, (%r14)
je 0x14e71
xorl %r12d, %r12d
movq %r15, %r13
movb (%r14,%r12), %al
movq 0x8(%rsp), %rcx
movb %al, 0x300(%rcx,%r15)
cmpq $0xff, %r15
je 0x14e53
incq %r12
leaq 0x1(%r13), %r15
movq (%rbp), %r14
movq %r14, %rdi
callq 0x4470
cmpq %rax, %r12
jb 0x14e0e
jmp 0x14e59
movq 0x8(%rsp), %rax
movb $0x1, 0x400(%rax)
jmp 0x14e8b
movl $0x100, %r15d           # imm = 0x100
cmpq $0xff, %r13
setb %al
leaq 0xa2d2(%rip), %r12      # 0x1f13c
leaq 0xb504(%rip), %r13      # 0x20375
cmpl $0x1, %ebx
je 0x14e8b
testb %al, %al
je 0x14e8b
movq 0x8(%rsp), %rax
movb $0x20, 0x300(%rax,%r15)
incq %r15
leal -0x1(%rbx), %eax
addq $0x8, %rbp
cmpl $0x1, %ebx
movl %eax, %ebx
jg 0x14dd3
movl $0xff, %eax
cmpq %rax, %r15
cmovaeq %rax, %r15
movq 0x8(%rsp), %rdi
movb $0x0, 0x300(%rdi,%r15)
callq 0x1cdac
xorl %ebx, %ebx
jmp 0x14eda
decl %ebx
movq %rcx, %rdi
callq 0x4460
movq %r15, %rdi
callq 0x4460
movq %r13, %rdi
callq 0x4460
movq %rbp, %r14
cmpb $0x0, 0x7(%rsp)
leaq 0x20(%rsp), %r13
leaq 0x14842(%rip), %rbp     # 0x29730
jne 0x14f7d
jmp 0x14fc6
cmpl $0x1, %ebx
je 0x14fb0
addq $0x8, %r14
incl %ebx
leaq 0xb471(%rip), %r12      # 0x20380
movq (%r14), %rdi
movq %r13, %rsi
callq 0x173f4
testb %al, %al
je 0x14f2c
movzwl 0x20(%rsp), %edi
decl %edi
callq 0x1cf51
jmp 0x14f70
movq (%r14), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x14f5b
leaq 0xb440(%rip), %rdi      # 0x20385
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x14f61
movq %r15, %rdi
callq 0x1ce34
jmp 0x14f70
movq (%rbp), %rdi
jmp 0x14f6b
leaq 0x147d0(%rip), %rax     # 0x29738
movq (%rax), %rdi
callq 0x1cde1
addq $0x8, %r14
decl %ebx
cmpl $0x2, %ebx
jg 0x14f0f
xorl %ebx, %ebx
leal -0x1(%rbx), %eax
addq $0x8, %r14
cmpl $0x1, %ebx
movl %eax, %ebx
jg 0x14c23
jmp 0x14fc6
leaq 0xb39c(%rip), %rsi      # 0x20334
movq %rdx, %rdi
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11852
leaq 0xb39c(%rip), %rsi      # 0x20353
movq 0x10(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x11852
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb3b5(%rip), %rsi      # 0x20391
jmp 0x14fb7