#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 sockaddr_nl {
  int dummy;
};
struct nlmsghdr {
  scalar_t__ nlmsg_type;
  scalar_t__ nlmsg_pid;
  int nlmsg_seq;
};
struct msghdr {
  int msg_namelen;
  int msg_iovlen;
  int msg_flags;
  struct iovec *msg_iov;
  void *msg_name;
};
struct iovec {
  char *member_0;
  size_t member_1;
};
struct dhcp6_if {
  int dummy;
};
typedef int /*<<< orphan*/ nl_addr;
typedef int /*<<< orphan*/ msgh;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ LOG_DEBUG;
int /*<<< orphan*/ LOG_ERR;
int MSG_TRUNC;
scalar_t__ NLMSG_DONE;
scalar_t__ NLMSG_ERROR;
scalar_t__ NLMSG_NEXT(struct nlmsghdr *, int);
scalar_t__ NLMSG_OK(struct nlmsghdr *, int);
int RTM_NEWLINK;
int RTM_NEWROUTE;
int /*<<< orphan*/ dprintf(int /*<<< orphan*/, char *);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_if_flags(struct nlmsghdr *, int, int, struct dhcp6_if *);
int /*<<< orphan*/ get_if_prefix(struct nlmsghdr *, int, int,
                                 struct dhcp6_if *);
scalar_t__ getpid();
int /*<<< orphan*/ memset(struct msghdr *, int /*<<< orphan*/, int);
void *realloc(char *, size_t);
int recvmsg(int, struct msghdr *, int /*<<< orphan*/);
scalar_t__ time(int /*<<< orphan*/ *);
int netlink_recv_rtgenmsg(int sd, int request, int seq, struct dhcp6_if *ifp) {
  struct nlmsghdr *nlm;
  struct msghdr msgh;
  struct sockaddr_nl nl_addr;
  char *buf = NULL;
  size_t newsize = 65536, size = 0;
  int msg_len;
  dprintf(LOG_DEBUG, "netlink_recv_rtgenmsg called");
  if (seq == 0)
    seq = (int)time(NULL);
  for (;;) {
    void *newbuf = realloc(buf, newsize);
    if (newbuf == NULL) {
      msg_len = -1;
      break;
    }
    buf = newbuf;
    do {
      struct iovec iov = {buf, newsize};
      memset(&msgh, 0, sizeof(msgh));
      msgh.msg_name = (void *)&nl_addr;
      msgh.msg_namelen = sizeof(nl_addr);
      msgh.msg_iov = &iov;
      msgh.msg_iovlen = 1;
      msg_len = recvmsg(sd, &msgh, 0);
    } while (msg_len < 0 && errno == EINTR);
    if (msg_len < 0 || msgh.msg_flags & MSG_TRUNC) {
      size = newsize;
      newsize *= 2;
      continue;
    } else if (msg_len == 0)
      break;
    for (nlm = (struct nlmsghdr *)buf; NLMSG_OK(nlm, msg_len);
         nlm = (struct nlmsghdr *)NLMSG_NEXT(nlm, msg_len)) {
      if (nlm->nlmsg_type == NLMSG_DONE || nlm->nlmsg_type == NLMSG_ERROR) {
        dprintf(LOG_ERR, "netlink_recv_rtgenmsg error");
        goto out;
      }
      if (nlm->nlmsg_pid != getpid() || nlm->nlmsg_seq != seq)
        continue;
      if (request == RTM_NEWROUTE)
        get_if_prefix(nlm, msg_len, request, ifp);
      if (request == RTM_NEWLINK)
        get_if_flags(nlm, msg_len, request, ifp);
    }
    free(buf);
    buf = NULL;
  }
out:
  if (buf)
    free(buf);
  return msg_len;
}


