// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x1a0, %rsp            # imm = 0x1A0
movl 0x10(%rbp), %eax
movl %edi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movl %ecx, -0x2c(%rbp)
movq %r8, -0x38(%rbp)
movl %r9d, -0x3c(%rbp)
movq -0x28(%rbp), %rdi
leaq 0x3f5e(%rip), %rsi      # 0x13420
movl $0xc, %edx
callq 0x21c0
cmpl $0x0, %eax
jne 0xf4f7
movq -0x28(%rbp), %rsi
addq $0xc, %rsi
leaq -0x70(%rbp), %rdx
movl $0x2, %edi
movl $0x2e, %ecx
callq 0x2030
movl -0x2c(%rbp), %eax
subl $0x60, %eax
movl %eax, -0x2c(%rbp)
jmp 0xf50e
movq -0x28(%rbp), %rsi
leaq -0x70(%rbp), %rdx
movl $0xa, %edi
movl $0x2e, %ecx
callq 0x2030
cmpq $0x0, -0x38(%rbp)
je 0xf562
movq -0x38(%rbp), %rdi
leaq 0x3f00(%rip), %rsi      # 0x13420
movl $0xc, %edx
callq 0x21c0
cmpl $0x0, %eax
jne 0xf546
callq 0x2050
movl $0x26, (%rax)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xf76b
movq -0x38(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
movl $0xa, %edi
movl $0x2e, %ecx
callq 0x2030
jmp 0xf562
cmpq $0x0, -0x20(%rbp)
je 0xf5d8
leaq -0xc0(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl $0x14, %esi
leaq 0x3ec0(%rip), %rdx      # 0x13440
movb $0x0, %al
callq 0x2140
movl %eax, -0x184(%rbp)
cmpl $0x1, -0x184(%rbp)
jl 0xf5a3
movslq -0x184(%rbp), %rax
cmpq $0x14, %rax
jb 0xf5ba
callq 0x2050
movl $0x1c, (%rax)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xf76b
leaq 0x3425(%rip), %rax      # 0x129e6
movq %rax, -0xc8(%rbp)
leaq 0x3e81(%rip), %rax      # 0x13450
movq %rax, -0xd0(%rbp)
jmp 0xf5fb
movb $0x0, -0xc0(%rbp)
leaq 0x3e76(%rip), %rax      # 0x1345c
movq %rax, -0xc8(%rbp)
leaq 0x3e75(%rip), %rax      # 0x13469
movq %rax, -0xd0(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0xf67c
leaq -0x180(%rbp), %rdi
movl 0x10(%rbp), %edx
leaq 0x3e39(%rip), %rcx      # 0x1344c
leaq 0x3e2e(%rip), %rax      # 0x13448
cmpl $0x0, %edx
cmovneq %rax, %rcx
movq -0xc8(%rbp), %r8
leaq -0x70(%rbp), %r9
movl -0x2c(%rbp), %r14d
movq -0xd0(%rbp), %rbx
leaq -0xa0(%rbp), %r11
movl -0x3c(%rbp), %r10d
leaq -0xc0(%rbp), %rax
movl $0xac, %esi
leaq 0x3e21(%rip), %rdx      # 0x13476
movl %r14d, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb $0x0, %al
callq 0x2140
movl %eax, -0x184(%rbp)
jmp 0xf6df
leaq -0x180(%rbp), %rdi
movl 0x10(%rbp), %edx
leaq 0x3dbf(%rip), %rcx      # 0x1344c
leaq 0x3db4(%rip), %rax      # 0x13448
cmpl $0x0, %edx
cmovneq %rax, %rcx
movq -0xc8(%rbp), %r8
leaq -0x70(%rbp), %r9
movl -0x2c(%rbp), %r11d
movq -0xd0(%rbp), %r10
leaq -0xc0(%rbp), %rax
movl $0xac, %esi
leaq 0x3dde(%rip), %rdx      # 0x134a2
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x2140
movl %eax, -0x184(%rbp)
cmpl $0x1, -0x184(%rbp)
jl 0xf6f7
movslq -0x184(%rbp), %rax
cmpq $0xac, %rax
jb 0xf70b
callq 0x2050
movl $0x1c, (%rax)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xf76b
leaq -0x180(%rbp), %rdi
callq 0x20f0
movl %eax, -0x184(%rbp)
cmpl $0x0, -0x184(%rbp)
jl 0xf750
movl -0x184(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0xf750
movl -0x184(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
cmpl $0x0, %eax
jne 0xf750
movl $0x1, -0x14(%rbp)
jmp 0xf76b
cmpl $0x0, -0x184(%rbp)
jl 0xf764
callq 0x2050
movl $0x5, (%rax)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movl -0x14(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbx
popq %r14
popq %rbp
retq
nopw (%rax,%rax)