#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 sockaddr {
  int dummy;
};
struct ifaddrs {
  struct ifaddrs *ifa_next;
  scalar_t__ ifa_addr;
};

/* Variables and functions */
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
scalar_t__ getifaddrs(struct ifaddrs **);
scalar_t__ sacmp(scalar_t__, struct sockaddr const *);
int check_local_ip(const struct sockaddr *saddr) {
  struct ifaddrs *addrs, *a;
  if (getifaddrs(&addrs) < 0)
    return -1;
  a = addrs;
  while (a) {
    if (a->ifa_addr && sacmp(a->ifa_addr, saddr)) {
      freeifaddrs(addrs);
      return 1;
    }
    a = a->ifa_next;
  }
  freeifaddrs(addrs);
  return 0;
}


x86 assembly (clang, -O0):
<check_local_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <getifaddrs@plt>
cmp    $0x0,%rax
jge    115b <check_local_ip+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cd <check_local_ip+0x9d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11bd <check_local_ip+0x8d>
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11ad <check_local_ip+0x7d>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <sacmp@plt>
cmp    $0x0,%rax
je     11ad <check_local_ip+0x7d>
mov    -0x18(%rbp),%rdi
call   1050 <freeifaddrs@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cd <check_local_ip+0x9d>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1163 <check_local_ip+0x33>
mov    -0x18(%rbp),%rdi
call   1050 <freeifaddrs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_local_ip>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
lea    0x8(%rsp),%rdi
call   1040 <getifaddrs@plt>
test   %rax,%rax
js     1190 <check_local_ip+0x60>
mov    0x8(%rsp),%rbx
xor    %r14d,%r14d
test   %rbx,%rbx
jne    1168 <check_local_ip+0x38>
xor    %edi,%edi
jmp    1189 <check_local_ip+0x59>
nopl   0x0(%rax)
mov    (%rbx),%rbx
test   %rbx,%rbx
je     1184 <check_local_ip+0x54>
mov    0x8(%rbx),%rdi
test   %rdi,%rdi
je     1160 <check_local_ip+0x30>
mov    %r15,%rsi
call   1030 <sacmp@plt>
test   %rax,%rax
je     1160 <check_local_ip+0x30>
mov    $0x1,%r14d
mov    0x8(%rsp),%rdi
call   1050 <freeifaddrs@plt>
jmp    1196 <check_local_ip+0x66>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.ifaddrs = type { %struct.ifaddrs*, i64 }
define i32 @check_local_ip(%struct.sockaddr* %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr*
%4 = alloca %struct.ifaddrs*
%5 = alloca %struct.ifaddrs*
store %struct.sockaddr* %0, %struct.sockaddr** %3
%6 = call i64 @getifaddrs(%struct.ifaddrs** %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %36
9: ; preds = %1
%10 = load %struct.ifaddrs*, %struct.ifaddrs** %4
store %struct.ifaddrs* %10, %struct.ifaddrs** %5
br label %11
11: ; preds = %29, %9
%12 = load %struct.ifaddrs*, %struct.ifaddrs** %5
%13 = icmp ne %struct.ifaddrs* %12, null
br i1 %13, label %14, label %33
14: ; preds = %11
%15 = load %struct.ifaddrs*, %struct.ifaddrs** %5
%16 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %14
%20 = load %struct.ifaddrs*, %struct.ifaddrs** %5
%21 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %20, i32 0, i32 1
%22 = load i64, i64* %21
%23 = load %struct.sockaddr*, %struct.sockaddr** %3
%24 = call i64 @sacmp(i64 %22, %struct.sockaddr* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%28 = call i32 @freeifaddrs(%struct.ifaddrs* %27)
store i32 1, i32* %2
br label %36
29: ; preds = %19, %14
%30 = load %struct.ifaddrs*, %struct.ifaddrs** %5
%31 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %30, i32 0, i32 0
%32 = load %struct.ifaddrs*, %struct.ifaddrs** %31
store %struct.ifaddrs* %32, %struct.ifaddrs** %5
br label %11
33: ; preds = %11
%34 = load %struct.ifaddrs*, %struct.ifaddrs** %4
%35 = call i32 @freeifaddrs(%struct.ifaddrs* %34)
store i32 0, i32* %2
br label %36
36: ; preds = %33, %26, %8
%37 = load i32, i32* %2
ret i32 %37
}

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