#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 */
typedef struct TYPE_6__ TYPE_3__;
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint32_t;
struct TYPE_5__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_2__ sin_addr;
};
struct TYPE_4__ {
  scalar_t__ ifu_broadaddr;
};
struct ifaddrs {
  TYPE_1__ ifa_ifu;
  int /*<<< orphan*/ ifa_name;
  TYPE_3__ *ifa_addr;
  struct ifaddrs *ifa_next;
};
struct TYPE_6__ {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int /*<<< orphan*/ getifaddrs(struct ifaddrs **);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
uint32_t getipv4bcast(char *intname) {
  struct ifaddrs *ifap, *ifa;
  struct sockaddr_in *sa;
  uint32_t rval = 0;
  getifaddrs(&ifap);
  for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
    if ((ifa->ifa_addr->sa_family == AF_INET) &&
        !(strcmp(ifa->ifa_name, intname))) {
      sa = (struct sockaddr_in *)(ifa->ifa_ifu.ifu_broadaddr);
      rval = sa->sin_addr.s_addr;
    }
  }
  freeifaddrs(ifap);
  return (htonl(rval));
}


x86 assembly (clang, -O0):
<getipv4bcast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <getifaddrs@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cd <getipv4bcast+0x8d>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
jne    11b7 <getipv4bcast+0x77>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x8(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11b7 <getipv4bcast+0x77>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    11bc <getipv4bcast+0x7c>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1164 <getipv4bcast+0x24>
mov    -0x10(%rbp),%rdi
call   1060 <freeifaddrs@plt>
mov    -0x24(%rbp),%edi
call   1030 <htonl@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getipv4bcast>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1050 <getifaddrs@plt>
mov    (%rsp),%rbp
test   %rbp,%rbp
je     11a3 <getipv4bcast+0x63>
mov    0x2e86(%rip),%r15
mov    (%r15),%rcx
xor    %r14d,%r14d
jmp    1179 <getipv4bcast+0x39>
nopw   0x0(%rax,%rax,1)
mov    0x18(%rbp),%rbp
test   %rbp,%rbp
je     119d <getipv4bcast+0x5d>
mov    0x10(%rbp),%rax
cmp    %rcx,(%rax)
jne    1170 <getipv4bcast+0x30>
mov    0x8(%rbp),%edi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
mov    (%r15),%rcx
test   %eax,%eax
jne    1170 <getipv4bcast+0x30>
mov    0x0(%rbp),%rax
mov    (%rax),%r14d
jmp    1170 <getipv4bcast+0x30>
mov    (%rsp),%rdi
jmp    11a8 <getipv4bcast+0x68>
xor    %edi,%edi
xor    %r14d,%r14d
call   1060 <freeifaddrs@plt>
mov    %r14d,%edi
call   1030 <htonl@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifaddrs = type { %struct.TYPE_4__, i32, %struct.TYPE_6__*, %struct.ifaddrs* }
%struct.TYPE_4__ = type { i64 }
%struct.TYPE_6__ = type { i64 }
%struct.sockaddr_in = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i32 }
@AF_INET = global i64 0
define i32 @getipv4bcast(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.ifaddrs*
%4 = alloca %struct.ifaddrs*
%5 = alloca %struct.sockaddr_in*
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %6
%7 = call i32 @getifaddrs(%struct.ifaddrs** %3)
%8 = load %struct.ifaddrs*, %struct.ifaddrs** %3
store %struct.ifaddrs* %8, %struct.ifaddrs** %4
br label %9
9: ; preds = %38, %1
%10 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%11 = icmp ne %struct.ifaddrs* %10, null
br i1 %11, label %12, label %42
12: ; preds = %9
%13 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%14 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %13, i32 0, i32 2
%15 = load %struct.TYPE_6__*, %struct.TYPE_6__** %14
%16 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* @AF_INET
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %37
20: ; preds = %12
%21 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%22 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = load i8*, i8** %2
%25 = call i32 @strcmp(i32 %23, i8* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %37, label %27
27: ; preds = %20
%28 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%29 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %28, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %29, i32 0, i32 0
%31 = load i64, i64* %30
%32 = inttoptr i64 %31 to %struct.sockaddr_in*
store %struct.sockaddr_in* %32, %struct.sockaddr_in** %5
%33 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %33, i32 0, i32 0
%35 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %34, i32 0, i32 0
%36 = load i32, i32* %35
store i32 %36, i32* %6
br label %37
37: ; preds = %27, %20, %12
br label %38
38: ; preds = %37
%39 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%40 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %39, i32 0, i32 3
%41 = load %struct.ifaddrs*, %struct.ifaddrs** %40
store %struct.ifaddrs* %41, %struct.ifaddrs** %4
br label %9
42: ; preds = %9
%43 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%44 = call i32 @freeifaddrs(%struct.ifaddrs* %43)
%45 = load i32, i32* %6
%46 = call i32 @htonl(i32 %45)
ret i32 %46
}

LLVM IR (-O2):
%struct.ifaddrs = type { %struct.TYPE_4__, i32, %struct.TYPE_6__*, %struct.ifaddrs* }
%struct.TYPE_4__ = type { i64 }
%struct.TYPE_6__ = type { i64 }
%struct.sockaddr_in = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i32 }
@AF_INET = global i64 0
define i32 @getipv4bcast(i8* %0) {
%2 = alloca %struct.ifaddrs*
%3 = bitcast %struct.ifaddrs** %2 to i8*
%4 = call i32 @getifaddrs(%struct.ifaddrs** %2)
%5 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%6 = icmp eq %struct.ifaddrs* %5, null
br i1 %6, label %38, label %7
7: ; preds = %1
%8 = load i64, i64* @AF_INET
br label %9
9: ; preds = %7, %30
%10 = phi i64 [ %31, %30 ], [ %8, %7 ]
%11 = phi %struct.ifaddrs* [ %34, %30 ], [ %5, %7 ]
%12 = phi i32 [ %32, %30 ], [ 0, %7 ]
%13 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %11, i64 0, i32 2
%14 = load %struct.TYPE_6__*, %struct.TYPE_6__** %13
%15 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %14, i64 0, i32 0
%16 = load i64, i64* %15
%17 = icmp eq i64 %16, %10
br i1 %17, label %18, label %30
18: ; preds = %9
%19 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %11, i64 0, i32 1
%20 = load i32, i32* %19
%21 = call i32 @strcmp(i32 %20, i8* %0)
%22 = icmp eq i32 %21, 0
%23 = load i64, i64* @AF_INET
br i1 %22, label %24, label %30
24: ; preds = %18
%25 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %11, i64 0, i32 0, i32 0
%26 = load i64, i64* %25
%27 = inttoptr i64 %26 to %struct.sockaddr_in*
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %27, i64 0, i32 0, i32 0
%29 = load i32, i32* %28
br label %30
30: ; preds = %9, %18, %24
%31 = phi i64 [ %23, %18 ], [ %23, %24 ], [ %10, %9 ]
%32 = phi i32 [ %12, %18 ], [ %29, %24 ], [ %12, %9 ]
%33 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %11, i64 0, i32 3
%34 = load %struct.ifaddrs*, %struct.ifaddrs** %33
%35 = icmp eq %struct.ifaddrs* %34, null
br i1 %35, label %36, label %9
36: ; preds = %30
%37 = load %struct.ifaddrs*, %struct.ifaddrs** %2
br label %38
38: ; preds = %36, %1
%39 = phi %struct.ifaddrs* [ null, %1 ], [ %37, %36 ]
%40 = phi i32 [ 0, %1 ], [ %32, %36 ]
%41 = call i32 @freeifaddrs(%struct.ifaddrs* %39)
%42 = call i32 @htonl(i32 %40)
ret i32 %42
}