#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 {
  scalar_t__ sa_family;
};
struct ifaddrs {
  char *ifa_name;
  struct sockaddr *ifa_addr;
  struct ifaddrs *ifa_next;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
scalar_t__ getifaddrs(struct ifaddrs **);
char *my_getnameinfo(struct sockaddr *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  struct ifaddrs *ifap;
  struct ifaddrs *cur;
  struct sockaddr *tmp;
  if (getifaddrs(&ifap)) {
    exit(1);
  }
  cur = ifap;
  if (ifap == NULL)
    exit(1);
  do {
    char *name = cur->ifa_name;
    char *address;
    tmp = cur->ifa_addr;
    if (tmp && (tmp->sa_family == AF_INET || tmp->sa_family == AF_INET6)) {
      if (argc < 2) {
        address = my_getnameinfo(tmp);
      } else {
        if (!strncmp(argv[1], "4", 1) && tmp->sa_family == AF_INET) {
          address = my_getnameinfo(tmp);
        } else if (!strncmp(argv[1], "6", 1) && tmp->sa_family == AF_INET6) {
          address = my_getnameinfo(tmp);
        } else {
          address = NULL;
        }
      }
    } else {
      address = NULL;
    }
    if (address != NULL) {
      printf("%s: %s\n", name, address);
    }
  } while (cur = cur->ifa_next);
  freeifaddrs(ifap);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <getifaddrs@plt>
cmp    $0x0,%rax
je     1193 <main+0x33>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b0 <main+0x50>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11b5 <main+0x55>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12ce <main+0x16e>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%rax
je     1205 <main+0xa5>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2de4(%rip),%rcx
cmp    (%rcx),%rax
jne    12ce <main+0x16e>
cmpl   $0x2,-0x8(%rbp)
jge    1221 <main+0xc1>
mov    -0x28(%rbp),%rdi
call   1050 <my_getnameinfo@plt>
mov    %rax,-0x38(%rbp)
jmp    12c9 <main+0x169>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd0(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    126c <main+0x10c>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2d97(%rip),%rcx
cmp    (%rcx),%rax
jne    126c <main+0x10c>
mov    -0x28(%rbp),%rdi
call   1050 <my_getnameinfo@plt>
mov    %rax,-0x38(%rbp)
jmp    12c4 <main+0x164>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd87(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12b7 <main+0x157>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2d44(%rip),%rcx
cmp    (%rcx),%rax
jne    12b7 <main+0x157>
mov    -0x28(%rbp),%rdi
call   1050 <my_getnameinfo@plt>
mov    %rax,-0x38(%rbp)
jmp    12bf <main+0x15f>
movq   $0x0,-0x38(%rbp)
jmp    12c4 <main+0x164>
jmp    12c9 <main+0x169>
jmp    12d6 <main+0x176>
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12f5 <main+0x195>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xd14(%rip),%rdi
call   1040 <printf@plt>
jmp    12fa <main+0x19a>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b5 <main+0x55>
mov    -0x18(%rbp),%rdi
call   1070 <freeifaddrs@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %edi,%ebp
mov    %rsp,%rdi
call   1060 <getifaddrs@plt>
test   %rax,%rax
jne    1186 <main+0x26>
mov    (%rsp),%r14
test   %r14,%r14
jne    1190 <main+0x30>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e51(%rip),%r15
jmp    11ad <main+0x4d>
nopl   0x0(%rax)
mov    0x10(%r14),%r14
test   %r14,%r14
je     1249 <main+0xe9>
mov    0x8(%r14),%r12
test   %r12,%r12
je     11a0 <main+0x40>
mov    (%r14),%rbx
mov    (%r12),%rax
cmp    (%r15),%rax
je     11ce <main+0x6e>
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%rax
jne    11a0 <main+0x40>
cmp    $0x2,%ebp
jge    11f4 <main+0x94>
mov    %r12,%rdi
call   1050 <my_getnameinfo@plt>
test   %rax,%rax
je     11a0 <main+0x40>
lea    0xe1d(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
jmp    11a0 <main+0x40>
mov    0x8(%r13),%rdi
lea    0xe01(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1216 <main+0xb6>
mov    (%r12),%rax
cmp    (%r15),%rax
je     11d3 <main+0x73>
mov    0x8(%r13),%rdi
lea    0xde1(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11a0 <main+0x40>
mov    (%r12),%rax
mov    0x2da2(%rip),%rcx
cmp    (%rcx),%rax
jne    11a0 <main+0x40>
jmp    11d3 <main+0x73>
mov    (%rsp),%rdi
call   1070 <freeifaddrs@plt>
xor    %edi,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
%struct.ifaddrs = type { i8*, %struct.sockaddr*, %struct.ifaddrs* }
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
@AF_INET6 = global i64 0
@.str = [2 x i8] c"4\00"
@.str.1 = [2 x i8] c"6\00"
@.str.2 = [8 x i8] c"%s: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %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 %9, label %7
7: ; preds = %2
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%11 = icmp eq %struct.ifaddrs* %10, null
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = icmp slt i32 %0, 2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
br label %17
15: ; preds = %9
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %12, %54
%18 = phi %struct.ifaddrs* [ %56, %54 ], [ %10, %12 ]
%19 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %18, i64 0, i32 0
%20 = load i8*, i8** %19
%21 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %18, i64 0, i32 1
%22 = load %struct.sockaddr*, %struct.sockaddr** %21
%23 = icmp eq %struct.sockaddr* %22, null
br i1 %23, label %54, label %24
24: ; preds = %17
%25 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %22, i64 0, i32 0
%26 = load i64, i64* %25
%27 = load i64, i64* @AF_INET
%28 = icmp eq i64 %26, %27
%29 = load i64, i64* @AF_INET6
%30 = icmp eq i64 %26, %29
%31 = select i1 %28, i1 true, i1 %30
br i1 %31, label %32, label %54
32: ; preds = %24
br i1 %13, label %49, label %33
33: ; preds = %32
%34 = load i8*, i8** %14
%35 = call i32 @strncmp(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i64, i64* %25
%39 = load i64, i64* @AF_INET
%40 = icmp eq i64 %38, %39
br i1 %40, label %49, label %41
41: ; preds = %37, %33
%42 = load i8*, i8** %14
%43 = call i32 @strncmp(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %54
45: ; preds = %41
%46 = load i64, i64* %25
%47 = load i64, i64* @AF_INET6
%48 = icmp eq i64 %46, %47
br i1 %48, label %49, label %54
49: ; preds = %45, %37, %32
%50 = call i8* @my_getnameinfo(%struct.sockaddr* %22)
%51 = icmp eq i8* %50, null
br i1 %51, label %54, label %52
52: ; preds = %49
%53 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %20, i8* %50)
br label %54
54: ; preds = %17, %24, %41, %45, %52, %49
%55 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %18, i64 0, i32 2
%56 = load %struct.ifaddrs*, %struct.ifaddrs** %55
%57 = icmp eq %struct.ifaddrs* %56, null
br i1 %57, label %58, label %17
58: ; preds = %54
%59 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%60 = call i32 @freeifaddrs(%struct.ifaddrs* %59)
%61 = call i32 @exit(i32 0)
unreachable
}