// File: /workspace/github_c_makefile_star2_O1/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 %rsi, %r12
movl $0xffff0000, %r13d      # imm = 0xFFFF0000
movl 0x8(%rdx), %eax
xorq %r13, %rax
orq (%rdx), %rax
je 0xb7b5
leaq 0x20(%rsp), %rax
movl $0xa, %edi
movq %rdx, %rsi
movq %rax, %rdx
movl $0x2e, %ecx
callq 0x2030
jmp 0xb7d6
addq $0xc, %rdx
leaq 0x20(%rsp), %rax
movl $0x2, %edi
movq %rdx, %rsi
movq %rax, %rdx
movl $0x2e, %ecx
callq 0x2030
addl $-0x60, %ebx
testq %r15, %r15
je 0xb802
movl 0x8(%r15), %eax
xorq %r13, %rax
orq (%r15), %rax
je 0xb8af
leaq 0x50(%rsp), %rdx
movl $0xa, %edi
movq %r15, %rsi
movl $0x2e, %ecx
callq 0x2030
testq %r12, %r12
je 0xb841
leaq 0x2af2(%rip), %rdx      # 0xe300
movq %rsp, %rdi
movl $0x14, %esi
movq %r12, %rcx
xorl %eax, %eax
callq 0x2140
addl $-0x14, %eax
movl $0x1c, %ebp
cmpl $-0x13, %eax
jb 0xb925
leaq 0x2ad8(%rip), %r10      # 0xe310
leaq 0x20f3(%rip), %r8       # 0xd932
jmp 0xb853
movb $0x0, (%rsp)
leaq 0x2add(%rip), %r10      # 0xe329
leaq 0x2ac9(%rip), %r8       # 0xe31c
cmpl $0x0, 0x170(%rsp)
leaq 0x2aaa(%rip), %rax      # 0xe30c
leaq 0x2a9f(%rip), %rcx      # 0xe308
cmoveq %rax, %rcx
subq $0x8, %rsp
testq %r15, %r15
je 0xb8b6
leaq 0x8(%rsp), %r11
leaq 0x58(%rsp), %r15
leaq 0x2aaf(%rip), %rdx      # 0xe336
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 0xb8e4
movl $0x26, %ebp
jmp 0xb925
leaq 0x8(%rsp), %r11
leaq 0x2aa0(%rip), %rdx      # 0xe362
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
movl $0x1c, %ebp
cmpl $0xffffff55, %eax       # imm = 0xFFFFFF55
jb 0xb925
leaq 0x80(%rsp), %rdi
callq 0x2100
testl %eax, %eax
sets %dl
xorl %ecx, %ecx
testl $0x8000ff7f, %eax       # imm = 0x8000FF7F
sete %al
orb %al, %dl
movl $0x5, %ebp
je 0xb925
movb %al, %cl
leal -0x1(,%rcx,2), %eax
jmp 0xb931
callq 0x2060
movl %ebp, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq