#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 ifreq {
  int dummy;
};
struct ifconf {
  int ifc_len;
  char *ifc_buf;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int BUFSIZ;
int /*<<< orphan*/ PrintResult(struct ifreq *);
int /*<<< orphan*/ SIOCGIFCONF;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ check_args(int, char **);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int ioctl(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  struct ifconf ifc;
  char buf[BUFSIZ], *ptr, *ptr_end;
  int ret, sock;
  check_args(argc, argv);
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0) {
    perror("socket");
    exit(1);
  }
  ifc.ifc_len = sizeof(buf);
  ifc.ifc_buf = buf;
  ret = ioctl(sock, SIOCGIFCONF, (char *)&ifc);
  if (ret < 0) {
    perror("ioctl: SIOCGIFCONF");
    exit(1);
  }
  ptr_end = buf + ifc.ifc_len;
  for (ptr = ifc.ifc_buf; ptr < ptr_end; ptr += sizeof(struct ifreq)) {
    struct ifreq *ifr;
    ifr = (struct ifreq *)ptr;
    ret = ioctl(sock, SIOCGIFFLAGS, (char *)ifr);
    if (ret < 0) {
      perror("ioctl : SIOCGIFFLAGS");
      exit(1);
    }
    PrintResult(ifr);
  }
  close(sock);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x60(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <check_args@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    11fe <main+0x8e>
lea    0xe11(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x58(%rbp),%rax
mov    -0x60(%rbp),%rcx
mov    %ecx,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
mov    -0x48(%rbp),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1245 <main+0xd5>
lea    0xdd1(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x58(%rbp),%rax
movslq -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    12c4 <main+0x154>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%edi
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
mov    -0x50(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    12aa <main+0x13a>
lea    0xd7f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x50(%rbp),%rdi
call   1060 <PrintResult@plt>
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
jmp    125c <main+0xec>
mov    -0x48(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e42(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%r15
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
call   1040 <check_args@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
test   %eax,%eax
jns    11c7 <main+0x57>
lea    0xe3e(%rip),%rdi
jmp    124a <main+0xda>
mov    %eax,%r14d
mov    %ebx,-0x30(%rbp)
mov    %r15,-0x28(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
mov    %r14d,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
jns    11f3 <main+0x83>
lea    0xe16(%rip),%rdi
jmp    124a <main+0xda>
movslq -0x30(%rbp),%rax
add    %rax,%r15
mov    -0x28(%rbp),%rbx
cmp    %r15,%rbx
jae    1234 <main+0xc4>
mov    0x2dce(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    (%r12),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
js     1243 <main+0xd3>
mov    %rbx,%rdi
call   1060 <PrintResult@plt>
add    $0x4,%rbx
cmp    %r15,%rbx
jb     1210 <main+0xa0>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xdd0(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.ifconf = type { i32, i8* }
%struct.ifreq = type { i32 }
@BUFSIZ = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SIOCGIFCONF = global i32 0
@.str.1 = [19 x i8] c"ioctl: SIOCGIFCONF\00"
@SIOCGIFFLAGS = global i32 0
@.str.2 = [21 x i8] c"ioctl : SIOCGIFFLAGS\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.ifconf
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.ifreq*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @BUFSIZ
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %7
%17 = alloca i8, i64 %15
store i64 %15, i64* %8
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @check_args(i32 %18, i8** %19)
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %2
%27 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %2
%30 = trunc i64 %15 to i32
%31 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %6, i32 0, i32 0
store i32 %30, i32* %31
%32 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %6, i32 0, i32 1
store i8* %17, i8** %32
%33 = load i32, i32* %12
%34 = load i32, i32* @SIOCGIFCONF
%35 = bitcast %struct.ifconf* %6 to i8*
%36 = call i32 @ioctl(i32 %33, i32 %34, i8* %35)
store i32 %36, i32* %11
%37 = load i32, i32* %11
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %29
%40 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %29
%43 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %6, i32 0, i32 0
%44 = load i32, i32* %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %17, i64 %45
store i8* %46, i8** %10
%47 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %6, i32 0, i32 1
%48 = load i8*, i8** %47
store i8* %48, i8** %9
br label %49
49: ; preds = %69, %42
%50 = load i8*, i8** %9
%51 = load i8*, i8** %10
%52 = icmp ult i8* %50, %51
br i1 %52, label %53, label %72
53: ; preds = %49
%54 = load i8*, i8** %9
%55 = bitcast i8* %54 to %struct.ifreq*
store %struct.ifreq* %55, %struct.ifreq** %13
%56 = load i32, i32* %12
%57 = load i32, i32* @SIOCGIFFLAGS
%58 = load %struct.ifreq*, %struct.ifreq** %13
%59 = bitcast %struct.ifreq* %58 to i8*
%60 = call i32 @ioctl(i32 %56, i32 %57, i8* %59)
store i32 %60, i32* %11
%61 = load i32, i32* %11
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %53
%64 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %53
%67 = load %struct.ifreq*, %struct.ifreq** %13
%68 = call i32 @PrintResult(%struct.ifreq* %67)
br label %69
69: ; preds = %66
%70 = load i8*, i8** %9
%71 = getelementptr inbounds i8, i8* %70, i64 4
store i8* %71, i8** %9
br label %49
72: ; preds = %49
%73 = load i32, i32* %12
%74 = call i32 @close(i32 %73)
%75 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.ifconf = type { i32, i8* }
%struct.ifreq = type { i32 }
@BUFSIZ = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SIOCGIFCONF = global i32 0
@.str.1 = [19 x i8] c"ioctl: SIOCGIFCONF\00"
@SIOCGIFFLAGS = global i32 0
@.str.2 = [21 x i8] c"ioctl : SIOCGIFFLAGS\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.ifconf
%4 = bitcast %struct.ifconf* %3 to i8*
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = tail call i32 @check_args(i32 %0, i8** %1)
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %3, i64 0, i32 0
store i32 %5, i32* %17
%18 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %3, i64 0, i32 1
store i8* %7, i8** %18
%19 = load i32, i32* @SIOCGIFCONF
%20 = call i32 @ioctl(i32 %11, i32 %19, i8* %4)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %16
%26 = load i32, i32* %17
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %7, i64 %27
%29 = load i8*, i8** %18
%30 = icmp ult i8* %29, %28
br i1 %30, label %31, label %44
31: ; preds = %25, %39
%32 = phi i8* [ %42, %39 ], [ %29, %25 ]
%33 = load i32, i32* @SIOCGIFFLAGS
%34 = call i32 @ioctl(i32 %11, i32 %33, i8* %32)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = bitcast i8* %32 to %struct.ifreq*
%41 = call i32 @PrintResult(%struct.ifreq* %40)
%42 = getelementptr inbounds i8, i8* %32, i64 4
%43 = icmp ult i8* %42, %28
br i1 %43, label %31, label %44
44: ; preds = %39, %25
%45 = call i32 @close(i32 %11)
%46 = call i32 @exit(i32 0)
unreachable
}