#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_2__ TYPE_1__;

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct TYPE_2__ {
  int /*<<< orphan*/ sa_family;
};
struct ifreq {
  char *ifr_name;
  TYPE_1__ ifr_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int IFNAMSIZ;
int /*<<< orphan*/ SIOCGIFADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
char *find_wifi_interface();
int /*<<< orphan*/ free(char *);
char const *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
const char *get_iface_addr(void) {
  struct ifreq ifr;
  int fd;
  char *iface_name;
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  ifr.ifr_addr.sa_family = AF_INET;
  iface_name = find_wifi_interface();
  if (iface_name != NULL) {
    strncpy(ifr.ifr_name, "virbr0", IFNAMSIZ - 1);
    free(iface_name);
    iface_name = NULL;
  }
  ifr.ifr_name[IFNAMSIZ - 1] = '\0';
  ioctl(fd, SIOCGIFADDR, &ifr);
  close(fd);
  return inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
}


x86 assembly (clang, -O0):
<get_iface_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1080 <find_wifi_interface@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e3 <get_iface_addr+0x73>
mov    -0x10(%rbp),%rdi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
lea    0xe33(%rip),%rsi
call   1040 <strncpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2dda(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <inet_ntoa@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_iface_addr>:
push   %rax
mov    0x2eb0(%rip),%rax
mov    (%rax),%edi
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
xor    %eax,%eax
call   1040 <find_wifi_interface@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
add    $0xffffffff,%edx
lea    0xe9c(%rip),%rsi
call   1030 <strncpy@plt>

LLVM IR (-O0):
%struct.ifreq = type { i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"virbr0\00"
@IFNAMSIZ = global i32 0
@SIOCGIFADDR = global i32 0
define i8* @get_iface_addr() {
%1 = alloca %struct.ifreq
%2 = alloca i32
%3 = alloca i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %2
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i32 0, i32 1
%9 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %8, i32 0, i32 0
store i32 %7, i32* %9
%10 = call i8* (...) @find_wifi_interface()
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %21
13: ; preds = %0
%14 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = load i32, i32* @IFNAMSIZ
%17 = sub nsw i32 %16, 1
%18 = call i32 @strncpy(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
store i8* null, i8** %3
br label %21
21: ; preds = %13, %0
%22 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = load i32, i32* @IFNAMSIZ
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 0, i8* %27
%28 = load i32, i32* %2
%29 = load i32, i32* @SIOCGIFADDR
%30 = call i32 @ioctl(i32 %28, i32 %29, %struct.ifreq* %1)
%31 = load i32, i32* %2
%32 = call i32 @close(i32 %31)
%33 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i32 0, i32 1
%34 = bitcast %struct.TYPE_2__* %33 to %struct.sockaddr_in*
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i8* @inet_ntoa(i32 %36)
ret i8* %37
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"virbr0\00"
@IFNAMSIZ = global i32 0
@SIOCGIFADDR = global i32 0
define i8* @get_iface_addr() {
%1 = load i32, i32* @AF_INET
%2 = load i32, i32* @SOCK_DGRAM
%3 = tail call i32 @socket(i32 %1, i32 %2, i32 0)
%4 = tail call i8* (...) @find_wifi_interface()
%5 = icmp ne i8* %4, null
%6 = load i32, i32* @IFNAMSIZ
%7 = add nsw i32 %6, -1
%8 = tail call i32 @strncpy(i8* undef, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %7)
unreachable
}