#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 */
typedef scalar_t__ uint16_t;
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct ifaddrs {
  TYPE_1__ *ifa_addr;
  int /*<<< orphan*/ ifa_name;
  struct ifaddrs *ifa_next;
};
struct TYPE_2__ {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET6;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
scalar_t__ getifaddrs(struct ifaddrs **);
scalar_t__ const htons(int);
int /*<<< orphan*/ stderr;
scalar_t__ strstr(int /*<<< orphan*/, char *);
int get_sta(char *interface, struct sockaddr_in6 *sta) {
  int found = 0;
  struct ifaddrs *ifap0, *ifap;
  if (getifaddrs(&ifap0)) {
    fprintf(stderr, "[get_sta] getifaddrs error: %m\n");
  }
  for (ifap = ifap0; ifap; ifap = ifap->ifa_next) {
    if (strstr(ifap->ifa_name, interface)) {
      if (ifap->ifa_addr == NULL) {
        fprintf(stderr, "[get_sta] %s ifa_addr is NULL!!", interface);
        continue;
      }
      if (ifap->ifa_addr->sa_family == AF_INET6) {
        struct sockaddr_in6 *temp_sockaddr_in6 =
            (struct sockaddr_in6 *)(ifap->ifa_addr);
        if ((((__const uint16_t *)(&temp_sockaddr_in6->sin6_addr))[0] ==
                 htons(0x2001) &&
             ((__const uint16_t *)(&temp_sockaddr_in6->sin6_addr))[1] ==
                 htons(0x200) &&
             ((__const uint16_t *)(&temp_sockaddr_in6->sin6_addr))[2] == 0)) {
          found = 1;
          break;
        } else {
          continue;
        }
      } else {
        continue;
      }
    } else {
      continue;
    }
  }
  if (!found) {
    freeifaddrs(ifap0);
    return -1;
  } else {
    *sta = *((struct sockaddr_in6 *)ifap->ifa_addr);
  }
  freeifaddrs(ifap0);
  return 0;
}


x86 assembly (clang, -O0):
<get_sta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x28(%rbp),%rdi
call   1050 <getifaddrs@plt>
cmp    $0x0,%rax
je     1191 <get_sta+0x41>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1297 <get_sta+0x147>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x10(%rbp),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1281 <get_sta+0x131>
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11ec <get_sta+0x9c>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1286 <get_sta+0x136>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x2deb(%rip),%rcx
cmp    (%rcx),%rax
jne    127c <get_sta+0x12c>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    $0x2001,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jne    1277 <get_sta+0x127>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    $0x200,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
jne    1277 <get_sta+0x127>
mov    -0x38(%rbp),%rax
cmpq   $0x0,0x10(%rax)
jne    1277 <get_sta+0x127>
movl   $0x1,-0x1c(%rbp)
jmp    1297 <get_sta+0x147>
jmp    1286 <get_sta+0x136>
jmp    1286 <get_sta+0x136>
jmp    1286 <get_sta+0x136>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1199 <get_sta+0x49>
cmpl   $0x0,-0x1c(%rbp)
jne    12b6 <get_sta+0x166>
mov    -0x28(%rbp),%rdi
call   1060 <freeifaddrs@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d5 <get_sta+0x185>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rcx),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
call   1060 <freeifaddrs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sta>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1050 <getifaddrs@plt>
test   %rax,%rax
je     118a <get_sta+0x3a>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x8(%rsp),%rbp
mov    $0xffffffff,%r15d
test   %rbp,%rbp
je     124d <get_sta+0xfd>
mov    %r14,0x10(%rsp)
lea    0xe76(%rip),%r12
mov    0x2e37(%rip),%r14
jmp    11df <get_sta+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x10(%rbp),%rbp
test   %rbp,%rbp
je     1240 <get_sta+0xf0>
mov    0x8(%rbp),%edi
mov    %rbx,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11d6 <get_sta+0x86>
mov    0x0(%rbp),%r15
test   %r15,%r15
je     11c0 <get_sta+0x70>
mov    (%r15),%r13
cmp    (%r14),%r13
jne    11d6 <get_sta+0x86>
mov    $0x2001,%edi
call   1030 <htons@plt>
cmp    %rax,%r13
jne    11d6 <get_sta+0x86>
mov    0x8(%r15),%r13
mov    $0x200,%edi
call   1030 <htons@plt>
cmp    %rax,%r13
jne    11d6 <get_sta+0x86>
cmpq   $0x0,0x10(%r15)
jne    11d6 <get_sta+0x86>
mov    0x0(%rbp),%rax
mov    (%rax),%eax
mov    0x10(%rsp),%rcx
mov    %eax,(%rcx)
xor    %r15d,%r15d
mov    0x8(%rsp),%rdi
jmp    124f <get_sta+0xff>
mov    0x8(%rsp),%rdi
mov    $0xffffffff,%r15d
jmp    124f <get_sta+0xff>
xor    %edi,%edi
call   1060 <freeifaddrs@plt>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32 }
%struct.ifaddrs = type { %struct.TYPE_2__*, i32, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i64 }
@stderr = global i32 0
@.str = [32 x i8] c"[get_sta] getifaddrs error: %m\0A\00"
@.str.1 = [32 x i8] c"[get_sta] %s ifa_addr is NULL!!\00"
@AF_INET6 = global i64 0
define i32 @get_sta(i8* %0, %struct.sockaddr_in6* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.sockaddr_in6*
%6 = alloca i32
%7 = alloca %struct.ifaddrs*
%8 = alloca %struct.ifaddrs*
%9 = alloca %struct.sockaddr_in6*
store i8* %0, i8** %4
store %struct.sockaddr_in6* %1, %struct.sockaddr_in6** %5
store i32 0, i32* %6
%10 = call i64 @getifaddrs(%struct.ifaddrs** %7)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %12, %2
%16 = load %struct.ifaddrs*, %struct.ifaddrs** %7
store %struct.ifaddrs* %16, %struct.ifaddrs** %8
br label %17
17: ; preds = %75, %15
%18 = load %struct.ifaddrs*, %struct.ifaddrs** %8
%19 = icmp ne %struct.ifaddrs* %18, null
br i1 %19, label %20, label %79
20: ; preds = %17
%21 = load %struct.ifaddrs*, %struct.ifaddrs** %8
%22 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = load i8*, i8** %4
%25 = call i64 @strstr(i32 %23, i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %74
27: ; preds = %20
%28 = load %struct.ifaddrs*, %struct.ifaddrs** %8
%29 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %28, i32 0, i32 0
%30 = load %struct.TYPE_2__*, %struct.TYPE_2__** %29
%31 = icmp eq %struct.TYPE_2__* %30, null
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %4
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %34)
br label %75
36: ; preds = %27
%37 = load %struct.ifaddrs*, %struct.ifaddrs** %8
%38 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %37, i32 0, i32 0
%39 = load %struct.TYPE_2__*, %struct.TYPE_2__** %38
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
%41 = load i64, i64* %40
%42 = load i64, i64* @AF_INET6
%43 = icmp eq i64 %41, %42
br i1 %43, label %44, label %73
44: ; preds = %36
%45 = load %struct.ifaddrs*, %struct.ifaddrs** %8
%46 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %45, i32 0, i32 0
%47 = load %struct.TYPE_2__*, %struct.TYPE_2__** %46
%48 = bitcast %struct.TYPE_2__* %47 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %48, %struct.sockaddr_in6** %9
%49 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%50 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %49, i32 0, i32 0
%51 = bitcast i32* %50 to i64*
%52 = getelementptr inbounds i64, i64* %51, i64 0
%53 = load i64, i64* %52
%54 = call i64 @htons(i32 8193)
%55 = icmp eq i64 %53, %54
br i1 %55, label %56, label %72
56: ; preds = %44
%57 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%58 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %57, i32 0, i32 0
%59 = bitcast i32* %58 to i64*
%60 = getelementptr inbounds i64, i64* %59, i64 1
%61 = load i64, i64* %60
%62 = call i64 @htons(i32 512)
%63 = icmp eq i64 %61, %62
br i1 %63, label %64, label %72
64: ; preds = %56
%65 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%66 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %65, i32 0, i32 0
%67 = bitcast i32* %66 to i64*
%68 = getelementptr inbounds i64, i64* %67, i64 2
%69 = load i64, i64* %68
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %64
store i32 1, i32* %6
br label %79
72: ; preds = %64, %56, %44
br label %75
73: ; preds = %36
br label %75
74: ; preds = %20
br label %75
75: ; preds = %74, %73, %72, %32
%76 = load %struct.ifaddrs*, %struct.ifaddrs** %8
%77 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %76, i32 0, i32 2
%78 = load %struct.ifaddrs*, %struct.ifaddrs** %77
store %struct.ifaddrs* %78, %struct.ifaddrs** %8
br label %17
79: ; preds = %71, %17
%80 = load i32, i32* %6
%81 = icmp ne i32 %80, 0
br i1 %81, label %85, label %82
82: ; preds = %79
%83 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%84 = call i32 @freeifaddrs(%struct.ifaddrs* %83)
store i32 -1, i32* %3
br label %96
85: ; preds = %79
%86 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %5
%87 = load %struct.ifaddrs*, %struct.ifaddrs** %8
%88 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %87, i32 0, i32 0
%89 = load %struct.TYPE_2__*, %struct.TYPE_2__** %88
%90 = bitcast %struct.TYPE_2__* %89 to %struct.sockaddr_in6*
%91 = bitcast %struct.sockaddr_in6* %86 to i8*
%92 = bitcast %struct.sockaddr_in6* %90 to i8*
br label %93
93: ; preds = %85
%94 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%95 = call i32 @freeifaddrs(%struct.ifaddrs* %94)
store i32 0, i32* %3
br label %96
96: ; preds = %93, %82
%97 = load i32, i32* %3
ret i32 %97
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32 }
%struct.ifaddrs = type { %struct.TYPE_2__*, i32, %struct.ifaddrs* }
%struct.TYPE_2__ = type { i64 }
@stderr = global i32 0
@.str = [32 x i8] c"[get_sta] getifaddrs error: %m\0A\00"
@.str.1 = [32 x i8] c"[get_sta] %s ifa_addr is NULL!!\00"
@AF_INET6 = global i64 0
define i32 @get_sta(i8* %0, %struct.sockaddr_in6* nocapture writeonly %1) {
%3 = alloca %struct.ifaddrs*
%4 = bitcast %struct.ifaddrs** %3 to i8*
%5 = call i64 @getifaddrs(%struct.ifaddrs** %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %2
%11 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%12 = icmp eq %struct.ifaddrs* %11, null
br i1 %12, label %55, label %13
13: ; preds = %10, %43
%14 = phi %struct.ifaddrs* [ %45, %43 ], [ %11, %10 ]
%15 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %14, i64 0, i32 1
%16 = load i32, i32* %15
%17 = call i64 @strstr(i32 %16, i8* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %43, label %19
19: ; preds = %13
%20 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %14, i64 0, i32 0
%21 = load %struct.TYPE_2__*, %struct.TYPE_2__** %20
%22 = icmp eq %struct.TYPE_2__* %21, null
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %43
26: ; preds = %19
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i64 0, i32 0
%28 = load i64, i64* %27
%29 = load i64, i64* @AF_INET6
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %43
31: ; preds = %26
%32 = call i64 @htons(i32 8193)
%33 = icmp eq i64 %28, %32
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i64 1, i32 0
%36 = load i64, i64* %35
%37 = call i64 @htons(i32 512)
%38 = icmp eq i64 %36, %37
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i64 2, i32 0
%41 = load i64, i64* %40
%42 = icmp eq i64 %41, 0
br i1 %42, label %49, label %43
43: ; preds = %39, %34, %31, %13, %26, %23
%44 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %14, i64 0, i32 2
%45 = load %struct.ifaddrs*, %struct.ifaddrs** %44
%46 = icmp eq %struct.ifaddrs* %45, null
br i1 %46, label %47, label %13
47: ; preds = %43
%48 = load %struct.ifaddrs*, %struct.ifaddrs** %3
br label %55
49: ; preds = %39
%50 = bitcast %struct.ifaddrs* %14 to i32**
%51 = load i32*, i32** %50
%52 = getelementptr %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i64 0, i32 0
%53 = load i32, i32* %51
store i32 %53, i32* %52
%54 = load %struct.ifaddrs*, %struct.ifaddrs** %3
br label %55
55: ; preds = %10, %47, %49
%56 = phi %struct.ifaddrs* [ %54, %49 ], [ %48, %47 ], [ null, %10 ]
%57 = phi i32 [ 0, %49 ], [ -1, %47 ], [ -1, %10 ]
%58 = call i32 @freeifaddrs(%struct.ifaddrs* %56)
ret i32 %57
}