#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 */
struct TYPE_2__ {
  scalar_t__ sa_family;
};
struct ifreq {
  int ifr_flags;
  TYPE_1__ ifr_addr;
};
struct ifconf {
  int ifc_len;
  struct ifreq *ifc_req;
};

/* Variables and functions */
scalar_t__ AF_INET;
int IFF_BROADCAST;
int IFF_LOOPBACK;
int IFF_POINTOPOINT;
int IFF_RUNNING;
int IFF_UP;
int /*<<< orphan*/ SIOCGIFFLAGS;
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ perror(char *);
struct ifreq *find_ifreq(int s, struct ifconf *iflist) {
  int index;
  for (index = 0; index < iflist->ifc_len / sizeof(struct ifreq); index++) {
    struct ifreq *ifreq = &iflist->ifc_req[index];
    if (ifreq->ifr_addr.sa_family != AF_INET) {
      continue;
    }
    if (ioctl(s, SIOCGIFFLAGS, ifreq) == -1) {
      perror("siocgifflags");
      return NULL;
    }
    if ((ifreq->ifr_flags & (IFF_UP | IFF_RUNNING | IFF_BROADCAST |
                             IFF_LOOPBACK | IFF_POINTOPOINT)) ==
        (IFF_UP | IFF_RUNNING | IFF_BROADCAST)) {
      return ifreq;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_ifreq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
shr    $0x4,%rcx
cmp    %rcx,%rax
jae    1231 <find_ifreq+0x111>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
je     1182 <find_ifreq+0x62>
jmp    1223 <find_ifreq+0x103>
mov    -0xc(%rbp),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11b9 <find_ifreq+0x99>
lea    0xe59(%rip),%rdi
call   1040 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1239 <find_ifreq+0x119>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    0x2e02(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e01(%rip),%rdx
or     (%rdx),%ecx
mov    0x2dd8(%rip),%rdx
or     (%rdx),%ecx
mov    0x2e17(%rip),%rdx
or     (%rdx),%ecx
mov    0x2dee(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
mov    0x2dd3(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2dd2(%rip),%rdx
or     (%rdx),%ecx
mov    0x2da9(%rip),%rdx
or     (%rdx),%ecx
cmp    %ecx,%eax
jne    121e <find_ifreq+0xfe>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1239 <find_ifreq+0x119>
jmp    1223 <find_ifreq+0x103>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1136 <find_ifreq+0x16>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_ifreq>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rsi),%eax
cmp    $0x10,%eax
jae    1146 <find_ifreq+0x26>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%rcx
xor    %r13d,%r13d
xor    %r15d,%r15d
jmp    1174 <find_ifreq+0x54>
xchg   %ax,%ax
add    $0x1,%r15
movslq %eax,%rdx
shr    $0x4,%rdx
add    $0x10,%r13
cmp    %r15,%rdx
jbe    1132 <find_ifreq+0x12>
mov    0x8(%rbx),%r12
cmp    %rcx,0x8(%r12,%r13,1)
jne    1160 <find_ifreq+0x40>
lea    (%r12,%r13,1),%rbp
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbp,%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11e8 <find_ifreq+0xc8>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    0x2e1c(%rip),%rcx
or     (%rcx),%eax
mov    0x2dfb(%rip),%rcx
or     (%rcx),%eax
mov    0x2e3a(%rip),%rcx
mov    (%rcx),%ecx
or     %eax,%ecx
mov    0x2e0f(%rip),%rdx
or     (%rdx),%ecx
and    (%r12,%r13,1),%ecx
cmp    %eax,%ecx
je     1134 <find_ifreq+0x14>
mov    0x2e02(%rip),%rax
mov    (%rax),%rcx
mov    (%rbx),%eax
jmp    1160 <find_ifreq+0x40>
lea    0xe11(%rip),%rdi
call   1040 <perror@plt>
jmp    1132 <find_ifreq+0x12>

LLVM IR (-O0):
%struct.ifreq = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
%struct.ifconf = type { i32, %struct.ifreq* }
@AF_INET = global i64 0
@SIOCGIFFLAGS = global i32 0
@.str = [13 x i8] c"siocgifflags\00"
@IFF_UP = global i32 0
@IFF_RUNNING = global i32 0
@IFF_BROADCAST = global i32 0
@IFF_LOOPBACK = global i32 0
@IFF_POINTOPOINT = global i32 0
define %struct.ifreq* @find_ifreq(i32 %0, %struct.ifconf* %1) {
%3 = alloca %struct.ifreq*
%4 = alloca i32
%5 = alloca %struct.ifconf*
%6 = alloca i32
%7 = alloca %struct.ifreq*
store i32 %0, i32* %4
store %struct.ifconf* %1, %struct.ifconf** %5
store i32 0, i32* %6
br label %8
8: ; preds = %62, %2
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = load %struct.ifconf*, %struct.ifconf** %5
%12 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = sext i32 %13 to i64
%15 = udiv i64 %14, 16
%16 = icmp ult i64 %10, %15
br i1 %16, label %17, label %65
17: ; preds = %8
%18 = load %struct.ifconf*, %struct.ifconf** %5
%19 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %18, i32 0, i32 1
%20 = load %struct.ifreq*, %struct.ifreq** %19
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %20, i64 %22
store %struct.ifreq* %23, %struct.ifreq** %7
%24 = load %struct.ifreq*, %struct.ifreq** %7
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %24, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
%27 = load i64, i64* %26
%28 = load i64, i64* @AF_INET
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %17
br label %62
31: ; preds = %17
%32 = load i32, i32* %4
%33 = load i32, i32* @SIOCGIFFLAGS
%34 = load %struct.ifreq*, %struct.ifreq** %7
%35 = call i32 @ioctl(i32 %32, i32 %33, %struct.ifreq* %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store %struct.ifreq* null, %struct.ifreq** %3
br label %66
39: ; preds = %31
%40 = load %struct.ifreq*, %struct.ifreq** %7
%41 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = load i32, i32* @IFF_UP
%44 = load i32, i32* @IFF_RUNNING
%45 = or i32 %43, %44
%46 = load i32, i32* @IFF_BROADCAST
%47 = or i32 %45, %46
%48 = load i32, i32* @IFF_LOOPBACK
%49 = or i32 %47, %48
%50 = load i32, i32* @IFF_POINTOPOINT
%51 = or i32 %49, %50
%52 = and i32 %42, %51
%53 = load i32, i32* @IFF_UP
%54 = load i32, i32* @IFF_RUNNING
%55 = or i32 %53, %54
%56 = load i32, i32* @IFF_BROADCAST
%57 = or i32 %55, %56
%58 = icmp eq i32 %52, %57
br i1 %58, label %59, label %61
59: ; preds = %39
%60 = load %struct.ifreq*, %struct.ifreq** %7
store %struct.ifreq* %60, %struct.ifreq** %3
br label %66
61: ; preds = %39
br label %62
62: ; preds = %61, %30
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %8
65: ; preds = %8
store %struct.ifreq* null, %struct.ifreq** %3
br label %66
66: ; preds = %65, %59, %37
%67 = load %struct.ifreq*, %struct.ifreq** %3
ret %struct.ifreq* %67
}

LLVM IR (-O2):
%struct.ifreq = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
%struct.ifconf = type { i32, %struct.ifreq* }
@AF_INET = global i64 0
@SIOCGIFFLAGS = global i32 0
@.str = [13 x i8] c"siocgifflags\00"
@IFF_UP = global i32 0
@IFF_RUNNING = global i32 0
@IFF_BROADCAST = global i32 0
@IFF_LOOPBACK = global i32 0
@IFF_POINTOPOINT = global i32 0
define %struct.ifreq* @find_ifreq(i32 %0, %struct.ifconf* nocapture %1) {
%3 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %1, i64 0, i32 0
%4 = load i32, i32* %3
%5 = icmp ult i32 %4, 16
br i1 %5, label %48, label %6
6: ; preds = %2
%7 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %1, i64 0, i32 1
%8 = load i64, i64* @AF_INET
br label %9
9: ; preds = %6, %41
%10 = phi i32 [ %4, %6 ], [ %42, %41 ]
%11 = phi i64 [ %8, %6 ], [ %43, %41 ]
%12 = phi i64 [ 0, %6 ], [ %44, %41 ]
%13 = load %struct.ifreq*, %struct.ifreq** %7
%14 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %13, i64 %12
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %13, i64 %12, i32 1, i32 0
%16 = load i64, i64* %15
%17 = icmp eq i64 %16, %11
br i1 %17, label %18, label %41
18: ; preds = %9
%19 = load i32, i32* @SIOCGIFFLAGS
%20 = tail call i32 @ioctl(i32 %0, i32 %19, %struct.ifreq* %14)
%21 = icmp eq i32 %20, -1
%22 = load i64, i64* @AF_INET
br i1 %21, label %23, label %25
23: ; preds = %18
%24 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %48
25: ; preds = %18
%26 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %14, i64 0, i32 0
%27 = load i32, i32* %26
%28 = load i32, i32* @IFF_UP
%29 = load i32, i32* @IFF_RUNNING
%30 = or i32 %29, %28
%31 = load i32, i32* @IFF_BROADCAST
%32 = or i32 %30, %31
%33 = load i32, i32* @IFF_LOOPBACK
%34 = or i32 %32, %33
%35 = load i32, i32* @IFF_POINTOPOINT
%36 = or i32 %34, %35
%37 = and i32 %36, %27
%38 = icmp eq i32 %37, %32
br i1 %38, label %48, label %39
39: ; preds = %25
%40 = load i32, i32* %3
br label %41
41: ; preds = %39, %9
%42 = phi i32 [ %10, %9 ], [ %40, %39 ]
%43 = phi i64 [ %11, %9 ], [ %22, %39 ]
%44 = add nuw nsw i64 %12, 1
%45 = sext i32 %42 to i64
%46 = lshr i64 %45, 4
%47 = icmp ugt i64 %46, %44
br i1 %47, label %9, label %48
48: ; preds = %41, %25, %2, %23
%49 = phi %struct.ifreq* [ null, %23 ], [ null, %2 ], [ null, %41 ], [ %14, %25 ]
ret %struct.ifreq* %49
}