#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 ifaddrs {
  int dummy;
};
struct ifaddrmsg {
  int /*<<< orphan*/ ifa_prefixlen;
  int /*<<< orphan*/ ifa_family;
  int /*<<< orphan*/ ifa_index;
};

/* Variables and functions */
scalar_t__ make_prefixes(struct ifaddrs *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
scalar_t__ set_addresses(struct ifaddrs *, struct ifaddrmsg *, void *, size_t);
scalar_t__ set_flags(struct ifaddrs *);
scalar_t__ set_ifname(struct ifaddrs *, int /*<<< orphan*/);
int populate_ifaddrs(struct ifaddrs *ifaddr, struct ifaddrmsg *msg, void *bytes,
                     size_t len) {
  if (set_ifname(ifaddr, msg->ifa_index) != 0) {
    return -1;
  }
  if (set_flags(ifaddr) != 0) {
    return -1;
  }
  if (set_addresses(ifaddr, msg, bytes, len) != 0) {
    return -1;
  }
  if (make_prefixes(ifaddr, msg->ifa_family, msg->ifa_prefixlen) != 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<populate_ifaddrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%esi
call   1060 <set_ifname@plt>
cmp    $0x0,%rax
je     117e <populate_ifaddrs+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <populate_ifaddrs+0xbb>
mov    -0x10(%rbp),%rdi
call   1030 <set_flags@plt>
cmp    $0x0,%rax
je     119d <populate_ifaddrs+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <populate_ifaddrs+0xbb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <set_addresses@plt>
cmp    $0x0,%rax
je     11c8 <populate_ifaddrs+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <populate_ifaddrs+0xbb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1040 <make_prefixes@plt>
cmp    $0x0,%rax
je     11f4 <populate_ifaddrs+0xb4>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <populate_ifaddrs+0xbb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<populate_ifaddrs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x8(%rsi),%esi
call   1060 <set_ifname@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    119d <populate_ifaddrs+0x5d>
mov    %rbx,%rdi
call   1030 <set_flags@plt>
test   %rax,%rax
jne    119d <populate_ifaddrs+0x5d>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   1050 <set_addresses@plt>
test   %rax,%rax
jne    119d <populate_ifaddrs+0x5d>
mov    (%r14),%edx
mov    0x4(%r14),%esi
mov    %rbx,%rdi
call   1040 <make_prefixes@plt>
neg    %rax
sbb    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifaddrs = type { i32 }
%struct.ifaddrmsg = type { i32, i32, i32 }
define i32 @populate_ifaddrs(%struct.ifaddrs* %0, %struct.ifaddrmsg* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca %struct.ifaddrs*
%7 = alloca %struct.ifaddrmsg*
%8 = alloca i8*
%9 = alloca i64
store %struct.ifaddrs* %0, %struct.ifaddrs** %6
store %struct.ifaddrmsg* %1, %struct.ifaddrmsg** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%10 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%11 = load %struct.ifaddrmsg*, %struct.ifaddrmsg** %7
%12 = getelementptr inbounds %struct.ifaddrmsg, %struct.ifaddrmsg* %11, i32 0, i32 2
%13 = load i32, i32* %12
%14 = call i64 @set_ifname(%struct.ifaddrs* %10, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -1, i32* %5
br label %42
17: ; preds = %4
%18 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%19 = call i64 @set_flags(%struct.ifaddrs* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %5
br label %42
22: ; preds = %17
%23 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%24 = load %struct.ifaddrmsg*, %struct.ifaddrmsg** %7
%25 = load i8*, i8** %8
%26 = load i64, i64* %9
%27 = call i64 @set_addresses(%struct.ifaddrs* %23, %struct.ifaddrmsg* %24, i8* %25, i64 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %22
store i32 -1, i32* %5
br label %42
30: ; preds = %22
%31 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%32 = load %struct.ifaddrmsg*, %struct.ifaddrmsg** %7
%33 = getelementptr inbounds %struct.ifaddrmsg, %struct.ifaddrmsg* %32, i32 0, i32 1
%34 = load i32, i32* %33
%35 = load %struct.ifaddrmsg*, %struct.ifaddrmsg** %7
%36 = getelementptr inbounds %struct.ifaddrmsg, %struct.ifaddrmsg* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i64 @make_prefixes(%struct.ifaddrs* %31, i32 %34, i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %30
store i32 -1, i32* %5
br label %42
41: ; preds = %30
store i32 0, i32* %5
br label %42
42: ; preds = %41, %40, %29, %21, %16
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
%struct.ifaddrs = type { i32 }
%struct.ifaddrmsg = type { i32, i32, i32 }
define i32 @populate_ifaddrs(%struct.ifaddrs* %0, %struct.ifaddrmsg* %1, i8* %2, i64 %3) {
%5 = getelementptr inbounds %struct.ifaddrmsg, %struct.ifaddrmsg* %1, i64 0, i32 2
%6 = load i32, i32* %5
%7 = tail call i64 @set_ifname(%struct.ifaddrs* %0, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %4
%10 = tail call i64 @set_flags(%struct.ifaddrs* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = tail call i64 @set_addresses(%struct.ifaddrs* %0, %struct.ifaddrmsg* %1, i8* %2, i64 %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = getelementptr inbounds %struct.ifaddrmsg, %struct.ifaddrmsg* %1, i64 0, i32 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.ifaddrmsg, %struct.ifaddrmsg* %1, i64 0, i32 0
%19 = load i32, i32* %18
%20 = tail call i64 @make_prefixes(%struct.ifaddrs* %0, i32 %17, i32 %19)
%21 = icmp ne i64 %20, 0
%22 = sext i1 %21 to i32
br label %23
23: ; preds = %15, %12, %9, %4
%24 = phi i32 [ -1, %4 ], [ -1, %9 ], [ -1, %12 ], [ %22, %15 ]
ret i32 %24
}