#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct dhcp6_if {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ NLM_F_ROOT;
int /*<<< orphan*/ RTM_GETLINK;
int /*<<< orphan*/ RTM_GETROUTE;
int /*<<< orphan*/ RTM_NEWLINK;
int /*<<< orphan*/ RTM_NEWROUTE;
int /*<<< orphan*/ close(int);
int netlink_recv_rtgenmsg(int, int /*<<< orphan*/, int, struct dhcp6_if *);
int netlink_send_rtgenmsg(int, int /*<<< orphan*/, int /*<<< orphan*/, int);
int netlink_send_rtmsg(int, int /*<<< orphan*/, int /*<<< orphan*/, int);
int open_netlink_socket();
int time(int /*<<< orphan*/ *);
int get_if_rainfo(struct dhcp6_if *ifp) {
  int sd, status;
  int seq = time(NULL);
  sd = open_netlink_socket();
  if (sd < 0)
    return sd;
  status = netlink_send_rtmsg(sd, RTM_GETROUTE, NLM_F_ROOT, seq);
  if (status >= 0)
    status = netlink_recv_rtgenmsg(sd, RTM_NEWROUTE, seq, ifp);
  else
    goto out;
  status = netlink_send_rtgenmsg(sd, RTM_GETLINK, NLM_F_ROOT, seq);
  if (status >= 0)
    status = netlink_recv_rtgenmsg(sd, RTM_NEWLINK, seq, ifp);
out:
  close(sd);
  return status;
}


x86 assembly (clang, -O0):
<get_if_rainfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <open_netlink_socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1197 <get_if_rainfo+0x37>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123e <get_if_rainfo+0xde>
mov    -0x14(%rbp),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
mov    -0x1c(%rbp),%ecx
call   1080 <netlink_send_rtmsg@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11e1 <get_if_rainfo+0x81>
mov    -0x14(%rbp),%edi
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1030 <netlink_recv_rtgenmsg@plt>
mov    %eax,-0x18(%rbp)
jmp    11e6 <get_if_rainfo+0x86>
jmp    1230 <get_if_rainfo+0xd0>
mov    -0x14(%rbp),%edi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
mov    -0x1c(%rbp),%ecx
call   1070 <netlink_send_rtgenmsg@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     122b <get_if_rainfo+0xcb>
mov    -0x14(%rbp),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1030 <netlink_recv_rtgenmsg@plt>
mov    %eax,-0x18(%rbp)
jmp    1230 <get_if_rainfo+0xd0>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_if_rainfo>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1050 <open_netlink_socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11f6 <get_if_rainfo+0x96>
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    0x2e46(%rip),%r12
mov    (%r12),%edx
mov    %ebp,%edi
mov    %r15d,%ecx
call   1080 <netlink_send_rtmsg@plt>
test   %eax,%eax
js     11eb <get_if_rainfo+0x8b>
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r15d,%edx
mov    %r14,%rcx
call   1030 <netlink_recv_rtgenmsg@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    (%r12),%edx
mov    %ebp,%edi
mov    %r15d,%ecx
call   1070 <netlink_send_rtgenmsg@plt>
test   %eax,%eax
js     11eb <get_if_rainfo+0x8b>
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r15d,%edx
mov    %r14,%rcx
call   1030 <netlink_recv_rtgenmsg@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dhcp6_if = type { i32 }
@RTM_GETROUTE = global i32 0
@NLM_F_ROOT = global i32 0
@RTM_NEWROUTE = global i32 0
@RTM_GETLINK = global i32 0
@RTM_NEWLINK = global i32 0
define i32 @get_if_rainfo(%struct.dhcp6_if* %0) {
%2 = alloca i32
%3 = alloca %struct.dhcp6_if*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.dhcp6_if* %0, %struct.dhcp6_if** %3
%7 = call i32 @time(i32* null)
store i32 %7, i32* %6
%8 = call i32 (...) @open_netlink_socket()
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %47
13: ; preds = %1
%14 = load i32, i32* %4
%15 = load i32, i32* @RTM_GETROUTE
%16 = load i32, i32* @NLM_F_ROOT
%17 = load i32, i32* %6
%18 = call i32 @netlink_send_rtmsg(i32 %14, i32 %15, i32 %16, i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %13
%22 = load i32, i32* %4
%23 = load i32, i32* @RTM_NEWROUTE
%24 = load i32, i32* %6
%25 = load %struct.dhcp6_if*, %struct.dhcp6_if** %3
%26 = call i32 @netlink_recv_rtgenmsg(i32 %22, i32 %23, i32 %24, %struct.dhcp6_if* %25)
store i32 %26, i32* %5
br label %28
27: ; preds = %13
br label %43
28: ; preds = %21
%29 = load i32, i32* %4
%30 = load i32, i32* @RTM_GETLINK
%31 = load i32, i32* @NLM_F_ROOT
%32 = load i32, i32* %6
%33 = call i32 @netlink_send_rtgenmsg(i32 %29, i32 %30, i32 %31, i32 %32)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = icmp sge i32 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %28
%37 = load i32, i32* %4
%38 = load i32, i32* @RTM_NEWLINK
%39 = load i32, i32* %6
%40 = load %struct.dhcp6_if*, %struct.dhcp6_if** %3
%41 = call i32 @netlink_recv_rtgenmsg(i32 %37, i32 %38, i32 %39, %struct.dhcp6_if* %40)
store i32 %41, i32* %5
br label %42
42: ; preds = %36, %28
br label %43
43: ; preds = %42, %27
%44 = load i32, i32* %4
%45 = call i32 @close(i32 %44)
%46 = load i32, i32* %5
store i32 %46, i32* %2
br label %47
47: ; preds = %43, %11
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
%struct.dhcp6_if = type { i32 }
@RTM_GETROUTE = global i32 0
@NLM_F_ROOT = global i32 0
@RTM_NEWROUTE = global i32 0
@RTM_GETLINK = global i32 0
@RTM_NEWLINK = global i32 0
define i32 @get_if_rainfo(%struct.dhcp6_if* %0) {
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 (...) @open_netlink_socket()
%4 = icmp slt i32 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %1
%6 = load i32, i32* @RTM_GETROUTE
%7 = load i32, i32* @NLM_F_ROOT
%8 = tail call i32 @netlink_send_rtmsg(i32 %3, i32 %6, i32 %7, i32 %2)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %20
10: ; preds = %5
%11 = load i32, i32* @RTM_NEWROUTE
%12 = tail call i32 @netlink_recv_rtgenmsg(i32 %3, i32 %11, i32 %2, %struct.dhcp6_if* %0)
%13 = load i32, i32* @RTM_GETLINK
%14 = load i32, i32* @NLM_F_ROOT
%15 = tail call i32 @netlink_send_rtgenmsg(i32 %3, i32 %13, i32 %14, i32 %2)
%16 = icmp sgt i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i32, i32* @RTM_NEWLINK
%19 = tail call i32 @netlink_recv_rtgenmsg(i32 %3, i32 %18, i32 %2, %struct.dhcp6_if* %0)
br label %20
20: ; preds = %10, %17, %5
%21 = phi i32 [ %19, %17 ], [ %15, %10 ], [ %8, %5 ]
%22 = tail call i32 @close(i32 %3)
br label %23
23: ; preds = %1, %20
%24 = phi i32 [ %21, %20 ], [ %3, %1 ]
ret i32 %24
}