#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 ifc_len;
  char *ifr_name;
  int /*<<< orphan*/ ifr_flags;
  struct ifreq *ifc_req;
};
struct ifconf {
  int ifc_len;
  char *ifr_name;
  int /*<<< orphan*/ ifr_flags;
  struct ifconf *ifc_req;
};
typedef int /*<<< orphan*/ ifr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IFF_UP;
int /*<<< orphan*/ SIOCGIFCONF;
int /*<<< orphan*/ SIOCSIFFLAGS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int ifdown(void) {
  struct ifreq ifr[64];
  struct ifconf ifc;
  int i, fd;
  int numif;
  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    fprintf(stderr, "ifdown: ");
    perror("socket");
    return -1;
  }
  ifc.ifc_len = sizeof(ifr);
  ifc.ifc_req = ifr;
  if (ioctl(fd, SIOCGIFCONF, &ifc) < 0) {
    fprintf(stderr, "ifdown: ");
    perror("SIOCGIFCONF");
    close(fd);
    return -1;
  }
  numif = ifc.ifc_len / sizeof(struct ifreq);
  for (i = 0; i < numif; i++) {
    if (strcmp(ifr[i].ifr_name, "lo") == 0)
      continue;
    if (strchr(ifr[i].ifr_name, ':') != NULL)
      continue;
    ifr[i].ifr_flags &= ~(IFF_UP);
    if (ioctl(fd, SIOCSIFFLAGS, &ifr[i]) < 0) {
      fprintf(stderr, "ifdown: shutdown ");
      perror(ifr[i].ifr_name);
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<ifdown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x838(%rbp)
cmp    $0x0,%eax
jge    11d0 <ifdown+0x60>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xe4a(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1390 <ifdown+0x220>
movl   $0x800,-0x830(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x818(%rbp)
mov    -0x838(%rbp),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
lea    -0x830(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1245 <ifdown+0xd5>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xde7(%rip),%rdi
call   1080 <perror@plt>
mov    -0x838(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1390 <ifdown+0x220>
movslq -0x830(%rbp),%rax
shr    $0x5,%rax
mov    %eax,-0x83c(%rbp)
movl   $0x0,-0x834(%rbp)
mov    -0x834(%rbp),%eax
cmp    -0x83c(%rbp),%eax
jge    137e <ifdown+0x20e>
movslq -0x834(%rbp),%rcx
lea    -0x810(%rbp),%rax
shl    $0x5,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rdi
lea    0xd8a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12a6 <ifdown+0x136>
jmp    136a <ifdown+0x1fa>
movslq -0x834(%rbp),%rcx
lea    -0x810(%rbp),%rax
shl    $0x5,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     12d8 <ifdown+0x168>
jmp    136a <ifdown+0x1fa>
mov    0x2cf9(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
movslq -0x834(%rbp),%rdx
lea    -0x810(%rbp),%rax
shl    $0x5,%rdx
add    %rdx,%rax
and    0x10(%rax),%ecx
mov    %ecx,0x10(%rax)
mov    -0x838(%rbp),%edi
mov    0x2cec(%rip),%rax
mov    (%rax),%esi
movslq -0x834(%rbp),%rax
lea    -0x810(%rbp),%rdx
shl    $0x5,%rax
add    %rax,%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1365 <ifdown+0x1f5>
mov    0x2c87(%rip),%rax
mov    (%rax),%edi
lea    0xcdd(%rip),%rsi
call   1070 <fprintf@plt>
movslq -0x834(%rbp),%rcx
lea    -0x810(%rbp),%rax
shl    $0x5,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rdi
call   1080 <perror@plt>
jmp    136a <ifdown+0x1fa>
mov    -0x834(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x834(%rbp)
jmp    1260 <ifdown+0xf0>
mov    -0x838(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ifdown>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
test   %eax,%eax
js     1286 <ifdown+0x116>
mov    %eax,%r14d
movl   $0x800,(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,0x18(%rsp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r14d,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     12ae <ifdown+0x13e>
mov    (%rsp),%ebp
cmp    $0x20,%ebp
jl     126a <ifdown+0xfa>
shr    $0x5,%rbp
lea    0xe32(%rip),%r12
mov    0x2de7(%rip),%r13
mov    0x2e00(%rip),%r15
jmp    120a <ifdown+0x9a>
nopw   0x0(%rax,%rax,1)
add    $0x20,%rbx
add    $0xffffffffffffffff,%rbp
je     126a <ifdown+0xfa>
mov    0x8(%rbx),%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1200 <ifdown+0x90>
mov    0x8(%rbx),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1200 <ifdown+0x90>
mov    0x0(%r13),%eax
not    %eax
and    %eax,0x10(%rbx)
mov    (%r15),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
jns    1200 <ifdown+0x90>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x8(%rbx),%rdi
call   1080 <perror@plt>
jmp    1200 <ifdown+0x90>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xd67(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
jmp    1274 <ifdown+0x104>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xd46(%rip),%rdi
call   1080 <perror@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    $0xffffffff,%eax
jmp    1274 <ifdown+0x104>

LLVM IR (-O0):
%struct.ifreq = type { i32, i8*, i32, %struct.ifreq* }
%struct.ifconf = type { i32, i8*, i32, %struct.ifconf* }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [9 x i8] c"ifdown: \00"
@.str.1 = [7 x i8] c"socket\00"
@SIOCGIFCONF = global i32 0
@.str.2 = [12 x i8] c"SIOCGIFCONF\00"
@.str.3 = [3 x i8] c"lo\00"
@IFF_UP = global i32 0
@SIOCSIFFLAGS = global i32 0
@.str.4 = [18 x i8] c"ifdown: shutdown \00"
define i32 @ifdown() {
%1 = alloca i32
%2 = alloca [64 x %struct.ifreq]
%3 = alloca %struct.ifconf
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %91
15: ; preds = %0
%16 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %3, i32 0, i32 0
store i32 2048, i32* %16
%17 = getelementptr inbounds [64 x %struct.ifreq], [64 x %struct.ifreq]* %2, i64 0, i64 0
%18 = bitcast %struct.ifreq* %17 to %struct.ifconf*
%19 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %3, i32 0, i32 3
store %struct.ifconf* %18, %struct.ifconf** %19
%20 = load i32, i32* %5
%21 = load i32, i32* @SIOCGIFCONF
%22 = bitcast %struct.ifconf* %3 to %struct.ifreq*
%23 = call i64 @ioctl(i32 %20, i32 %21, %struct.ifreq* %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* %5
%30 = call i32 @close(i32 %29)
store i32 -1, i32* %1
br label %91
31: ; preds = %15
%32 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %3, i32 0, i32 0
%33 = load i32, i32* %32
%34 = sext i32 %33 to i64
%35 = udiv i64 %34, 32
%36 = trunc i64 %35 to i32
store i32 %36, i32* %6
store i32 0, i32* %4
br label %37
37: ; preds = %85, %31
%38 = load i32, i32* %4
%39 = load i32, i32* %6
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %88
41: ; preds = %37
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [64 x %struct.ifreq], [64 x %struct.ifreq]* %2, i64 0, i64 %43
%45 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %44, i32 0, i32 1
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %41
br label %85
50: ; preds = %41
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [64 x %struct.ifreq], [64 x %struct.ifreq]* %2, i64 0, i64 %52
%54 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %53, i32 0, i32 1
%55 = load i8*, i8** %54
%56 = call i32* @strchr(i8* %55, i8 signext 58)
%57 = icmp ne i32* %56, null
br i1 %57, label %58, label %59
58: ; preds = %50
br label %85
59: ; preds = %50
%60 = load i32, i32* @IFF_UP
%61 = xor i32 %60, -1
%62 = load i32, i32* %4
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [64 x %struct.ifreq], [64 x %struct.ifreq]* %2, i64 0, i64 %63
%65 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %64, i32 0, i32 2
%66 = load i32, i32* %65
%67 = and i32 %66, %61
store i32 %67, i32* %65
%68 = load i32, i32* %5
%69 = load i32, i32* @SIOCSIFFLAGS
%70 = load i32, i32* %4
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [64 x %struct.ifreq], [64 x %struct.ifreq]* %2, i64 0, i64 %71
%73 = call i64 @ioctl(i32 %68, i32 %69, %struct.ifreq* %72)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %84
75: ; preds = %59
%76 = load i32, i32* @stderr
%77 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%78 = load i32, i32* %4
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [64 x %struct.ifreq], [64 x %struct.ifreq]* %2, i64 0, i64 %79
%81 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %80, i32 0, i32 1
%82 = load i8*, i8** %81
%83 = call i32 @perror(i8* %82)
br label %84
84: ; preds = %75, %59
br label %85
85: ; preds = %84, %58, %49
%86 = load i32, i32* %4
%87 = add nsw i32 %86, 1
store i32 %87, i32* %4
br label %37
88: ; preds = %37
%89 = load i32, i32* %5
%90 = call i32 @close(i32 %89)
store i32 0, i32* %1
br label %91
91: ; preds = %88, %25, %11
%92 = load i32, i32* %1
ret i32 %92
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i8*, i32, %struct.ifreq* }
%struct.ifconf = type { i32, i8*, i32, %struct.ifconf* }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [9 x i8] c"ifdown: \00"
@.str.1 = [7 x i8] c"socket\00"
@SIOCGIFCONF = global i32 0
@.str.2 = [12 x i8] c"SIOCGIFCONF\00"
@.str.3 = [3 x i8] c"lo\00"
@IFF_UP = global i32 0
@SIOCSIFFLAGS = global i32 0
@.str.4 = [18 x i8] c"ifdown: shutdown \00"
define i32 @ifdown() {
%1 = alloca [64 x %struct.ifreq]
%2 = alloca %struct.ifconf
%3 = bitcast [64 x %struct.ifreq]* %1 to i8*
%4 = bitcast %struct.ifconf* %2 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %62
13: ; preds = %0
%14 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %2, i64 0, i32 0
store i32 2048, i32* %14
%15 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %2, i64 0, i32 3
%16 = bitcast %struct.ifconf** %15 to [64 x %struct.ifreq]**
store [64 x %struct.ifreq]* %1, [64 x %struct.ifreq]** %16
%17 = load i32, i32* @SIOCGIFCONF
%18 = bitcast %struct.ifconf* %2 to %struct.ifreq*
%19 = call i64 @ioctl(i32 %7, i32 %17, %struct.ifreq* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @close(i32 %7)
br label %62
26: ; preds = %13
%27 = load i32, i32* %14
%28 = icmp sgt i32 %27, 31
br i1 %28, label %29, label %60
29: ; preds = %26
%30 = lshr i32 %27, 5
%31 = zext i32 %30 to i64
br label %32
32: ; preds = %29, %57
%33 = phi i64 [ 0, %29 ], [ %58, %57 ]
%34 = getelementptr inbounds [64 x %struct.ifreq], [64 x %struct.ifreq]* %1, i64 0, i64 %33
%35 = getelementptr inbounds [64 x %struct.ifreq], [64 x %struct.ifreq]* %1, i64 0, i64 %33, i32 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %57, label %39
39: ; preds = %32
%40 = load i8*, i8** %35
%41 = call i32* @strchr(i8* %40, i8 signext 58)
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %57
43: ; preds = %39
%44 = load i32, i32* @IFF_UP
%45 = xor i32 %44, -1
%46 = getelementptr inbounds [64 x %struct.ifreq], [64 x %struct.ifreq]* %1, i64 0, i64 %33, i32 2
%47 = load i32, i32* %46
%48 = and i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @SIOCSIFFLAGS
%50 = call i64 @ioctl(i32 %7, i32 %49, %struct.ifreq* %34)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %43
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%55 = load i8*, i8** %35
%56 = call i32 @perror(i8* %55)
br label %57
57: ; preds = %43, %52, %39, %32
%58 = add nuw nsw i64 %33, 1
%59 = icmp eq i64 %58, %31
br i1 %59, label %60, label %32
60: ; preds = %57, %26
%61 = call i32 @close(i32 %7)
br label %62
62: ; preds = %60, %21, %9
%63 = phi i32 [ -1, %9 ], [ -1, %21 ], [ 0, %60 ]
ret i32 %63
}