// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
cmpl $0x0, -0xc(%rbp)
jle 0x1d07d
movq -0x8(%rbp), %rax
movq (%rax), %rsi
leaq 0x111c7(%rip), %rdi     # 0x2e0d0
callq 0x4800
cmpl $0x0, %eax
je 0x1cf2f
movq -0x8(%rbp), %rax
movq (%rax), %rsi
leaq 0x11708(%rip), %rdi     # 0x2e629
callq 0x4800
cmpl $0x0, %eax
jne 0x1cfb8
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x8(%rbp)
cmpl $0x1, -0xc(%rbp)
jge 0x1cf69
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq -0x8(%rax), %rdx
leaq 0x116d4(%rip), %rsi     # 0x2e631
movb $0x0, %al
callq 0x18d60
jmp 0x1d106
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq 0x12362(%rip), %rsi     # 0x2f2d9
leaq -0x20(%rbp), %rdx
movb $0x0, %al
callq 0x41c0
cmpl $0x1, %eax
jne 0x1cf8d
cmpl $0x1, -0x20(%rbp)
jge 0x1cfb3
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq -0x8(%rax), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rcx
leaq 0x116af(%rip), %rsi     # 0x2e656
movb $0x0, %al
callq 0x18d60
jmp 0x1d106
jmp 0x1d063
movq -0x8(%rbp), %rax
movq (%rax), %rsi
leaq 0x10eaa(%rip), %rdi     # 0x2de70
callq 0x4800
cmpl $0x0, %eax
je 0x1cfe8
movq -0x8(%rbp), %rax
movq (%rax), %rsi
leaq 0x1169f(%rip), %rdi     # 0x2e67d
callq 0x4800
cmpl $0x0, %eax
jne 0x1d020
leaq 0x11695(%rip), %rdi     # 0x2e684
callq 0x67d0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x1d01e
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq -0x8(%rax), %rdx
leaq 0x11684(%rip), %rsi     # 0x2e696
movb $0x0, %al
callq 0x18d60
jmp 0x1d106
jmp 0x1d061
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0x34(%rbp), %rsi
callq 0x218b0
testb $0x1, %al
jne 0x1d036
jmp 0x1d041
movl -0x34(%rbp), %eax
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x1d05f
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rdx
leaq 0x11665(%rip), %rsi     # 0x2e6b8
movb $0x0, %al
callq 0x18d60
jmp 0x1d106
jmp 0x1d061
jmp 0x1d063
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x8(%rbp)
jmp 0x1cef1
cmpl $0x0, -0x1c(%rbp)
jne 0x1d08a
movl $0x1, -0x1c(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x1d0e4
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x126bd(%rip), %rsi     # 0x2f75d
movb $0x0, %al
callq 0x4a00
movq -0x18(%rbp), %rdi
callq 0x4ad0
movq -0x18(%rbp), %rdi
callq 0x48a0
movq -0x30(%rbp), %rdi
leaq 0x11daf(%rip), %rsi     # 0x2ee73
callq 0x42b0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x1d0e2
leaq 0x11601(%rip), %rdi     # 0x2e6dc
callq 0x49e0
jmp 0x1d118
jmp 0x1d0e4
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
callq 0x2bb40
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2bcd0
jmp 0x1d131
movq -0x18(%rbp), %rdi
callq 0x4ad0
movq -0x18(%rbp), %rdi
callq 0x48a0
cmpq $0x0, -0x30(%rbp)
je 0x1d131
movq -0x30(%rbp), %rdi
callq 0x42f0
movq -0x30(%rbp), %rdi
callq 0x4450
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)