#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 ifr_flags;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ req;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int IFF_UP;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SIOCSIFFLAGS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int ifdown(void) {
  int inet6_fd;
  struct ifreq req;
  inet6_fd = socket(AF_INET6, SOCK_DGRAM, 0);
  if (inet6_fd < 0) {
    perror("socket");
    return 0;
  }
  memset(&req, 0, sizeof(req));
  strcpy(req.ifr_name, "eth0");
  if (ioctl(inet6_fd, SIOCGIFFLAGS, &req) < 0) {
    perror("ioctl");
    close(inet6_fd);
    return 0;
  }
  if (req.ifr_flags & IFF_UP) {
    req.ifr_flags &= ~IFF_UP;
    if (ioctl(inet6_fd, SIOCSIFFLAGS, &req) < 0) {
      perror("ioctl");
      close(inet6_fd);
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<ifdown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a6 <ifdown+0x46>
lea    0xe6b(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1276 <ifdown+0x116>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%edi
lea    0xe47(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1204 <ifdown+0xa4>
lea    0xe21(%rip),%rdi
call   1070 <perror@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1276 <ifdown+0x116>
mov    -0x10(%rbp),%eax
mov    0x2dd2(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     126f <ifdown+0x10f>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    126a <ifdown+0x10a>
lea    0xdbb(%rip),%rdi
call   1070 <perror@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1276 <ifdown+0x116>
jmp    126f <ifdown+0x10f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ifdown>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     120e <ifdown+0xae>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0xc(%rsp),%edi
lea    0xe59(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
js     121c <ifdown+0xbc>
mov    0x8(%rsp),%eax
mov    0x2e0a(%rip),%rcx
mov    (%rcx),%ecx
mov    $0x1,%ebx
test   %eax,%ecx
je     1203 <ifdown+0xa3>
not    %ecx
and    %ecx,%eax
mov    %eax,0x8(%rsp)
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
test   %rax,%rax
js     1231 <ifdown+0xd1>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdeb(%rip),%rdi
call   1070 <perror@plt>
jmp    1203 <ifdown+0xa3>
lea    0xde9(%rip),%rdi
call   1070 <perror@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    1203 <ifdown+0xa3>
lea    0xdd4(%rip),%rdi
call   1070 <perror@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %ebx,%ebx
jmp    1203 <ifdown+0xa3>

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [5 x i8] c"eth0\00"
@SIOCGIFFLAGS = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
@IFF_UP = global i32 0
@SIOCSIFFLAGS = global i32 0
define i32 @ifdown() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.ifreq
%4 = load i32, i32* @AF_INET6
%5 = load i32, i32* @SOCK_DGRAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %46
11: ; preds = %0
%12 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 8)
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 1
%14 = load i32, i32* %13
%15 = call i32 @strcpy(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %2
%17 = load i32, i32* @SIOCGIFFLAGS
%18 = call i64 @ioctl(i32 %16, i32 %17, %struct.ifreq* %3)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %11
%21 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* %2
%23 = call i32 @close(i32 %22)
store i32 0, i32* %1
br label %46
24: ; preds = %11
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i32, i32* @IFF_UP
%28 = and i32 %26, %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %45
30: ; preds = %24
%31 = load i32, i32* @IFF_UP
%32 = xor i32 %31, -1
%33 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 0
%34 = load i32, i32* %33
%35 = and i32 %34, %32
store i32 %35, i32* %33
%36 = load i32, i32* %2
%37 = load i32, i32* @SIOCSIFFLAGS
%38 = call i64 @ioctl(i32 %36, i32 %37, %struct.ifreq* %3)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %30
%41 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* %2
%43 = call i32 @close(i32 %42)
store i32 0, i32* %1
br label %46
44: ; preds = %30
br label %45
45: ; preds = %44, %24
store i32 1, i32* %1
br label %46
46: ; preds = %45, %40, %20, %9
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [5 x i8] c"eth0\00"
@SIOCGIFFLAGS = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
@IFF_UP = global i32 0
@SIOCSIFFLAGS = global i32 0
define i32 @ifdown() {
%1 = alloca %struct.ifreq
%2 = bitcast %struct.ifreq* %1 to i8*
%3 = load i32, i32* @AF_INET6
%4 = load i32, i32* @SOCK_DGRAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %35
9: ; preds = %0
%10 = call i32 @memset(%struct.ifreq* %1, i32 0, i32 8)
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 1
%12 = load i32, i32* %11
%13 = call i32 @strcpy(i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @SIOCGIFFLAGS
%15 = call i64 @ioctl(i32 %5, i32 %14, %struct.ifreq* %1)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %9
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @close(i32 %5)
br label %35
20: ; preds = %9
%21 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 0
%22 = load i32, i32* %21
%23 = load i32, i32* @IFF_UP
%24 = and i32 %23, %22
%25 = icmp eq i32 %24, 0
br i1 %25, label %35, label %26
26: ; preds = %20
%27 = xor i32 %23, -1
%28 = and i32 %22, %27
store i32 %28, i32* %21
%29 = load i32, i32* @SIOCSIFFLAGS
%30 = call i64 @ioctl(i32 %5, i32 %29, %struct.ifreq* %1)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @close(i32 %5)
br label %35
35: ; preds = %20, %26, %32, %17, %7
%36 = phi i32 [ 0, %7 ], [ 0, %17 ], [ 0, %32 ], [ 1, %26 ], [ 1, %20 ]
ret i32 %36
}