#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_6__ TYPE_3__;
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  unsigned int s_addr;
};
struct sockaddr_in {
  TYPE_2__ sin_addr;
};
struct TYPE_6__ {
  int /*<<< orphan*/ ifru_addr;
};
struct TYPE_4__ {
  char *ifrn_name;
};
struct ifreq {
  TYPE_3__ ifr_ifru;
  TYPE_1__ ifr_ifrn;
};
struct ifconf {
  int ifc_len;
  struct ifreq *ifc_req;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCGIFCONF;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifconf *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
unsigned int get_address(char *if_name) {
  struct ifconf if_list;
  struct ifreq interfaces[16];
  int i, s = socket(AF_INET, SOCK_DGRAM, 0);
  if_list.ifc_len = 16 * sizeof(struct ifreq);
  if_list.ifc_req = interfaces;
  ioctl(s, SIOCGIFCONF, &if_list);
  close(s);
  for (i = 0; i != if_list.ifc_len / sizeof(struct ifreq); i++) {
    char *name = interfaces[i].ifr_ifrn.ifrn_name;
    unsigned int address =
        ((struct sockaddr_in *)&interfaces[i].ifr_ifru.ifru_addr)
            ->sin_addr.s_addr;
    if (if_name && !strcmp(name, if_name))
      return address;
    if (!if_name && address != 0x0100007F)
      return address;
  }
  return 0x0100007F;
}


x86 assembly (clang, -O0):
<get_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x128(%rbp)
movl   $0x100,-0x20(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x128(%rbp),%edi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
mov    -0x128(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x124(%rbp)
movslq -0x124(%rbp),%rax
movslq -0x20(%rbp),%rcx
shr    $0x4,%rcx
cmp    %rcx,%rax
je     1276 <get_address+0x136>
movslq -0x124(%rbp),%rcx
lea    -0x120(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
mov    %rax,-0x130(%rbp)
movslq -0x124(%rbp),%rcx
lea    -0x120(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1234 <get_address+0xf4>
mov    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1234 <get_address+0xf4>
mov    -0x134(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    127d <get_address+0x13d>
cmpq   $0x0,-0x10(%rbp)
jne    125d <get_address+0x11d>
cmpl   $0x100007f,-0x134(%rbp)
je     125d <get_address+0x11d>
mov    -0x134(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    127d <get_address+0x13d>
jmp    1262 <get_address+0x122>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    11ad <get_address+0x6d>
movl   $0x100007f,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_address>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%r14
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebp
movl   $0x100,(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1030 <ioctl@plt>
mov    %ebp,%edi
call   1040 <close@plt>
movslq (%rsp),%rbx
cmp    $0x10,%rbx
jae    11b7 <get_address+0x77>
mov    $0x100007f,%r15d
mov    %r15d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
shr    $0x4,%rbx
lea    0x18(%rsp),%rbp
jmp    11e3 <get_address+0xa3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x100007f,%r15d
jne    11a6 <get_address+0x66>
add    $0x10,%rbp
add    $0xffffffffffffffff,%rbx
je     11a0 <get_address+0x60>
mov    -0x8(%rbp),%r15d
test   %r14,%r14
je     11d0 <get_address+0x90>
mov    0x0(%rbp),%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    11d9 <get_address+0x99>
jmp    11a6 <get_address+0x66>

LLVM IR (-O0):
%struct.ifconf = type { i32, %struct.ifreq* }
%struct.ifreq = type { %struct.TYPE_6__, %struct.TYPE_4__ }
%struct.TYPE_6__ = type { i32 }
%struct.TYPE_4__ = type { i8* }
%struct.sockaddr_in = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCGIFCONF = global i32 0
define i32 @get_address(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.ifconf
%5 = alloca [16 x %struct.ifreq]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %3
%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* %7
%13 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i32 0, i32 0
store i32 256, i32* %13
%14 = getelementptr inbounds [16 x %struct.ifreq], [16 x %struct.ifreq]* %5, i64 0, i64 0
%15 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i32 0, i32 1
store %struct.ifreq* %14, %struct.ifreq** %15
%16 = load i32, i32* %7
%17 = load i32, i32* @SIOCGIFCONF
%18 = call i32 @ioctl(i32 %16, i32 %17, %struct.ifconf* %4)
%19 = load i32, i32* %7
%20 = call i32 @close(i32 %19)
store i32 0, i32* %6
br label %21
21: ; preds = %63, %1
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i32 0, i32 0
%25 = load i32, i32* %24
%26 = sext i32 %25 to i64
%27 = udiv i64 %26, 16
%28 = icmp ne i64 %23, %27
br i1 %28, label %29, label %66
29: ; preds = %21
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [16 x %struct.ifreq], [16 x %struct.ifreq]* %5, i64 0, i64 %31
%33 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %32, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %33, i32 0, i32 0
%35 = load i8*, i8** %34
store i8* %35, i8** %8
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [16 x %struct.ifreq], [16 x %struct.ifreq]* %5, i64 0, i64 %37
%39 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %38, i32 0, i32 0
%40 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %39, i32 0, i32 0
%41 = bitcast i32* %40 to %struct.sockaddr_in*
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %41, i32 0, i32 0
%43 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %42, i32 0, i32 0
%44 = load i32, i32* %43
store i32 %44, i32* %9
%45 = load i8*, i8** %3
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %54
47: ; preds = %29
%48 = load i8*, i8** %8
%49 = load i8*, i8** %3
%50 = call i32 @strcmp(i8* %48, i8* %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %47
%53 = load i32, i32* %9
store i32 %53, i32* %2
br label %67
54: ; preds = %47, %29
%55 = load i8*, i8** %3
%56 = icmp ne i8* %55, null
br i1 %56, label %62, label %57
57: ; preds = %54
%58 = load i32, i32* %9
%59 = icmp ne i32 %58, 16777343
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = load i32, i32* %9
store i32 %61, i32* %2
br label %67
62: ; preds = %57, %54
br label %63
63: ; preds = %62
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %21
66: ; preds = %21
store i32 16777343, i32* %2
br label %67
67: ; preds = %66, %60, %52
%68 = load i32, i32* %2
ret i32 %68
}

LLVM IR (-O2):
%struct.ifconf = type { i32, %struct.ifreq* }
%struct.ifreq = type { %struct.TYPE_6__, %struct.TYPE_4__ }
%struct.TYPE_6__ = type { i32 }
%struct.TYPE_4__ = type { i8* }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCGIFCONF = global i32 0
define i32 @get_address(i8* %0) {
%2 = alloca %struct.ifconf
%3 = alloca [16 x %struct.ifreq]
%4 = bitcast %struct.ifconf* %2 to i8*
%5 = bitcast [16 x %struct.ifreq]* %3 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %2, i64 0, i32 0
store i32 256, i32* %9
%10 = getelementptr inbounds [16 x %struct.ifreq], [16 x %struct.ifreq]* %3, i64 0, i64 0
%11 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %2, i64 0, i32 1
store %struct.ifreq* %10, %struct.ifreq** %11
%12 = load i32, i32* @SIOCGIFCONF
%13 = call i32 @ioctl(i32 %8, i32 %12, %struct.ifconf* %2)
%14 = call i32 @close(i32 %8)
%15 = load i32, i32* %9
%16 = sext i32 %15 to i64
%17 = lshr i64 %16, 4
%18 = icmp ult i32 %15, 16
br i1 %18, label %35, label %19
19: ; preds = %1
%20 = icmp eq i8* %0, null
br label %21
21: ; preds = %19, %32
%22 = phi i64 [ 0, %19 ], [ %33, %32 ]
%23 = getelementptr inbounds [16 x %struct.ifreq], [16 x %struct.ifreq]* %3, i64 0, i64 %22, i32 0, i32 0
%24 = load i32, i32* %23
br i1 %20, label %30, label %25
25: ; preds = %21
%26 = getelementptr inbounds [16 x %struct.ifreq], [16 x %struct.ifreq]* %3, i64 0, i64 %22, i32 1, i32 0
%27 = load i8*, i8** %26
%28 = call i32 @strcmp(i8* dereferenceable(1) %27, i8* %0)
%29 = icmp eq i32 %28, 0
br i1 %29, label %35, label %32
30: ; preds = %21
%31 = icmp eq i32 %24, 16777343
br i1 %31, label %32, label %35
32: ; preds = %25, %30
%33 = add nuw i64 %22, 1
%34 = icmp eq i64 %17, %33
br i1 %34, label %35, label %21
35: ; preds = %30, %32, %25, %1
%36 = phi i32 [ 16777343, %1 ], [ %24, %25 ], [ 16777343, %32 ], [ %24, %30 ]
ret i32 %36
}