// File: /workspace/github_c_makefile_star2_O2/jech[P]shncpd/kernel.c
// Function: kernel_route
int
kernel_route(int ifindex, const char *ifname,
             const struct in6_addr *dest, int dlen,
             const struct in6_addr *src, int slen,
             int add)
{
    char to[INET6_ADDRSTRLEN];
    char from[INET6_ADDRSTRLEN];
    char iface[20];
    char *type, *metric;
    char cmd[2 * INET6_ADDRSTRLEN + 80];
    int rc;

    if(memcmp(dest, v4prefix, 12) == 0) {
        inet_ntop(AF_INET, (char*)dest + 12, to, sizeof(to));
        dlen -= 96;
    } else {
        inet_ntop(AF_INET6, dest, to, sizeof(to));
    }

    if(src) {
        if(memcmp(src, v4prefix, 12) == 0) {
            errno = ENOSYS;
            return -1;
        } else {
            inet_ntop(AF_INET6, src, from, sizeof(from));
        }
    }

    if(ifname) {
        rc = snprintf(iface, sizeof(iface), " dev %s", ifname);
        if(rc < 1 || rc >= sizeof(iface)) {
            errno = ENOSPC;
            return -1;
        }
        type = "";
        /* Unfortunately, Linux doesn't allow duplicate routes even if they
           have different protocol numbers. */
        metric = " metric 512";
    } else {
        iface[0] = '\0';
        type = " unreachable";
        metric = " metric 4096";
    }

    if(src)
        rc = snprintf(cmd, sizeof(cmd),
                      "ip route %s%s %s/%d%s from %s/%d%s proto 43",
                      add ? "add" : "del", type, to, dlen, metric,
                      from, slen, iface);
    else
        rc = snprintf(cmd, sizeof(cmd),
                      "ip route %s%s %s/%d%s%s proto 43",
                      add ? "add" : "del", type, to, dlen, metric, iface);
    if(rc < 1 || rc >= sizeof(cmd)) {
        errno = ENOSPC;
        return -1;
    }

    rc = system(cmd);
    if(rc >= 0 && WIFEXITED(rc) && WEXITSTATUS(rc) == 0)
        return 1;

    if(rc >= 0)
        errno = EIO;            /* any better ideas? */
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %r9d, %r14d
movq %r8, %r15
movl %ecx, %ebx
movq %rdx, %r13
movq %rsi, %r12
leaq 0x2dcb(%rip), %rsi      # 0xd280
pushq $0xc
popq %rdx
movq %r13, %rdi
callq 0x2270
testl %eax, %eax
je 0xa4d9
pushq $0xa
popq %rdi
leaq 0x20(%rsp), %rdx
pushq $0x2e
popq %rcx
movq %r13, %rsi
callq 0x2030
jmp 0xa4f3
addq $0xc, %r13
pushq $0x2
popq %rdi
leaq 0x20(%rsp), %rdx
pushq $0x2e
popq %rcx
movq %r13, %rsi
callq 0x2030
addl $-0x60, %ebx
testq %r15, %r15
je 0xa525
leaq 0x2d81(%rip), %rsi      # 0xd280
pushq $0xc
popq %rdx
movq %r15, %rdi
callq 0x2270
testl %eax, %eax
je 0xa5ce
pushq $0xa
popq %rdi
leaq 0x50(%rsp), %rdx
pushq $0x2e
popq %rcx
movq %r15, %rsi
callq 0x2030
pushq $0x1c
popq %rbp
testq %r12, %r12
je 0xa560
leaq 0x2d6c(%rip), %rdx      # 0xd2a0
movq %rsp, %rdi
pushq $0x14
popq %rsi
movq %r12, %rcx
xorl %eax, %eax
callq 0x2140
addl $-0x14, %eax
cmpl $-0x13, %eax
jb 0xa63a
leaq 0x2d59(%rip), %r10      # 0xd2b0
leaq 0x238c(%rip), %r8       # 0xc8ea
jmp 0xa572
movb $0x0, (%rsp)
leaq 0x2d5e(%rip), %r10      # 0xd2c9
leaq 0x2d4a(%rip), %r8       # 0xd2bc
cmpl $0x0, 0x170(%rsp)
leaq 0x2d2b(%rip), %rax      # 0xd2ac
leaq 0x2d20(%rip), %rcx      # 0xd2a8
cmoveq %rax, %rcx
subq $0x8, %rsp
testq %r15, %r15
je 0xa5d2
leaq 0x8(%rsp), %r11
leaq 0x58(%rsp), %r15
leaq 0x2d30(%rip), %rdx      # 0xd2d6
leaq 0x88(%rsp), %rdi
leaq 0x28(%rsp), %r9
movl $0xac, %esi
xorl %eax, %eax
pushq %r11
pushq %r14
pushq %r15
pushq %r10
pushq %rbx
callq 0x2140
addq $0x30, %rsp
jmp 0xa600
pushq $0x26
jmp 0xa639
leaq 0x8(%rsp), %r11
leaq 0x2d24(%rip), %rdx      # 0xd302
leaq 0x88(%rsp), %rdi
leaq 0x28(%rsp), %r9
movl $0xac, %esi
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %rbx
callq 0x2140
addq $0x20, %rsp
addl $0xffffff54, %eax       # imm = 0xFFFFFF54
cmpl $0xffffff55, %eax       # imm = 0xFFFFFF55
jb 0xa63a
leaq 0x80(%rsp), %rdi
callq 0x2100
testl %eax, %eax
sets %dl
xorl %ecx, %ecx
testl $0x8000ff7f, %eax       # imm = 0x8000FF7F
sete %al
orb %al, %dl
je 0xa637
movb %al, %cl
leal -0x1(,%rcx,2), %eax
jmp 0xa644
pushq $0x5
popq %rbp
callq 0x2060
movl %ebp, (%rax)
pushq $-0x1
popq %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq