#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
struct TYPE_4__ {
  int sa_family;
};
struct ifreq {
  TYPE_2__ ifr_addr;
  int /*<<< orphan*/ ifr_name;
};
struct ifconf {
  int ifc_len;
  void *ifc_buf;
};

/* Variables and functions */
#define AF_INET 128
int /*<<< orphan*/ dbgprintf(char *, int, ...);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
void print_ifc(struct ifconf *ifc) {
  int i;
  void *p;
  struct ifreq *ifr;
  struct in_addr in_addr;
  size_t len = 0;
  dbgprintf("[ifc]\n", ifc->ifc_len);
  for (p = ifc->ifc_buf; p < (void *)ifc->ifc_buf + ifc->ifc_len; p += len) {
    ifr = (struct ifreq *)p;
    switch (ifr->ifr_addr.sa_family) {
    case AF_INET:
      in_addr.s_addr = ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr;
      dbgprintf("if_name = %s; ip_addr = %s; sa_family = %d\n", ifr->ifr_name,
                inet_ntoa(in_addr), ifr->ifr_addr.sa_family);
      break;
    default:
      dbgprintf("unsupported address family %d\n", ifr->ifr_addr.sa_family);
      break;
    }
    len = sizeof(struct ifreq);
  }
}


x86 assembly (clang, -O0):
<print_ifc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <dbgprintf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    0x8(%rcx),%rcx
mov    -0x8(%rbp),%rdx
movslq (%rdx),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    11f7 <print_ifc+0xd7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
sub    $0x80,%eax
jne    11ca <print_ifc+0xaa>
jmp    1191 <print_ifc+0x71>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    -0x34(%rbp),%esi
mov    %eax,%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <dbgprintf@plt>
jmp    11de <print_ifc+0xbe>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <dbgprintf@plt>
movq   $0x8,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1154 <print_ifc+0x34>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ifc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
mov    (%rdi),%esi
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1040 <dbgprintf@plt>
mov    0x8(%r12),%rbx
movslq (%r12),%rax
add    %rbx,%rax
cmp    %rax,%rbx
jae    11a5 <print_ifc+0x85>
lea    0xeb4(%rip),%r14
lea    0xed9(%rip),%r15
jmp    117c <print_ifc+0x5c>
nopl   0x0(%rax)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <dbgprintf@plt>
add    $0x8,%rbx
movslq (%r12),%rax
add    0x8(%r12),%rax
cmp    %rax,%rbx
jae    11a5 <print_ifc+0x85>
mov    (%rbx),%esi
cmp    $0x80,%esi
jne    1160 <print_ifc+0x40>
mov    0x4(%rbx),%ebp
mov    $0x80,%edi
call   1030 <inet_ntoa@plt>
mov    (%rbx),%ecx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <dbgprintf@plt>
jmp    116a <print_ifc+0x4a>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifconf = type { i32, i8* }
%struct.ifreq = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
@.str = [7 x i8] c"[ifc]\0A\00"
@.str.1 = [44 x i8] c"if_name = %s; ip_addr = %s; sa_family = %d\0A\00"
@.str.2 = [31 x i8] c"unsupported address family %d\0A\00"
define void @print_ifc(%struct.ifconf* %0) {
%2 = alloca %struct.ifconf*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.ifreq*
%6 = alloca %struct.in_addr
%7 = alloca i64
store %struct.ifconf* %0, %struct.ifconf** %2
store i64 0, i64* %7
%8 = load %struct.ifconf*, %struct.ifconf** %2
%9 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i32 (i8*, i32, ...) @dbgprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load %struct.ifconf*, %struct.ifconf** %2
%13 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %12, i32 0, i32 1
%14 = load i8*, i8** %13
store i8* %14, i8** %4
br label %15
15: ; preds = %59, %1
%16 = load i8*, i8** %4
%17 = load %struct.ifconf*, %struct.ifconf** %2
%18 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %17, i32 0, i32 1
%19 = load i8*, i8** %18
%20 = load %struct.ifconf*, %struct.ifconf** %2
%21 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = getelementptr i8, i8* %19, i64 %23
%25 = icmp ult i8* %16, %24
br i1 %25, label %26, label %63
26: ; preds = %15
%27 = load i8*, i8** %4
%28 = bitcast i8* %27 to %struct.ifreq*
store %struct.ifreq* %28, %struct.ifreq** %5
%29 = load %struct.ifreq*, %struct.ifreq** %5
%30 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %29, i32 0, i32 0
%31 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %30, i32 0, i32 0
%32 = load i32, i32* %31
switch i32 %32, label %52 [
i32 128, label %33
]
33: ; preds = %26
%34 = load %struct.ifreq*, %struct.ifreq** %5
%35 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %34, i32 0, i32 0
%36 = bitcast %struct.TYPE_4__* %35 to %struct.sockaddr_in*
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %36, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %37, i32 0, i32 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
store i32 %39, i32* %40
%41 = load %struct.ifreq*, %struct.ifreq** %5
%42 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %41, i32 0, i32 1
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @inet_ntoa(i32 %45)
%47 = load %struct.ifreq*, %struct.ifreq** %5
%48 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %47, i32 0, i32 0
%49 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 (i8*, i32, ...) @dbgprintf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %43, i32 %46, i32 %50)
br label %58
52: ; preds = %26
%53 = load %struct.ifreq*, %struct.ifreq** %5
%54 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %53, i32 0, i32 0
%55 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 (i8*, i32, ...) @dbgprintf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %52, %33
store i64 8, i64* %7
br label %59
59: ; preds = %58
%60 = load i64, i64* %7
%61 = load i8*, i8** %4
%62 = getelementptr i8, i8* %61, i64 %60
store i8* %62, i8** %4
br label %15
63: ; preds = %15
ret void
}

LLVM IR (-O2):
%struct.ifconf = type { i32, i8* }
@.str = [7 x i8] c"[ifc]\0A\00"
@.str.1 = [44 x i8] c"if_name = %s; ip_addr = %s; sa_family = %d\0A\00"
@.str.2 = [31 x i8] c"unsupported address family %d\0A\00"
define void @print_ifc(%struct.ifconf* nocapture %0) {
%2 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = tail call i32 (i8*, i32, ...) @dbgprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %0, i64 0, i32 1
%6 = load i8*, i8** %5
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = getelementptr i8, i8* %6, i64 %8
%10 = icmp ult i8* %6, %9
br i1 %10, label %11, label %32
11: ; preds = %1, %25
%12 = phi i8* [ %26, %25 ], [ %6, %1 ]
%13 = bitcast i8* %12 to i32*
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 128
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %12, i64 4
%18 = bitcast i8* %17 to i32*
%19 = load i32, i32* %18
%20 = tail call i32 @inet_ntoa(i32 128)
%21 = load i32, i32* %13
%22 = tail call i32 (i8*, i32, ...) @dbgprintf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %20, i32 %21)
br label %25
23: ; preds = %11
%24 = tail call i32 (i8*, i32, ...) @dbgprintf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %25
25: ; preds = %23, %16
%26 = getelementptr i8, i8* %12, i64 8
%27 = load i8*, i8** %5
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = getelementptr i8, i8* %27, i64 %29
%31 = icmp ult i8* %26, %30
br i1 %31, label %11, label %32
32: ; preds = %25, %1
ret void
}