// File: /workspace/github_c_makefile_star2_O2/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 0x13d66
movl %esi, %r13d
movq %rdi, %r14
movq %r15, 0x8(%rsp)
testl %r13d, %r13d
jle 0x13db5
movq (%r14), %rbp
movzbl (%rbp), %r15d
leal -0x2d(%r15), %ebx
negl %ebx
movl %ebx, %eax
cmpl $0x2d, %r15d
jne 0x13a93
movzbl 0x1(%rbp), %eax
subl $0x61, %eax
jne 0x13a91
movzbl 0x2(%rbp), %eax
negl %eax
testl %eax, %eax
je 0x13b26
leaq 0xb865(%rip), %rdi      # 0x1f307
movq %rbp, %rsi
callq 0x4820
testl %eax, %eax
je 0x13b26
movl %ebx, %eax
cmpb $0x2d, %r15b
jne 0x13ac5
movzbl 0x1(%rbp), %eax
subl $0x72, %eax
jne 0x13ac3
movzbl 0x2(%rbp), %eax
negl %eax
testl %eax, %eax
je 0x13cd9
leaq 0xb544(%rip), %rdi      # 0x1f018
movq %rbp, %rsi
callq 0x4820
testl %eax, %eax
je 0x13cd9
cmpb $0x2d, %r15b
jne 0x13af9
movzbl 0x1(%rbp), %ebx
subl $0x6c, %ebx
jne 0x13af7
movzbl 0x2(%rbp), %ebx
negl %ebx
testl %ebx, %ebx
je 0x13b14
leaq 0xb840(%rip), %rdi      # 0x1f344
movq %rbp, %rsi
callq 0x4820
testl %eax, %eax
jne 0x13dc4
movq 0x8(%rsp), %rdi
callq 0x1c447
decl %r13d
jmp 0x13cd0
cmpl $0x2, %r13d
jbe 0x13d85
callq 0x1b658
movq %rax, %rbp
movq 0x8(%r14), %rsi
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
pushq $0x3a
popq %r15
movl %r15d, %edx
callq 0x5f96
movq %rax, %r12
movq %rbx, %rdi
xorl %esi, %esi
movl %r15d, %edx
callq 0x5f96
movq %rax, %r15
movq %rbx, %rdi
xorl %esi, %esi
pushq $0x3a
popq %rdx
callq 0x5f96
movq %rax, %rbx
testq %r12, %r12
je 0x13d9d
testq %r15, %r15
je 0x13d9d
testq %rbx, %rbx
je 0x13d9d
movl $0x100, %esi            # imm = 0x100
movq %rbp, %rdi
leaq 0xa4aa(%rip), %rdx      # 0x1e047
movq %r12, %rcx
xorl %eax, %eax
callq 0x4110
cmpb $0x0, (%r15)
leaq 0x100(%rbp), %rdi
movq %r15, %rcx
leaq 0xb771(%rip), %rax      # 0x1f32d
cmoveq %rax, %rcx
movl $0x100, %esi            # imm = 0x100
leaq 0xa47b(%rip), %rdx      # 0x1e047
xorl %eax, %eax
callq 0x4110
movq %rbp, %rdi
addq $0x200, %rdi            # imm = 0x200
cmpb $0x0, (%rbx)
movq %rbx, %rcx
leaq 0xb743(%rip), %rax      # 0x1f32d
cmoveq %rax, %rcx
movl $0x100, %esi            # imm = 0x100
leaq 0xa44d(%rip), %rdx      # 0x1e047
xorl %eax, %eax
callq 0x4110
movq %r12, %rdi
callq 0x4460
movq %r15, %rdi
callq 0x4460
movq %rbx, %rdi
callq 0x4460
addl $-0x2, %r13d
addq $0x10, %r14
xorl %r15d, %r15d
testl %r13d, %r13d
jle 0x13caf
movq (%r14), %rsi
movzbl (%rsi), %eax
subl $0x2d, %eax
jne 0x13c45
movzbl 0x1(%rsi), %eax
subl $0x6f, %eax
jne 0x13c45
movzbl 0x2(%rsi), %eax
negl %eax
testl %eax, %eax
je 0x13c8b
leaq 0xb6dd(%rip), %rdi      # 0x1f32f
callq 0x4820
testl %eax, %eax
je 0x13c8b
xorl %r12d, %r12d
cmpq $0xff, %r15
ja 0x13c92
movq (%r14), %rbx
movq %rbx, %rdi
callq 0x4470
cmpq %rax, %r12
jae 0x13c9b
movb (%rbx,%r12), %al
movb %al, 0x300(%rbp,%r15)
incq %r15
incq %r12
jmp 0x13c5e
movb $0x1, 0x400(%rbp)
decl %r13d
addq $0x8, %r14
jmp 0x13c24
cmpl $0x1, %r13d
je 0x13c92
movb $0x20, 0x300(%rbp,%r15)
incq %r15
jmp 0x13c92
movl $0xff, %eax
cmpq %rax, %r15
cmovaeq %rax, %r15
movb $0x0, 0x300(%rbp,%r15)
movq %rbp, %rdi
callq 0x1b665
pushq $-0x1
popq %r13
addq $0x8, %r14
jmp 0x13a65
cmpl $0x1, %r13d
je 0x13d85
addq $0x8, %r14
leaq 0x10(%rsp), %r12
leaq 0xb647(%rip), %rbp      # 0x1f33a
cmpl $0x2, %r13d
jl 0x13ccc
movq (%r14), %rdi
movq %r12, %rsi
callq 0x160f1
testb %al, %al
je 0x13d16
movzwl 0x10(%rsp), %edi
decl %edi
callq 0x1b7ef
jmp 0x13d5d
movq (%r14), %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x4820
testl %eax, %eax
je 0x13d45
leaq 0xb610(%rip), %rdi      # 0x1f33f
movq %rbx, %rsi
callq 0x4820
testl %eax, %eax
je 0x13d4e
movq %rbx, %rdi
callq 0x1b6ed
jmp 0x13d5d
leaq 0x149e4(%rip), %rax     # 0x28730
jmp 0x13d55
leaq 0x149e3(%rip), %rax     # 0x28738
movq (%rax), %rdi
callq 0x1b69a
addq $0x8, %r14
decl %r13d
jmp 0x13cf3
leaq 0xb581(%rip), %rsi      # 0x1f2ee
movq %r15, %rdi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10897
leaq 0xb581(%rip), %rsi      # 0x1f30d
movq 0x8(%rsp), %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x10897
jmp 0x13db5
movq %r12, %rdi
callq 0x4460
movq %r15, %rdi
callq 0x4460
movq %rbx, %rdi
callq 0x4460
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb580(%rip), %rsi      # 0x1f34b
jmp 0x13d8c