// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
testl %esi, %esi
jle 0x14706
movl %esi, %r13d
movq %rdi, %r12
leaq 0xb915(%rip), %rbp      # 0x1ff40
xorl %ebx, %ebx
xorl %r15d, %r15d
movq (%r12), %r14
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4820
testl %eax, %eax
je 0x14698
leaq 0xbe4f(%rip), %rdi      # 0x20499
movq %r14, %rsi
callq 0x4820
testl %eax, %eax
je 0x14698
leaq 0xb683(%rip), %rdi      # 0x1fce0
movq %r14, %rsi
callq 0x4820
testl %eax, %eax
je 0x146d7
leaq 0xbe7d(%rip), %rdi      # 0x204ed
movq %r14, %rsi
callq 0x4820
testl %eax, %eax
je 0x146d7
movq %r14, %rdi
leaq 0x14(%rsp), %rsi
callq 0x1746c
testb %al, %al
je 0x147cf
orl 0x14(%rsp), %r15d
jmp 0x146ef
cmpl $0x1, %r13d
je 0x1478a
movq 0x8(%r12), %rdi
leaq 0xcabd(%rip), %rsi      # 0x2116b
leaq 0x4(%rsp), %rdx
xorl %eax, %eax
callq 0x41c0
cmpl $0x1, %eax
jne 0x1479e
cmpl $0x0, 0x4(%rsp)
jle 0x1479e
addq $0x8, %r12
decl %r13d
jmp 0x146ef
leaq 0xbe16(%rip), %rdi      # 0x204f4
callq 0x5ebb
testq %rax, %rax
je 0x147bf
movq %rax, %rbx
leal -0x1(%r13), %eax
addq $0x8, %r12
cmpl $0x1, %r13d
movl %eax, %r13d
jg 0x14630
jmp 0x1470b
xorl %r15d, %r15d
xorl %ebx, %ebx
cmpl $0x1, %r15d
adcl $0x0, %r15d
testq %rbx, %rbx
je 0x14769
leaq 0xced0(%rip), %rsi      # 0x215ef
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4a30
movq %r14, %rdi
callq 0x4b00
movq %r14, %rdi
callq 0x48c0
leaq 0xc599(%rip), %rsi      # 0x20ce1
movq %rbx, %rdi
callq 0x42a0
movq %rax, %rdi
testq %rax, %rax
jne 0x1476e
leaq 0xbded(%rip), %rdi      # 0x2054c
callq 0x4a10
jmp 0x147f9
movq 0x8(%rsp), %rdi
movl 0x4(%rsp), %ecx
movq %rbx, %rsi
movl %r15d, %edx
callq 0x1e788
movq %rax, %rdi
callq 0x1e869
jmp 0x1480e
leaq 0xbd10(%rip), %rsi      # 0x204a1
movq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
jmp 0x147e2
movq (%r12), %rdx
movq 0x8(%r12), %rcx
leaq 0xbd18(%rip), %rsi      # 0x204c6
movq 0x8(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x11852
jmp 0x147e9
movq -0x8(%r12), %rdx
leaq 0xbd3b(%rip), %rsi      # 0x20506
xorl %ebx, %ebx
jmp 0x147da
movq (%r12), %rdx
leaq 0xbd4e(%rip), %rsi      # 0x20528
movq 0x8(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x11852
movq %r15, %rdi
callq 0x4b00
movq %r15, %rdi
callq 0x48c0
testq %rbx, %rbx
je 0x1480e
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