// File: /workspace/github_c_makefile_star2_O3/baskerville[P]bspwm/src/messages.c
// Function: cmd_subscribe
void cmd_subscribe(char **args, int num, FILE *rsp)
{
	int field = 0;
	int count = -1;
	FILE *stream = rsp;
	char *fifo_path = NULL;
	subscriber_mask_t mask;

	while (num > 0) {
		if (streq("-c", *args) || streq("--count", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "subscribe %s: Not enough arguments.\n", *(args - 1));
				goto failed;
			}
			if (sscanf(*args, "%i", &count) != 1 || count < 1) {
				fail(rsp, "subscribe %s: Invalid argument: '%s'.\n", *(args - 1), *args);
				goto failed;
			}
		} else if (streq("-f", *args) || streq("--fifo", *args)) {
			fifo_path = mktempfifo(FIFO_TEMPLATE);
			if (fifo_path == NULL) {
				fail(rsp, "subscribe %s: Can't create FIFO.\n", *(args - 1));
				goto failed;
			}
		} else if (parse_subscriber_mask(*args, &mask)) {
			field |= mask;
		} else {
			fail(rsp, "subscribe: Invalid argument: '%s'.\n", *args);
			goto failed;
		}
		num--, args++;
	}

	if (field == 0) {
		field = SBSC_MASK_REPORT;
	}

	if (fifo_path) {
		fprintf(rsp, "%s\n", fifo_path);
		fflush(rsp);
		fclose(rsp);

		stream = fopen(fifo_path, "w");

		if (stream == NULL) {
			perror("subscribe: fopen");
			goto free_fifo_path;
		}
	}

	subscriber_list_t *sb = make_subscriber(stream, fifo_path, field, count);
	add_subscriber(sb);
	return;

failed:
	fflush(rsp);
	fclose(rsp);

free_fifo_path:
	if (fifo_path) {
		unlink(fifo_path);
		free(fifo_path);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, (%rsp)
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
testl %esi, %esi
jle 0x1468b
movl %esi, %r12d
movq %rdi, %r15
xorl %ebx, %ebx
movl $0x0, 0xc(%rsp)
movq (%r15), %r14
movzbl (%r14), %ebp
leal -0x2d(%rbp), %r13d
negl %r13d
movl %r13d, %eax
cmpl $0x2d, %ebp
jne 0x14560
movzbl 0x1(%r14), %eax
subl $0x63, %eax
jne 0x1455e
movzbl 0x2(%r14), %eax
negl %eax
testl %eax, %eax
je 0x145cb
leaq 0xbee2(%rip), %rdi      # 0x2044d
movq %r14, %rsi
callq 0x4820
testl %eax, %eax
je 0x145cb
cmpb $0x2d, %bpl
jne 0x14590
movzbl 0x1(%r14), %r13d
subl $0x66, %r13d
jne 0x1458d
movzbl 0x2(%r14), %r13d
negl %r13d
testl %r13d, %r13d
je 0x14609
leaq 0xbf05(%rip), %rdi      # 0x204a1
movq %r14, %rsi
callq 0x4820
testl %eax, %eax
je 0x14609
movq %r14, %rdi
leaq 0x14(%rsp), %rsi
callq 0x1733d
testb %al, %al
je 0x146ee
movl 0xc(%rsp), %eax
orl 0x14(%rsp), %eax
movl %eax, 0xc(%rsp)
jmp 0x14621
cmpl $0x1, %r12d
je 0x146ae
movq 0x8(%r15), %rdi
leaq 0xcb3f(%rip), %rsi      # 0x2111f
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x41c0
cmpl $0x1, %eax
jne 0x146c1
cmpl $0x0, 0x10(%rsp)
jle 0x146c1
addq $0x8, %r15
decl %r12d
jmp 0x14621
leaq 0xbe98(%rip), %rdi      # 0x204a8
callq 0x5e79
testq %rax, %rax
je 0x146df
movq %rax, %rbx
leal -0x1(%r12), %eax
addq $0x8, %r15
cmpl $0x1, %r12d
movl %eax, %r12d
jg 0x14539
movl 0xc(%rsp), %ebp
cmpl $0x1, %ebp
adcl $0x0, %ebp
testq %rbx, %rbx
je 0x14690
leaq 0xcf56(%rip), %rsi      # 0x215a3
movq (%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4a30
movq %r14, %rdi
callq 0x4b00
movq %r14, %rdi
callq 0x48c0
leaq 0xc620(%rip), %rsi      # 0x20c95
movq %rbx, %rdi
callq 0x42a0
testq %rax, %rax
je 0x1473a
movq %rax, %rdi
jmp 0x14696
movl $0x1, %ebp
xorl %ebx, %ebx
movq (%rsp), %rdi
movl 0x10(%rsp), %ecx
movq %rbx, %rsi
movl %ebp, %edx
callq 0x1e33c
movq %rax, %rdi
callq 0x1e416
jmp 0x1472b
leaq 0xbda0(%rip), %rsi      # 0x20455
movq (%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
jmp 0x146ff
movq (%r15), %rdx
movq 0x8(%r15), %rcx
leaq 0xbdab(%rip), %rsi      # 0x2047a
movq (%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x117fd
jmp 0x14706
movq -0x8(%r15), %rdx
leaq 0xbdd0(%rip), %rsi      # 0x204ba
xorl %ebx, %ebx
jmp 0x146f8
movq (%r15), %rdx
leaq 0xbde4(%rip), %rsi      # 0x204dc
movq (%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x117fd
movq %r15, %rdi
callq 0x4b00
movq %r15, %rdi
callq 0x48c0
testq %rbx, %rbx
je 0x1472b
movq %rbx, %rdi
callq 0x42e0
movq %rbx, %rdi
callq 0x4460
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbdbf(%rip), %rdi      # 0x20500
callq 0x4a10
jmp 0x1471b