// File: /workspace/github_c_makefile_star2_O0/skeeto[P]enchive/src/enchive.c
// Function: agent_run
static int
agent_run(const uint8_t *key, const uint8_t *iv)
{
    struct pollfd pfd = {-1, POLLIN, 0};
    struct sockaddr_un addr;
    pid_t pid;

    pfd.fd = socket(AF_UNIX, SOCK_STREAM, 0);
    if (pfd.fd == -1) {
        warning("could not create agent socket");
        return 0;
    }

    if (!agent_addr(&addr, iv))
        return 0;

    pid = fork();
    if (pid == -1) {
        warning("could not fork() agent -- %s", strerror(errno));
        return 0;
    } else if (pid != 0) {
        return 1;
    }
    close(0);
    close(1);

    umask(~(S_IRUSR | S_IWUSR));

    if (unlink(addr.sun_path))
        if (errno != ENOENT)
            fatal("failed to remove existing socket -- %s", strerror(errno));

    if (bind(pfd.fd, (struct sockaddr *)&addr, sizeof(addr))) {
        if (errno != EADDRINUSE)
            warning("could not bind agent socket %s -- %s",
                    addr.sun_path, strerror(errno));
        exit(EXIT_FAILURE);
    }

    if (listen(pfd.fd, SOMAXCONN)) {
        if (errno != EADDRINUSE)
            fatal("could not listen on agent socket -- %s", strerror(errno));
        exit(EXIT_FAILURE);
    }

    close(2);
    for (;;) {
        int cfd;
        int r = poll(&pfd, 1, global_agent_timeout * 1000);
        if (r < 0) {
            unlink(addr.sun_path);
            fatal("agent poll failed -- %s", strerror(errno));
        }
        if (r == 0) {
            unlink(addr.sun_path);
            fputs("info: agent timeout\n", stderr);
            close(pfd.fd);
            break;
        }
        cfd = accept(pfd.fd, 0, 0);
        if (cfd != -1) {
            if (write(cfd, key, 32) != 32)
                warning("agent write failed");
            close(cfd);
        }
    }
    exit(EXIT_SUCCESS);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq 0x6a9e(%rip), %rax      # 0xc058
movq %rax, -0x20(%rbp)
movl $0x1, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x2370
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x55ef
leaq 0x63ca(%rip), %rdi      # 0xb9a6
movb $0x0, %al
callq 0x5990
movl $0x0, -0x4(%rbp)
jmp 0x5857
movq -0x18(%rbp), %rsi
leaq -0x8e(%rbp), %rdi
callq 0x5870
cmpl $0x0, %eax
jne 0x5610
movl $0x0, -0x4(%rbp)
jmp 0x5857
callq 0x2360
movl %eax, -0x94(%rbp)
cmpl $-0x1, -0x94(%rbp)
jne 0x564d
callq 0x2070
movl (%rax), %edi
callq 0x2350
movq %rax, %rsi
leaq 0x638a(%rip), %rdi      # 0xb9c4
movb $0x0, %al
callq 0x5990
movl $0x0, -0x4(%rbp)
jmp 0x5857
cmpl $0x0, -0x94(%rbp)
je 0x5662
movl $0x1, -0x4(%rbp)
jmp 0x5857
jmp 0x5664
xorl %edi, %edi
callq 0x2170
movl $0x1, %edi
callq 0x2170
movl $0xfffffe7f, %edi       # imm = 0xFFFFFE7F
callq 0x2200
leaq -0x8e(%rbp), %rdi
addq $0x2, %rdi
callq 0x2080
cmpl $0x0, %eax
je 0x56bd
callq 0x2070
cmpl $0x2, (%rax)
je 0x56bb
callq 0x2070
movl (%rax), %edi
callq 0x2350
movq %rax, %rsi
leaq 0x632d(%rip), %rdi      # 0xb9e1
movb $0x0, %al
callq 0x3340
jmp 0x56bd
movl -0x20(%rbp), %edi
leaq -0x8e(%rbp), %rsi
movl $0x6e, %edx
callq 0x2290
cmpl $0x0, %eax
je 0x5720
callq 0x2070
cmpl $0x62, (%rax)
je 0x5716
leaq -0x8e(%rbp), %rax
addq $0x2, %rax
movq %rax, -0xa8(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x2350
movq -0xa8(%rbp), %rsi
movq %rax, %rdx
leaq 0x62f9(%rip), %rdi      # 0xba08
movb $0x0, %al
callq 0x5990
movl $0x1, %edi
callq 0x2310
movl -0x20(%rbp), %edi
movl $0x1000, %esi           # imm = 0x1000
callq 0x2260
cmpl $0x0, %eax
je 0x5763
callq 0x2070
cmpl $0x62, (%rax)
je 0x5759
callq 0x2070
movl (%rax), %edi
callq 0x2350
movq %rax, %rsi
leaq 0x62db(%rip), %rdi      # 0xba2d
movb $0x0, %al
callq 0x3340
movl $0x1, %edi
callq 0x2310
movl $0x2, %edi
callq 0x2170
imull $0x3e8, 0x9b29(%rip), %edx # imm = 0x3E8
leaq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x2280
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x9c(%rbp)
jge 0x57c1
leaq -0x8e(%rbp), %rdi
addq $0x2, %rdi
callq 0x2080
callq 0x2070
movl (%rax), %edi
callq 0x2350
movq %rax, %rsi
leaq 0x629a(%rip), %rdi      # 0xba54
movb $0x0, %al
callq 0x3340
cmpl $0x0, -0x9c(%rbp)
jne 0x57fa
leaq -0x8e(%rbp), %rdi
addq $0x2, %rdi
callq 0x2080
movq 0x9817(%rip), %rax      # 0xeff8
movq (%rax), %rsi
leaq 0x6281(%rip), %rdi      # 0xba6c
callq 0x2150
movl -0x20(%rbp), %edi
callq 0x2170
jmp 0x5850
movl -0x20(%rbp), %edi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x22f0
movl %eax, -0x98(%rbp)
cmpl $-0x1, -0x98(%rbp)
je 0x584b
movl -0x98(%rbp), %edi
movq -0x10(%rbp), %rsi
movl $0x20, %edx
callq 0x20f0
cmpq $0x20, %rax
je 0x5840
leaq 0x6248(%rip), %rdi      # 0xba81
movb $0x0, %al
callq 0x5990
movl -0x98(%rbp), %edi
callq 0x2170
jmp 0x576d
xorl %edi, %edi
callq 0x2310
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)