#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 /*<<< orphan*/ ifa_name;
  int /*<<< orphan*/ *ifa_addr;
  struct ifaddrs *ifa_next;
};
typedef int /*<<< orphan*/ cinterface;

/* Variables and functions */
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int getifaddrs(struct ifaddrs **);
int /*<<< orphan*/ perror(char *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
void cfg_guess_interface(char *cinterface) {
  struct ifaddrs *ifaddr, *ifa;
  if (getifaddrs(&ifaddr) == -1) {
    perror("getifaddrs");
    return;
  }
  for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
    if (ifa->ifa_addr == NULL) {
      continue;
    }
    if (strcmp(ifa->ifa_name, "lo")) {
      strncpy(cinterface, ifa->ifa_name, sizeof(cinterface));
      break;
    }
  }
  freeifaddrs(ifaddr);
}


x86 assembly (clang, -O0):
<cfg_guess_interface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    117f <cfg_guess_interface+0x2f>
lea    0xe8b(%rip),%rdi
call   1070 <perror@plt>
jmp    11fa <cfg_guess_interface+0xaa>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f1 <cfg_guess_interface+0xa1>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11a6 <cfg_guess_interface+0x56>
jmp    11e0 <cfg_guess_interface+0x90>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11db <cfg_guess_interface+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    $0x8,%edx
call   1030 <strncpy@plt>
jmp    11f1 <cfg_guess_interface+0xa1>
jmp    11e0 <cfg_guess_interface+0x90>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1187 <cfg_guess_interface+0x37>
mov    -0x10(%rbp),%rdi
call   1060 <freeifaddrs@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfg_guess_interface>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
call   1050 <getifaddrs@plt>
cmp    $0xffffffff,%eax
je     11c2 <cfg_guess_interface+0x72>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     11ae <cfg_guess_interface+0x5e>
lea    0xe8f(%rip),%r15
jmp    1189 <cfg_guess_interface+0x39>
xchg   %ax,%ax
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     11ae <cfg_guess_interface+0x5e>
cmpq   $0x0,0x8(%rbx)
je     1180 <cfg_guess_interface+0x30>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1180 <cfg_guess_interface+0x30>
mov    (%rbx),%esi
mov    %r14,%rdi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    0x8(%rsp),%rdi
call   1060 <freeifaddrs@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe37(%rip),%rdi
call   1070 <perror@plt>
jmp    11b8 <cfg_guess_interface+0x68>

LLVM IR (-O0):
%struct.ifaddrs = type { i32, i32*, %struct.ifaddrs* }
@.str = [11 x i8] c"getifaddrs\00"
@.str.1 = [3 x i8] c"lo\00"
define void @cfg_guess_interface(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.ifaddrs*
%4 = alloca %struct.ifaddrs*
store i8* %0, i8** %2
%5 = call i32 @getifaddrs(%struct.ifaddrs** %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %40
9: ; preds = %1
%10 = load %struct.ifaddrs*, %struct.ifaddrs** %3
store %struct.ifaddrs* %10, %struct.ifaddrs** %4
br label %11
11: ; preds = %33, %9
%12 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%13 = icmp ne %struct.ifaddrs* %12, null
br i1 %13, label %14, label %37
14: ; preds = %11
%15 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%16 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %15, i32 0, i32 1
%17 = load i32*, i32** %16
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %14
br label %33
20: ; preds = %14
%21 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%22 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i64 @strcmp(i32 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i8*, i8** %2
%28 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%29 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @strncpy(i8* %27, i32 %30, i32 8)
br label %37
32: ; preds = %20
br label %33
33: ; preds = %32, %19
%34 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%35 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %34, i32 0, i32 2
%36 = load %struct.ifaddrs*, %struct.ifaddrs** %35
store %struct.ifaddrs* %36, %struct.ifaddrs** %4
br label %11
37: ; preds = %26, %11
%38 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%39 = call i32 @freeifaddrs(%struct.ifaddrs* %38)
br label %40
40: ; preds = %37, %7
ret void
}

LLVM IR (-O2):
%struct.ifaddrs = type { i32, i32*, %struct.ifaddrs* }
@.str = [11 x i8] c"getifaddrs\00"
@.str.1 = [3 x i8] c"lo\00"
define void @cfg_guess_interface(i8* %0) {
%2 = alloca %struct.ifaddrs*
%3 = bitcast %struct.ifaddrs** %2 to i8*
%4 = call i32 @getifaddrs(%struct.ifaddrs** %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%8 = icmp eq %struct.ifaddrs* %7, null
br i1 %8, label %29, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %32
11: ; preds = %6, %25
%12 = phi %struct.ifaddrs* [ %27, %25 ], [ %7, %6 ]
%13 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %12, i64 0, i32 1
%14 = load i32*, i32** %13
%15 = icmp eq i32* %14, null
br i1 %15, label %25, label %16
16: ; preds = %11
%17 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %12, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @strcmp(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %16
%22 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %12, i64 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @strncpy(i8* %0, i32 %23, i32 8)
br label %29
25: ; preds = %16, %11
%26 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %12, i64 0, i32 2
%27 = load %struct.ifaddrs*, %struct.ifaddrs** %26
%28 = icmp eq %struct.ifaddrs* %27, null
br i1 %28, label %29, label %11
29: ; preds = %25, %6, %21
%30 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%31 = call i32 @freeifaddrs(%struct.ifaddrs* %30)
br label %32
32: ; preds = %29, %9
ret void
}