#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ const s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct ifaddrs {
  TYPE_2__ *ifa_addr;
  int /*<<< orphan*/ ifa_name;
  struct ifaddrs *ifa_next;
};
typedef int /*<<< orphan*/ const in_addr_t;
struct TYPE_4__ {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
scalar_t__ getifaddrs(struct ifaddrs **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(int /*<<< orphan*/, char *);
in_addr_t jb_get_wsl_public_ip() {
  struct ifaddrs *ifaddrs_p_base;
  if (getifaddrs(&ifaddrs_p_base) != 0) {
    perror("getifaddrs failed");
    exit(-1);
  }
  for (struct ifaddrs *ifaddrs_p = ifaddrs_p_base; ifaddrs_p != NULL;
       ifaddrs_p = ifaddrs_p->ifa_next) {
    if ((ifaddrs_p->ifa_addr->sa_family != AF_INET) ||
        ((strcmp(ifaddrs_p->ifa_name, "eth0") != 0))) {
      continue;
    }
    const struct sockaddr_in *in_addr =
        (struct sockaddr_in *)ifaddrs_p->ifa_addr;
    const in_addr_t result = in_addr->sin_addr.s_addr;
    freeifaddrs(ifaddrs_p_base);
    return result;
  }
  freeifaddrs(ifaddrs_p_base);
  fprintf(stderr, "No interface %s found", "eth0");
  exit(-1);
}


x86 assembly (clang, -O0):
<jb_get_wsl_public_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
call   1050 <getifaddrs@plt>
cmp    $0x0,%rax
je     1191 <jb_get_wsl_public_ip+0x31>
lea    0xe7e(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1217 <jb_get_wsl_public_ip+0xb7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
jne    11db <jb_get_wsl_public_ip+0x7b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
lea    0xe46(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     11e0 <jb_get_wsl_public_ip+0x80>
jmp    1206 <jb_get_wsl_public_ip+0xa6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <freeifaddrs@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    1199 <jb_get_wsl_public_ip+0x39>
mov    -0x8(%rbp),%rdi
call   1060 <freeifaddrs@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
lea    0xddb(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<jb_get_wsl_public_ip>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <getifaddrs@plt>
test   %rax,%rax
jne    1211 <jb_get_wsl_public_ip+0xb1>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     1227 <jb_get_wsl_public_ip+0xc7>
mov    0x2e57(%rip),%r15
mov    (%r15),%rax
lea    0xe77(%rip),%r14
jmp    11a9 <jb_get_wsl_public_ip+0x49>
nopl   (%rax)
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     11e1 <jb_get_wsl_public_ip+0x81>
mov    (%rbx),%rcx
cmp    %rax,(%rcx)
jne    11a0 <jb_get_wsl_public_ip+0x40>
mov    0x8(%rbx),%edi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11c6 <jb_get_wsl_public_ip+0x66>
mov    (%r15),%rax
jmp    11a0 <jb_get_wsl_public_ip+0x40>
mov    (%rbx),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1060 <freeifaddrs@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x8(%rsp),%rdi
call   1060 <freeifaddrs@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
lea    0xe10(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xde8(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
xor    %edi,%edi
jmp    11e6 <jb_get_wsl_public_ip+0x86>

LLVM IR (-O0):
%struct.ifaddrs = type { %struct.TYPE_4__*, i32, %struct.ifaddrs* }
%struct.TYPE_4__ = type { i64 }
%struct.sockaddr_in = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
@.str = [18 x i8] c"getifaddrs failed\00"
@AF_INET = global i64 0
@.str.1 = [5 x i8] c"eth0\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"No interface %s found\00"
define i32 @jb_get_wsl_public_ip() {
%1 = alloca %struct.ifaddrs*
%2 = alloca %struct.ifaddrs*
%3 = alloca %struct.sockaddr_in*
%4 = alloca i32
%5 = call i64 @getifaddrs(%struct.ifaddrs** %1)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
%11 = load %struct.ifaddrs*, %struct.ifaddrs** %1
store %struct.ifaddrs* %11, %struct.ifaddrs** %2
br label %12
12: ; preds = %42, %10
%13 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%14 = icmp ne %struct.ifaddrs* %13, null
br i1 %14, label %15, label %46
15: ; preds = %12
%16 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%17 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %16, i32 0, i32 0
%18 = load %struct.TYPE_4__*, %struct.TYPE_4__** %17
%19 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %18, i32 0, i32 0
%20 = load i64, i64* %19
%21 = load i64, i64* @AF_INET
%22 = icmp ne i64 %20, %21
br i1 %22, label %29, label %23
23: ; preds = %15
%24 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%25 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = call i64 @strcmp(i32 %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23, %15
br label %42
30: ; preds = %23
%31 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%32 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %31, i32 0, i32 0
%33 = load %struct.TYPE_4__*, %struct.TYPE_4__** %32
%34 = bitcast %struct.TYPE_4__* %33 to %struct.sockaddr_in*
store %struct.sockaddr_in* %34, %struct.sockaddr_in** %3
%35 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %35, i32 0, i32 0
%37 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %36, i32 0, i32 0
%38 = load i32, i32* %37
store i32 %38, i32* %4
%39 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%40 = call i32 @freeifaddrs(%struct.ifaddrs* %39)
%41 = load i32, i32* %4
ret i32 %41
42: ; preds = %29
%43 = load %struct.ifaddrs*, %struct.ifaddrs** %2
%44 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %43, i32 0, i32 2
%45 = load %struct.ifaddrs*, %struct.ifaddrs** %44
store %struct.ifaddrs* %45, %struct.ifaddrs** %2
br label %12
46: ; preds = %12
%47 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%48 = call i32 @freeifaddrs(%struct.ifaddrs* %47)
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%51 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
%struct.ifaddrs = type { %struct.TYPE_4__*, i32, %struct.ifaddrs* }
%struct.TYPE_4__ = type { i64 }
%struct.sockaddr_in = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
@.str = [18 x i8] c"getifaddrs failed\00"
@AF_INET = global i64 0
@.str.1 = [5 x i8] c"eth0\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"No interface %s found\00"
define i32 @jb_get_wsl_public_ip() {
%1 = alloca %struct.ifaddrs*
%2 = bitcast %struct.ifaddrs** %1 to i8*
%3 = call i64 @getifaddrs(%struct.ifaddrs** %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%7 = icmp eq %struct.ifaddrs* %6, null
br i1 %7, label %34, label %8
8: ; preds = %5
%9 = load i64, i64* @AF_INET
br label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %8, %27
%14 = phi i64 [ %28, %27 ], [ %9, %8 ]
%15 = phi %struct.ifaddrs* [ %30, %27 ], [ %6, %8 ]
%16 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %15, i64 0, i32 0
%17 = load %struct.TYPE_4__*, %struct.TYPE_4__** %16
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %17, i64 0, i32 0
%19 = load i64, i64* %18
%20 = icmp eq i64 %19, %14
br i1 %20, label %21, label %27
21: ; preds = %13
%22 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %15, i64 0, i32 1
%23 = load i32, i32* %22
%24 = call i64 @strcmp(i32 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
%26 = load i64, i64* @AF_INET
br i1 %25, label %40, label %27
27: ; preds = %13, %21
%28 = phi i64 [ %14, %13 ], [ %26, %21 ]
%29 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %15, i64 0, i32 2
%30 = load %struct.ifaddrs*, %struct.ifaddrs** %29
%31 = icmp eq %struct.ifaddrs* %30, null
br i1 %31, label %32, label %13
32: ; preds = %27
%33 = load %struct.ifaddrs*, %struct.ifaddrs** %1
br label %34
34: ; preds = %32, %5
%35 = phi %struct.ifaddrs* [ %33, %32 ], [ null, %5 ]
%36 = call i32 @freeifaddrs(%struct.ifaddrs* %35)
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %21
%41 = bitcast %struct.ifaddrs* %15 to %struct.sockaddr_in**
%42 = load %struct.sockaddr_in*, %struct.sockaddr_in** %41
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %42, i64 0, i32 0, i32 0
%44 = load i32, i32* %43
%45 = load %struct.ifaddrs*, %struct.ifaddrs** %1
%46 = call i32 @freeifaddrs(%struct.ifaddrs* %45)
ret i32 %44
}