#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*/ exit(int);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifconf *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int i = 0;
  int sockfd;
  struct ifconf ifconf;
  unsigned char buf[512];
  struct ifreq *ifreq;
  ifconf.ifc_len = 512;
  ifconf.ifc_buf = buf;
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
    exit(1);
  }
  ioctl(sockfd, SIOCGIFCONF, &ifconf);
  ifreq = (struct ifreq *)buf;
  for (i = (ifconf.ifc_len / sizeof(struct ifreq)); i > 0; i--) {
    printf("name = %s \n", ifreq->ifr_name);
    printf("local addr = %s \n",
           inet_ntoa(((struct sockaddr_in *)&(ifreq->ifr_addr))->sin_addr));
    ifreq++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x200,-0x20(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11c6 <main+0x66>
lea    0xe49(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0xc(%rbp),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
lea    -0x220(%rbp),%rax
mov    %rax,-0x228(%rbp)
movslq -0x20(%rbp),%rax
shr    $0x4,%rax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1252 <main+0xf2>
mov    -0x228(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x228(%rbp),%rax
mov    0x8(%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x228(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x228(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    11f4 <main+0x94>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x218,%rsp
movl   $0x200,(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,0x8(%rsp)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     120a <main+0xaa>
mov    0x2e2e(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1050 <ioctl@plt>
mov    (%rsp),%ebp
cmp    $0x10,%ebp
jl     11fa <main+0x9a>
shr    $0x4,%ebp
add    $0x1,%ebp
lea    0xe44(%rip),%r14
lea    0xe49(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    0x8(%rbx),%edi
call   1030 <inet_ntoa@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
add    $0xffffffff,%ebp
add    $0x10,%rbx
cmp    $0x1,%ebp
ja     11d0 <main+0x70>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdef(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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
@.str = [7 x i8] c"socket\00"
@SIOCGIFCONF = global i32 0
@.str.1 = [12 x i8] c"name = %s \0A\00"
@.str.2 = [18 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 [512 x i8]
%6 = alloca %struct.ifreq*
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]* %5, 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 %17
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* %3
%19 = load i32, i32* @SIOCGIFCONF
%20 = call i32 @ioctl(i32 %18, i32 %19, %struct.ifconf* %4)
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%22 = bitcast i8* %21 to %struct.ifreq*
store %struct.ifreq* %22, %struct.ifreq** %6
%23 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i32 0, i32 0
%24 = load i32, i32* %23
%25 = sext i32 %24 to i64
%26 = udiv i64 %25, 16
%27 = trunc i64 %26 to i32
store i32 %27, i32* %2
br label %28
28: ; preds = %45, %17
%29 = load i32, i32* %2
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %48
31: ; preds = %28
%32 = load %struct.ifreq*, %struct.ifreq** %6
%33 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %32, i32 0, i32 0
%34 = load i8*, i8** %33
%35 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load %struct.ifreq*, %struct.ifreq** %6
%37 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %36, i32 0, i32 1
%38 = bitcast i32* %37 to %struct.sockaddr_in*
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i8* @inet_ntoa(i32 %40)
%42 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = load %struct.ifreq*, %struct.ifreq** %6
%44 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %43, i32 1
store %struct.ifreq* %44, %struct.ifreq** %6
br label %45
45: ; preds = %31
%46 = load i32, i32* %2
%47 = add nsw i32 %46, -1
store i32 %47, i32* %2
br label %28
48: ; preds = %28
ret i32 0
}

LLVM IR (-O2):
%struct.ifconf = type { i32, i8* }
%struct.ifreq = type { i8*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SIOCGIFCONF = global i32 0
@.str.1 = [12 x i8] c"name = %s \0A\00"
@.str.2 = [18 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 %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = load i32, i32* @SIOCGIFCONF
%16 = call i32 @ioctl(i32 %9, i32 %15, %struct.ifconf* %1)
%17 = load i32, i32* %5
%18 = icmp sgt i32 %17, 15
br i1 %18, label %19, label %35
19: ; preds = %14
%20 = lshr i32 %17, 4
%21 = bitcast [512 x i8]* %2 to %struct.ifreq*
br label %22
22: ; preds = %19, %22
%23 = phi %struct.ifreq* [ %32, %22 ], [ %21, %19 ]
%24 = phi i32 [ %33, %22 ], [ %20, %19 ]
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %23, i64 0, i32 0
%26 = load i8*, i8** %25
%27 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %23, i64 0, i32 1
%29 = load i32, i32* %28
%30 = call i8* @inet_ntoa(i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %23, i64 1
%33 = add nsw i32 %24, -1
%34 = icmp ugt i32 %24, 1
br i1 %34, label %22, label %35
35: ; preds = %22, %14
ret i32 0
}