#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_in {
  int /*<<< orphan*/ sin_addr;
};
struct ifreq {
  char *ifr_name;
  int /*<<< orphan*/ ifr_addr;
};
struct ifconf {
  int ifc_len;
  unsigned char *ifc_buf;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCGIFCONF;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *inet_ntoa(int /*<<< orphan*/);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifconf *);
int /*<<< orphan*/ printf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  int i = 0;
  int sockfd;
  struct ifconf ifcon;
  struct ifreq *ifr;
  unsigned char buf[512];
  ifcon.ifc_len = 512;
  ifcon.ifc_buf = buf;
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    fprintf(stderr, "socket() error: %s\n", strerror(errno));
    return -1;
  }
  if (ioctl(sockfd, SIOCGIFCONF, &ifcon) < 0) {
    fprintf(stderr, "ioctl() error: %s\n", strerror(errno));
    close(sockfd);
    return -1;
  }
  ifr = (struct ifreq *)buf;
  for (i = ifcon.ifc_len / sizeof(struct ifreq); i > 0; --i) {
    printf("name = [%s]\n", ifr->ifr_name);
    printf("local addr = [%s]\n",
           inet_ntoa(((struct sockaddr_in *)&(ifr->ifr_addr))->sin_addr));
    ifr++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x200,-0x20(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11fe <main+0x8e>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x234(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x234(%rbp),%edi
mov    %rax,%rdx
lea    0xe13(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d2 <main+0x162>
mov    -0xc(%rbp),%edi
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1263 <main+0xf3>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x238(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x238(%rbp),%edi
mov    %rax,%rdx
lea    0xdca(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d2 <main+0x162>
lea    -0x230(%rbp),%rax
mov    %rax,-0x28(%rbp)
movslq -0x20(%rbp),%rax
shr    $0x4,%rax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    12cb <main+0x15b>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
lea    0xd96(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd88(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1279 <main+0x109>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x210,%rsp
movl   $0x200,(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,0x8(%rsp)
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
test   %eax,%eax
js     121c <main+0xac>
mov    %eax,%ebp
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
test   %rax,%rax
js     1246 <main+0xd6>
mov    (%rsp),%ebp
xor    %r14d,%r14d
cmp    $0x10,%ebp
jl     127b <main+0x10b>
shr    $0x4,%ebp
add    $0x1,%ebp
lea    0xe44(%rip),%r15
lea    0xe4a(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%rsi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    0x8(%rbx),%edi
call   1030 <inet_ntoa@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
add    $0xffffffff,%ebp
add    $0x10,%rbx
cmp    $0x1,%ebp
ja     11f0 <main+0x80>
jmp    127b <main+0x10b>
mov    0x2dad(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdc6(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
jmp    1275 <main+0x105>
mov    0x2d83(%rip),%rax
mov    (%rax),%ebx
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdb0(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifconf = type { i32, i8* }
%struct.ifreq = type { i8*, i32 }
%struct.sockaddr_in = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"socket() error: %s\0A\00"
@errno = global i32 0
@SIOCGIFCONF = global i32 0
@.str.1 = [19 x i8] c"ioctl() error: %s\0A\00"
@.str.2 = [13 x i8] c"name = [%s]\0A\00"
@.str.3 = [19 x i8] c"local addr = [%s]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.ifconf
%5 = alloca %struct.ifreq*
%6 = alloca [512 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
%7 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i32 0, i32 0
store i32 512, i32* %7
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i32 0, i32 1
store i8* %8, i8** %9
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 -1, i32* %1
br label %60
19: ; preds = %0
%20 = load i32, i32* %3
%21 = load i32, i32* @SIOCGIFCONF
%22 = call i64 @ioctl(i32 %20, i32 %21, %struct.ifconf* %4)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %3
%30 = call i32 @close(i32 %29)
store i32 -1, i32* %1
br label %60
31: ; preds = %19
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%33 = bitcast i8* %32 to %struct.ifreq*
store %struct.ifreq* %33, %struct.ifreq** %5
%34 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i32 0, i32 0
%35 = load i32, i32* %34
%36 = sext i32 %35 to i64
%37 = udiv i64 %36, 16
%38 = trunc i64 %37 to i32
store i32 %38, i32* %2
br label %39
39: ; preds = %56, %31
%40 = load i32, i32* %2
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %59
42: ; preds = %39
%43 = load %struct.ifreq*, %struct.ifreq** %5
%44 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %43, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = load %struct.ifreq*, %struct.ifreq** %5
%48 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %47, i32 0, i32 1
%49 = bitcast i32* %48 to %struct.sockaddr_in*
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i8* @inet_ntoa(i32 %51)
%53 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %52)
%54 = load %struct.ifreq*, %struct.ifreq** %5
%55 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %54, i32 1
store %struct.ifreq* %55, %struct.ifreq** %5
br label %56
56: ; preds = %42
%57 = load i32, i32* %2
%58 = add nsw i32 %57, -1
store i32 %58, i32* %2
br label %39
59: ; preds = %39
store i32 0, i32* %1
br label %60
60: ; preds = %59, %24, %14
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
%struct.ifconf = type { i32, i8* }
%struct.ifreq = type { i8*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"socket() error: %s\0A\00"
@errno = global i32 0
@SIOCGIFCONF = global i32 0
@.str.1 = [19 x i8] c"ioctl() error: %s\0A\00"
@.str.2 = [13 x i8] c"name = [%s]\0A\00"
@.str.3 = [19 x i8] c"local addr = [%s]\0A\00"
define i32 @main() {
%1 = alloca %struct.ifconf
%2 = alloca [512 x i8]
%3 = bitcast %struct.ifconf* %1 to i8*
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %1, i64 0, i32 0
store i32 512, i32* %5
%6 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %1, i64 0, i32 1
store i8* %4, i8** %6
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %45
16: ; preds = %0
%17 = load i32, i32* @SIOCGIFCONF
%18 = call i64 @ioctl(i32 %9, i32 %17, %struct.ifconf* %1)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = call i32 @close(i32 %9)
br label %45
26: ; preds = %16
%27 = load i32, i32* %5
%28 = icmp sgt i32 %27, 15
br i1 %28, label %29, label %45
29: ; preds = %26
%30 = lshr i32 %27, 4
%31 = bitcast [512 x i8]* %2 to %struct.ifreq*
br label %32
32: ; preds = %29, %32
%33 = phi %struct.ifreq* [ %42, %32 ], [ %31, %29 ]
%34 = phi i32 [ %43, %32 ], [ %30, %29 ]
%35 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %33, i64 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %33, i64 0, i32 1
%39 = load i32, i32* %38
%40 = call i8* @inet_ntoa(i32 %39)
%41 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %33, i64 1
%43 = add nsw i32 %34, -1
%44 = icmp ugt i32 %34, 1
br i1 %44, label %32, label %45
45: ; preds = %32, %26, %20, %11
%46 = phi i32 [ -1, %11 ], [ -1, %20 ], [ 0, %26 ], [ 0, %32 ]
ret i32 %46
}