x86 assembly (clang, -O0):
<netlink_recv_rtgenmsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x10000,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
call   1070 <dprintf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    120b <netlink_recv_rtgenmsg+0x5b>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0xc(%rbp)
jmp    1210 <netlink_recv_rtgenmsg+0x60>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1090 <realloc@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    1238 <netlink_recv_rtgenmsg+0x88>
movl   $0xffffffff,-0x64(%rbp)
jmp    1436 <netlink_recv_rtgenmsg+0x286>
mov    -0x70(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
lea    -0x48(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x4,-0x40(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x40(%rbp),%rsi
xor    %edx,%edx
call   10a0 <recvmsg@plt>
mov    %eax,-0x64(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x64(%rbp)
mov    %al,-0x81(%rbp)
jge    12be <netlink_recv_rtgenmsg+0x10e>
mov    0x2d18(%rip),%rax
mov    (%rax),%rax
mov    0x2d06(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x81(%rbp)
mov    -0x81(%rbp),%al
test   $0x1,%al
jne    1240 <netlink_recv_rtgenmsg+0x90>
cmpl   $0x0,-0x64(%rbp)
jl     12eb <netlink_recv_rtgenmsg+0x13b>
mov    -0x38(%rbp),%eax
mov    0x2d00(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1304 <netlink_recv_rtgenmsg+0x154>
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1210 <netlink_recv_rtgenmsg+0x60>
cmpl   $0x0,-0x64(%rbp)
jne    1313 <netlink_recv_rtgenmsg+0x163>
jmp    1436 <netlink_recv_rtgenmsg+0x286>
jmp    1318 <netlink_recv_rtgenmsg+0x168>
mov    -0x50(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1050 <NLMSG_OK@plt>
cmp    $0x0,%rax
je     1420 <netlink_recv_rtgenmsg+0x270>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2c8c(%rip),%rcx
cmp    (%rcx),%rax
je     1364 <netlink_recv_rtgenmsg+0x1b4>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2c8d(%rip),%rcx
cmp    (%rcx),%rax
jne    137e <netlink_recv_rtgenmsg+0x1ce>
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
lea    0xca9(%rip),%rsi
call   1070 <dprintf@plt>
jmp    143b <netlink_recv_rtgenmsg+0x28b>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x90(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,%rcx
mov    -0x90(%rbp),%rax
cmp    %rcx,%rax
jne    13b7 <netlink_recv_rtgenmsg+0x207>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%eax
cmp    -0xc(%rbp),%eax
je     13bc <netlink_recv_rtgenmsg+0x20c>
jmp    140b <netlink_recv_rtgenmsg+0x25b>
mov    -0x8(%rbp),%eax
mov    0x2bda(%rip),%rcx
cmp    (%rcx),%eax
jne    13e1 <netlink_recv_rtgenmsg+0x231>
mov    -0x20(%rbp),%rdi
mov    -0x64(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   10b0 <get_if_prefix@plt>
mov    -0x8(%rbp),%eax
mov    0x2bdd(%rip),%rcx
cmp    (%rcx),%eax
jne    1406 <netlink_recv_rtgenmsg+0x256>
mov    -0x20(%rbp),%rdi
mov    -0x64(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   10c0 <get_if_flags@plt>
jmp    140b <netlink_recv_rtgenmsg+0x25b>
mov    -0x20(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   10d0 <NLMSG_NEXT@plt>
mov    %rax,-0x20(%rbp)
jmp    1320 <netlink_recv_rtgenmsg+0x170>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x50(%rbp)
jmp    1210 <netlink_recv_rtgenmsg+0x60>
jmp    143b <netlink_recv_rtgenmsg+0x28b>
cmpq   $0x0,-0x50(%rbp)
je     144f <netlink_recv_rtgenmsg+0x29f>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x64(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netlink_recv_rtgenmsg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rcx,0x8(%rsp)
mov    %edx,%ebx
mov    %esi,0x4(%rsp)
mov    %edi,%r13d
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
call   1070 <dprintf@plt>
mov    %rbx,0x10(%rsp)
test   %ebx,%ebx
jne    1206 <netlink_recv_rtgenmsg+0x46>
xor    %edi,%edi
call   1080 <time@plt>
mov    %rax,0x10(%rsp)
mov    $0x10000,%ebx
mov    $0x10000,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     13ed <netlink_recv_rtgenmsg+0x22d>
mov    %rax,%r12
lea    0x38(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
lea    0x20(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,0x28(%rsp)
mov    %rbx,0x30(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    %rbp,0x50(%rsp)
movabs $0x100000004,%rax
mov    %rax,0x38(%rsp)
lea    0x28(%rsp),%rax
mov    %rax,0x48(%rsp)
mov    %r13d,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   10b0 <recvmsg@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    12a1 <netlink_recv_rtgenmsg+0xe1>
mov    0x2d26(%rip),%rax
mov    (%rax),%rax
mov    0x2d24(%rip),%rcx
cmp    %rax,(%rcx)
je     1240 <netlink_recv_rtgenmsg+0x80>
test   %r15d,%r15d
js     12b5 <netlink_recv_rtgenmsg+0xf5>
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
test   %eax,0x40(%rsp)
je     12e0 <netlink_recv_rtgenmsg+0x120>
add    %rbx,%rbx
mov    %r12,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <realloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1230 <netlink_recv_rtgenmsg+0x70>
jmp    13f5 <netlink_recv_rtgenmsg+0x235>
nopw   0x0(%rax,%rax,1)
test   %r15d,%r15d
je     141d <netlink_recv_rtgenmsg+0x25d>
mov    %r12,%rdi
mov    %r15d,%esi
call   1050 <NLMSG_OK@plt>
test   %rax,%rax
je     13c2 <netlink_recv_rtgenmsg+0x202>
mov    %r12,%rbp
jmp    1332 <netlink_recv_rtgenmsg+0x172>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r15d,%esi
call   10e0 <NLMSG_NEXT@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15d,%esi
call   1050 <NLMSG_OK@plt>
test   %rax,%rax
je     13c2 <netlink_recv_rtgenmsg+0x202>
mov    0x0(%rbp),%rax
mov    0x2c93(%rip),%rcx
cmp    (%rcx),%rax
je     13d1 <netlink_recv_rtgenmsg+0x211>
mov    0x2c9b(%rip),%rcx
cmp    (%rcx),%rax
je     13d1 <netlink_recv_rtgenmsg+0x211>
mov    0x8(%rbp),%rax
mov    %rax,0x18(%rsp)
xor    %eax,%eax
call   1040 <getpid@plt>
cmp    %rax,0x18(%rsp)
jne    1310 <netlink_recv_rtgenmsg+0x150>
mov    0x10(%rsp),%rax
cmp    %eax,0x10(%rbp)
jne    1310 <netlink_recv_rtgenmsg+0x150>
mov    0x4(%rsp),%eax
mov    0x2c22(%rip),%rcx
cmp    %eax,(%rcx)
jne    139a <netlink_recv_rtgenmsg+0x1da>
mov    %rbp,%rdi
mov    %r15d,%esi
mov    0x4(%rsp),%edx
mov    0x8(%rsp),%rcx
call   10c0 <get_if_prefix@plt>
mov    0x4(%rsp),%eax
mov    0x2c27(%rip),%rcx
cmp    %eax,(%rcx)
jne    1310 <netlink_recv_rtgenmsg+0x150>
mov    %rbp,%rdi
mov    %r15d,%esi
mov    0x4(%rsp),%edx
mov    0x8(%rsp),%rcx
call   10d0 <get_if_flags@plt>
jmp    1310 <netlink_recv_rtgenmsg+0x150>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
jmp    12bb <netlink_recv_rtgenmsg+0xfb>
mov    0x2bc0(%rip),%rax
mov    (%rax),%edi
lea    0xc3c(%rip),%rsi
call   1070 <dprintf@plt>
test   %r12,%r12
jne    1403 <netlink_recv_rtgenmsg+0x243>
jmp    140b <netlink_recv_rtgenmsg+0x24b>
mov    $0xffffffff,%r15d
jmp    140b <netlink_recv_rtgenmsg+0x24b>
mov    $0xffffffff,%r15d
mov    %rbp,%r12
test   %r12,%r12
je     140b <netlink_recv_rtgenmsg+0x24b>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r15d,%r15d
test   %r12,%r12
jne    1403 <netlink_recv_rtgenmsg+0x243>
jmp    140b <netlink_recv_rtgenmsg+0x24b>

LLVM IR (-O0):
%struct.dhcp6_if = type { i32 }
%struct.nlmsghdr = type { i64, i64, i32 }
%struct.msghdr = type { i32, i32, i32, %struct.iovec*, i8* }
%struct.iovec = type { i8*, i64 }
%struct.sockaddr_nl = type { i32 }
@LOG_DEBUG = global i32 0
@.str = [29 x i8] c"netlink_recv_rtgenmsg called\00"
@errno = global i64 0
@EINTR = global i64 0
@MSG_TRUNC = global i32 0
@NLMSG_DONE = global i64 0
@NLMSG_ERROR = global i64 0
@LOG_ERR = global i32 0
@.str.1 = [28 x i8] c"netlink_recv_rtgenmsg error\00"
@RTM_NEWROUTE = global i32 0
@RTM_NEWLINK = global i32 0
define i32 @netlink_recv_rtgenmsg(i32 %0, i32 %1, i32 %2, %struct.dhcp6_if* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.dhcp6_if*
%9 = alloca %struct.nlmsghdr*
%10 = alloca %struct.msghdr
%11 = alloca %struct.sockaddr_nl
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
%16 = alloca i8*
%17 = alloca %struct.iovec
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store %struct.dhcp6_if* %3, %struct.dhcp6_if** %8
store i8* null, i8** %12
store i64 65536, i64* %13
store i64 0, i64* %14
%18 = load i32, i32* @LOG_DEBUG
%19 = call i32 @dprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %4
%23 = call i64 @time(i32* null)
%24 = trunc i64 %23 to i32
store i32 %24, i32* %7
br label %25
25: ; preds = %22, %4
br label %26
26: ; preds = %137, %66, %25
%27 = load i8*, i8** %12
%28 = load i64, i64* %13
%29 = call i8* @realloc(i8* %27, i64 %28)
store i8* %29, i8** %16
%30 = load i8*, i8** %16
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 -1, i32* %15
br label %140
33: ; preds = %26
%34 = load i8*, i8** %16
store i8* %34, i8** %12
br label %35
35: ; preds = %55, %33
%36 = getelementptr inbounds %struct.iovec, %struct.iovec* %17, i32 0, i32 0
%37 = load i8*, i8** %12
store i8* %37, i8** %36
%38 = getelementptr inbounds %struct.iovec, %struct.iovec* %17, i32 0, i32 1
%39 = load i64, i64* %13
store i64 %39, i64* %38
%40 = call i32 @memset(%struct.msghdr* %10, i32 0, i32 32)
%41 = bitcast %struct.sockaddr_nl* %11 to i8*
%42 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %10, i32 0, i32 4
store i8* %41, i8** %42
%43 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %10, i32 0, i32 0
store i32 4, i32* %43
%44 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %10, i32 0, i32 3
store %struct.iovec* %17, %struct.iovec** %44
%45 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %10, i32 0, i32 1
store i32 1, i32* %45
%46 = load i32, i32* %5
%47 = call i32 @recvmsg(i32 %46, %struct.msghdr* %10, i32 0)
store i32 %47, i32* %15
br label %48
48: ; preds = %35
%49 = load i32, i32* %15
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %48
%52 = load i64, i64* @errno
%53 = load i64, i64* @EINTR
%54 = icmp eq i64 %52, %53
br label %55
55: ; preds = %51, %48
%56 = phi i1 [ false, %48 ], [ %54, %51 ]
br i1 %56, label %35, label %57
57: ; preds = %55
%58 = load i32, i32* %15
%59 = icmp slt i32 %58, 0
br i1 %59, label %66, label %60
60: ; preds = %57
%61 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %10, i32 0, i32 2
%62 = load i32, i32* %61
%63 = load i32, i32* @MSG_TRUNC
%64 = and i32 %62, %63
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %60, %57
%67 = load i64, i64* %13
store i64 %67, i64* %14
%68 = load i64, i64* %13
%69 = mul i64 %68, 2
store i64 %69, i64* %13
br label %26
70: ; preds = %60
%71 = load i32, i32* %15
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %70
br label %140
74: ; preds = %70
br label %75
75: ; preds = %74
%76 = load i8*, i8** %12
%77 = bitcast i8* %76 to %struct.nlmsghdr*
store %struct.nlmsghdr* %77, %struct.nlmsghdr** %9
br label %78
78: ; preds = %132, %75
%79 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%80 = load i32, i32* %15
%81 = call i64 @NLMSG_OK(%struct.nlmsghdr* %79, i32 %80)
%82 = icmp ne i64 %81, 0
br i1 %82, label %83, label %137
83: ; preds = %78
%84 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%85 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %84, i32 0, i32 0
%86 = load i64, i64* %85
%87 = load i64, i64* @NLMSG_DONE
%88 = icmp eq i64 %86, %87
br i1 %88, label %95, label %89
89: ; preds = %83
%90 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%91 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %90, i32 0, i32 0
%92 = load i64, i64* %91
%93 = load i64, i64* @NLMSG_ERROR
%94 = icmp eq i64 %92, %93
br i1 %94, label %95, label %98
95: ; preds = %89, %83
%96 = load i32, i32* @LOG_ERR
%97 = call i32 @dprintf(i32 %96, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %141
98: ; preds = %89
%99 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%100 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %99, i32 0, i32 1
%101 = load i64, i64* %100
%102 = call i64 (...) @getpid()
%103 = icmp ne i64 %101, %102
br i1 %103, label %110, label %104
104: ; preds = %98
%105 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%106 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %105, i32 0, i32 2
%107 = load i32, i32* %106
%108 = load i32, i32* %7
%109 = icmp ne i32 %107, %108
br i1 %109, label %110, label %111
110: ; preds = %104, %98
br label %132
111: ; preds = %104
%112 = load i32, i32* %6
%113 = load i32, i32* @RTM_NEWROUTE
%114 = icmp eq i32 %112, %113
br i1 %114, label %115, label %121
115: ; preds = %111
%116 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%117 = load i32, i32* %15
%118 = load i32, i32* %6
%119 = load %struct.dhcp6_if*, %struct.dhcp6_if** %8
%120 = call i32 @get_if_prefix(%struct.nlmsghdr* %116, i32 %117, i32 %118, %struct.dhcp6_if* %119)
br label %121
121: ; preds = %115, %111
%122 = load i32, i32* %6
%123 = load i32, i32* @RTM_NEWLINK
%124 = icmp eq i32 %122, %123
br i1 %124, label %125, label %131
125: ; preds = %121
%126 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%127 = load i32, i32* %15
%128 = load i32, i32* %6
%129 = load %struct.dhcp6_if*, %struct.dhcp6_if** %8
%130 = call i32 @get_if_flags(%struct.nlmsghdr* %126, i32 %127, i32 %128, %struct.dhcp6_if* %129)
br label %131
131: ; preds = %125, %121
br label %132
132: ; preds = %131, %110
%133 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%134 = load i32, i32* %15
%135 = call i64 @NLMSG_NEXT(%struct.nlmsghdr* %133, i32 %134)
%136 = inttoptr i64 %135 to %struct.nlmsghdr*
store %struct.nlmsghdr* %136, %struct.nlmsghdr** %9
br label %78
137: ; preds = %78
%138 = load i8*, i8** %12
%139 = call i32 @free(i8* %138)
store i8* null, i8** %12
br label %26
140: ; preds = %73, %32
br label %141
141: ; preds = %140, %95
%142 = load i8*, i8** %12
%143 = icmp ne i8* %142, null
br i1 %143, label %144, label %147
144: ; preds = %141
%145 = load i8*, i8** %12
%146 = call i32 @free(i8* %145)
br label %147
147: ; preds = %144, %141
%148 = load i32, i32* %15
ret i32 %148
}

LLVM IR (-O2):
%struct.dhcp6_if = type { i32 }
%struct.msghdr = type { i32, i32, i32, %struct.iovec*, i8* }
%struct.iovec = type { i8*, i64 }
%struct.sockaddr_nl = type { i32 }
%struct.nlmsghdr = type { i64, i64, i32 }
@LOG_DEBUG = global i32 0
@.str = [29 x i8] c"netlink_recv_rtgenmsg called\00"
@errno = global i64 0
@EINTR = global i64 0
@MSG_TRUNC = global i32 0
@NLMSG_DONE = global i64 0
@NLMSG_ERROR = global i64 0
@LOG_ERR = global i32 0
@.str.1 = [28 x i8] c"netlink_recv_rtgenmsg error\00"
@RTM_NEWROUTE = global i32 0
@RTM_NEWLINK = global i32 0
define i32 @netlink_recv_rtgenmsg(i32 %0, i32 %1, i32 %2, %struct.dhcp6_if* %3) {
%5 = alloca %struct.msghdr
%6 = alloca %struct.sockaddr_nl
%7 = alloca %struct.iovec
%8 = bitcast %struct.msghdr* %5 to i8*
%9 = bitcast %struct.sockaddr_nl* %6 to i8*
%10 = load i32, i32* @LOG_DEBUG
%11 = tail call i32 @dprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %2, 0
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = tail call i64 @time(i32* null)
%15 = trunc i64 %14 to i32
br label %16
16: ; preds = %13, %4
%17 = phi i32 [ %15, %13 ], [ %2, %4 ]
%18 = call dereferenceable_or_null(65536) i8* @malloc(i64 65536)
%19 = icmp eq i8* %18, null
br i1 %19, label %104, label %20
20: ; preds = %16
%21 = bitcast %struct.iovec* %7 to i8*
%22 = getelementptr inbounds %struct.iovec, %struct.iovec* %7, i64 0, i32 0
%23 = getelementptr inbounds %struct.iovec, %struct.iovec* %7, i64 0, i32 1
%24 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 4
%25 = bitcast i8** %24 to %struct.sockaddr_nl**
%26 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 0
%27 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 3
%28 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 1
%29 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 2
br label %30
30: ; preds = %20, %93
%31 = phi i8* [ %18, %20 ], [ %96, %93 ]
%32 = phi i64 [ 65536, %20 ], [ %95, %93 ]
br label %33
33: ; preds = %30, %33
store i8* %31, i8** %22
store i64 %32, i64* %23
%34 = call i32 @memset(%struct.msghdr* %5, i32 0, i32 32)
store %struct.sockaddr_nl* %6, %struct.sockaddr_nl** %25
store i32 4, i32* %26
store %struct.iovec* %7, %struct.iovec** %27
store i32 1, i32* %28
%35 = call i32 @recvmsg(i32 %0, %struct.msghdr* %5, i32 0)
%36 = icmp slt i32 %35, 0
%37 = load i64, i64* @errno
%38 = load i64, i64* @EINTR
%39 = icmp eq i64 %37, %38
%40 = select i1 %36, i1 %39, i1 false
br i1 %40, label %33, label %41
41: ; preds = %33
br i1 %36, label %47, label %42
42: ; preds = %41
%43 = load i32, i32* %29
%44 = load i32, i32* @MSG_TRUNC
%45 = and i32 %44, %43
%46 = icmp eq i32 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %42, %41
%48 = shl i64 %32, 1
br label %93
49: ; preds = %42
%50 = icmp eq i32 %35, 0
br i1 %50, label %98, label %51
51: ; preds = %49
%52 = bitcast i8* %31 to %struct.nlmsghdr*
%53 = call i64 @NLMSG_OK(%struct.nlmsghdr* %52, i32 %35)
%54 = icmp eq i64 %53, 0
br i1 %54, label %91, label %55
55: ; preds = %51, %86
%56 = phi %struct.nlmsghdr* [ %88, %86 ], [ %52, %51 ]
%57 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %56, i64 0, i32 0
%58 = load i64, i64* %57
%59 = load i64, i64* @NLMSG_DONE
%60 = icmp eq i64 %58, %59
%61 = load i64, i64* @NLMSG_ERROR
%62 = icmp eq i64 %58, %61
%63 = select i1 %60, i1 true, i1 %62
br i1 %63, label %64, label %67
64: ; preds = %55
%65 = load i32, i32* @LOG_ERR
%66 = call i32 @dprintf(i32 %65, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %98
67: ; preds = %55
%68 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %56, i64 0, i32 1
%69 = load i64, i64* %68
%70 = call i64 (...) @getpid()
%71 = icmp eq i64 %69, %70
br i1 %71, label %72, label %86
72: ; preds = %67
%73 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %56, i64 0, i32 2
%74 = load i32, i32* %73
%75 = icmp eq i32 %74, %17
br i1 %75, label %76, label %86
76: ; preds = %72
%77 = load i32, i32* @RTM_NEWROUTE
%78 = icmp eq i32 %77, %1
br i1 %78, label %79, label %81
79: ; preds = %76
%80 = call i32 @get_if_prefix(%struct.nlmsghdr* %56, i32 %35, i32 %1, %struct.dhcp6_if* %3)
br label %81
81: ; preds = %79, %76
%82 = load i32, i32* @RTM_NEWLINK
%83 = icmp eq i32 %82, %1
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = call i32 @get_if_flags(%struct.nlmsghdr* %56, i32 %35, i32 %1, %struct.dhcp6_if* %3)
br label %86
86: ; preds = %81, %84, %67, %72
%87 = call i64 @NLMSG_NEXT(%struct.nlmsghdr* %56, i32 %35)
%88 = inttoptr i64 %87 to %struct.nlmsghdr*
%89 = call i64 @NLMSG_OK(%struct.nlmsghdr* %88, i32 %35)
%90 = icmp eq i64 %89, 0
br i1 %90, label %91, label %55
91: ; preds = %86, %51
%92 = call i32 @free(i8* %31)
br label %93
93: ; preds = %91, %47
%94 = phi i8* [ %31, %47 ], [ null, %91 ]
%95 = phi i64 [ %48, %47 ], [ %32, %91 ]
%96 = call i8* @realloc(i8* %94, i64 %95)
%97 = icmp eq i8* %96, null
br i1 %97, label %98, label %30
98: ; preds = %49, %93, %64
%99 = phi i8* [ %31, %64 ], [ %31, %49 ], [ %94, %93 ]
%100 = phi i32 [ %35, %64 ], [ 0, %49 ], [ -1, %93 ]
%101 = icmp eq i8* %99, null
br i1 %101, label %104, label %102
102: ; preds = %98
%103 = call i32 @free(i8* %99)
br label %104
104: ; preds = %16, %98, %102
%105 = phi i32 [ %100, %98 ], [ %100, %102 ], [ -1, %16 ]
ret i32 %105
}