// File: /workspace/github_c_makefile_star2_O3/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 0xb1e1
leaq 0x20(%rsp), %rax
movl $0xa, %edi
movq %rdx, %rsi
movq %rax, %rdx
movl $0x2e, %ecx
callq 0x2030
jmp 0xb202
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 0xb22e
movl 0x8(%r15), %eax
xorq %r13, %rax
orq (%r15), %rax
je 0xb2db
leaq 0x50(%rsp), %rdx
movl $0xa, %edi
movq %r15, %rsi
movl $0x2e, %ecx
callq 0x2030
testq %r12, %r12
je 0xb26d
leaq 0x3086(%rip), %rdx      # 0xe2c0
movq %rsp, %rdi
movl $0x14, %esi
movq %r12, %rcx
xorl %eax, %eax
callq 0x2140
addl $-0x14, %eax
movl $0x1c, %ebp
cmpl $-0x13, %eax
jb 0xb351
leaq 0x306c(%rip), %r10      # 0xe2d0
leaq 0x26a7(%rip), %r8       # 0xd912
jmp 0xb27f
movb $0x0, (%rsp)
leaq 0x3071(%rip), %r10      # 0xe2e9
leaq 0x305d(%rip), %r8       # 0xe2dc
cmpl $0x0, 0x170(%rsp)
leaq 0x303e(%rip), %rax      # 0xe2cc
leaq 0x3033(%rip), %rcx      # 0xe2c8
cmoveq %rax, %rcx
subq $0x8, %rsp
testq %r15, %r15
je 0xb2e2
leaq 0x8(%rsp), %r11
leaq 0x58(%rsp), %r15
leaq 0x3043(%rip), %rdx      # 0xe2f6
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 0xb310
movl $0x26, %ebp
jmp 0xb351
leaq 0x8(%rsp), %r11
leaq 0x3034(%rip), %rdx      # 0xe322
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 0xb351
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 0xb351
movb %al, %cl
leal -0x1(,%rcx,2), %eax
jmp 0xb35d
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