// File: /workspace/github_c_makefile_star2_O0/panux[P]linit/src/linit-sup-stop.c
// Function: main
int main(int argc, char **argv) {
    if(argc != 3) {
        perror("Missing args\n");
        return 1;
    }
    //connect
    int fd = socket(AF_UNIX, SOCK_STREAM, 0);
    if(fd == -1) {
        fprintf(stderr, "Failed to create socket: %s\n", strerror(errno));
        return 65;
    }
    struct sockaddr_un addr = { .sun_family = AF_UNIX };
    strcpy(addr.sun_path, "/tmp/linit-supd.sock");
    if(connect(fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_un)) == -1) {
        fprintf(stderr, "Failed to connect: %s\n", strerror(errno));
        return 65;
    }
    FILE *supconn = fdopen(fd, "r+");
    if(supconn == NULL) {
        fprintf(stderr, "Failed to convert fd to stream: %s\n", strerror(errno));
        return 65;
    }
    //write command
    if(fprintf(supconn, "^%d%s\n", atoi(argv[1]), argv[2]) == -1) {
        fprintf(stderr, "Failed to write to linit-supd connection: %s\n", strerror(errno));
        return 65;
    }
    if(fflush(supconn) != 0) {
        fprintf(stderr, "Failed to flush linit-supd connection: %s\n", strerror(errno));
        return 65;
    }
    //get response
    char resp[80];
    if(fgets(resp, 80, supconn) == NULL) {
        fprintf(stderr, "Failed to get response from linit-supd connection: %s\n", strerror(errno));
        return 65;
    }
    fclose(supconn);
    if(!streq(resp, "ok\n")) {
        return 65;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
je 0x1247
leaq 0xdce(%rip), %rdi       # 0x2004
callq 0x10c0
movl $0x1, -0x4(%rbp)
jmp 0x14ef
movl $0x1, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x1100
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x129f
movq 0x2d93(%rip), %rax      # 0x3ff8
movq (%rax), %rax
movq %rax, -0xe8(%rbp)
callq 0x1030
movl (%rax), %edi
callq 0x10f0
movq -0xe8(%rbp), %rdi
movq %rax, %rdx
leaq 0xd86(%rip), %rsi       # 0x2012
movb $0x0, %al
callq 0x1090
movl $0x41, -0x4(%rbp)
jmp 0x14ef
leaq -0x82(%rbp), %rdi
xorl %esi, %esi
movl $0x6e, %edx
callq 0x1060
movw $0x1, -0x82(%rbp)
leaq -0x82(%rbp), %rdi
addq $0x2, %rdi
leaq 0xd62(%rip), %rsi       # 0x202f
callq 0x1040
movl -0x14(%rbp), %edi
leaq -0x82(%rbp), %rsi
movl $0x6e, %edx
callq 0x10e0
cmpl $-0x1, %eax
jne 0x132c
movq 0x2d06(%rip), %rax      # 0x3ff8
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
callq 0x1030
movl (%rax), %edi
callq 0x10f0
movq -0xf0(%rbp), %rdi
movq %rax, %rdx
leaq 0xd2b(%rip), %rsi       # 0x2044
movb $0x0, %al
callq 0x1090
movl $0x41, -0x4(%rbp)
jmp 0x14ef
movl -0x14(%rbp), %edi
leaq 0xd25(%rip), %rsi       # 0x205b
callq 0x10b0
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x138d
movq 0x2ca5(%rip), %rax      # 0x3ff8
movq (%rax), %rax
movq %rax, -0xf8(%rbp)
callq 0x1030
movl (%rax), %edi
callq 0x10f0
movq -0xf8(%rbp), %rdi
movq %rax, %rdx
leaq 0xce4(%rip), %rsi       # 0x205e
movb $0x0, %al
callq 0x1090
movl $0x41, -0x4(%rbp)
jmp 0x14ef
movq -0x90(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x10d0
movq -0x100(%rbp), %rdi
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0xcc2(%rip), %rsi       # 0x2082
movb $0x0, %al
callq 0x1090
cmpl $-0x1, %eax
jne 0x140d
movq 0x2c25(%rip), %rax      # 0x3ff8
movq (%rax), %rax
movq %rax, -0x108(%rbp)
callq 0x1030
movl (%rax), %edi
callq 0x10f0
movq -0x108(%rbp), %rdi
movq %rax, %rdx
leaq 0xc8f(%rip), %rsi       # 0x2089
movb $0x0, %al
callq 0x1090
movl $0x41, -0x4(%rbp)
jmp 0x14ef
movq -0x90(%rbp), %rdi
callq 0x10a0
cmpl $0x0, %eax
je 0x145f
movq 0x2bd3(%rip), %rax      # 0x3ff8
movq (%rax), %rax
movq %rax, -0x110(%rbp)
callq 0x1030
movl (%rax), %edi
callq 0x10f0
movq -0x110(%rbp), %rdi
movq %rax, %rdx
leaq 0xc6b(%rip), %rsi       # 0x20b7
movb $0x0, %al
callq 0x1090
movl $0x41, -0x4(%rbp)
jmp 0x14ef
leaq -0xe0(%rbp), %rdi
movq -0x90(%rbp), %rdx
movl $0x50, %esi
callq 0x1070
cmpq $0x0, %rax
jne 0x14bb
movq 0x2b74(%rip), %rax      # 0x3ff8
movq (%rax), %rax
movq %rax, -0x118(%rbp)
callq 0x1030
movl (%rax), %edi
callq 0x10f0
movq -0x118(%rbp), %rdi
movq %rax, %rdx
leaq 0xc37(%rip), %rsi       # 0x20e2
movb $0x0, %al
callq 0x1090
movl $0x41, -0x4(%rbp)
jmp 0x14ef
movq -0x90(%rbp), %rdi
callq 0x1050
leaq -0xe0(%rbp), %rdi
leaq 0xc44(%rip), %rsi       # 0x2119
callq 0x1080
cmpl $0x0, %eax
je 0x14e8
movl $0x41, -0x4(%rbp)
jmp 0x14ef
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq