// File: /workspace/github_c_makefile_star2_O2/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 %esi, %r12d
leaq 0x4(%rsp), %rax
orl $-0x1, (%rax)
movq %rdi, %r15
movl $0x0, (%rsp)
xorl %ebx, %ebx
testl %r12d, %r12d
jle 0x1355e
movq (%r15), %r14
movzbl (%r14), %ebp
leal -0x2d(%rbp), %r13d
negl %r13d
movl %r13d, %eax
cmpl $0x2d, %ebp
jne 0x13493
movzbl 0x1(%r14), %eax
subl $0x63, %eax
jne 0x13491
movzbl 0x2(%r14), %eax
negl %eax
testl %eax, %eax
je 0x134fc
leaq 0xbfaf(%rip), %rdi      # 0x1f44d
movq %r14, %rsi
callq 0x4820
testl %eax, %eax
je 0x134fc
cmpb $0x2d, %bpl
jne 0x134c3
movzbl 0x1(%r14), %r13d
subl $0x66, %r13d
jne 0x134c0
movzbl 0x2(%r14), %r13d
negl %r13d
testl %r13d, %r13d
je 0x1353a
leaq 0xbfd2(%rip), %rdi      # 0x1f4a1
movq %r14, %rsi
callq 0x4820
testl %eax, %eax
je 0x1353a
movq %r14, %rdi
leaq 0x14(%rsp), %rsi
callq 0x16169
testb %al, %al
je 0x13620
movl (%rsp), %eax
orl 0x14(%rsp), %eax
movl %eax, (%rsp)
jmp 0x13552
cmpl $0x1, %r12d
je 0x135c1
movq 0x8(%r15), %rdi
leaq 0xcc0e(%rip), %rsi      # 0x2011f
leaq 0x4(%rsp), %rdx
xorl %eax, %eax
callq 0x41c0
cmpl $0x1, %eax
jne 0x135d5
cmpl $0x0, 0x4(%rsp)
jle 0x135d5
addq $0x8, %r15
decl %r12d
jmp 0x13552
leaq 0xbf67(%rip), %rdi      # 0x1f4a8
callq 0x5dca
testq %rax, %rax
je 0x13611
movq %rax, %rbx
decl %r12d
addq $0x8, %r15
jmp 0x13463
movl (%rsp), %ebp
cmpl $0x1, %ebp
adcl $0x0, %ebp
testq %rbx, %rbx
je 0x135f4
leaq 0xd02c(%rip), %rsi      # 0x205a3
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4a30
movq %r14, %rdi
callq 0x4af0
movq %r14, %rdi
callq 0x48c0
leaq 0xc6f5(%rip), %rsi      # 0x1fc95
movq %rbx, %rdi
callq 0x42a0
movq %rax, %rdi
testq %rax, %rax
jne 0x135f9
leaq 0xbf49(%rip), %rdi      # 0x1f500
callq 0x4a10
jmp 0x1364e
leaq 0xbe8d(%rip), %rsi      # 0x1f455
movq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
jmp 0x13632
movq (%r15), %rdx
movq 0x8(%r15), %rcx
leaq 0xbe97(%rip), %rsi      # 0x1f47a
movq 0x8(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x10897
jmp 0x13639
movq 0x8(%rsp), %rdi
movl 0x4(%rsp), %ecx
movq %rbx, %rsi
movl %ebp, %edx
callq 0x1cd20
movq %rax, %rdi
callq 0x1cdf2
jmp 0x1365e
movq -0x8(%r15), %rdx
leaq 0xbe9e(%rip), %rsi      # 0x1f4ba
xorl %ebx, %ebx
jmp 0x1362a
movq (%r15), %rdx
leaq 0xbeb2(%rip), %rsi      # 0x1f4dc
movq 0x8(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x10897
movq %r15, %rdi
callq 0x4af0
movq %r15, %rdi
callq 0x48c0
testq %rbx, %rbx
je 0x1365e
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