#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 */

/* Variables and functions */
int /*<<< orphan*/ ifconfigCheckCopyInput(char *, int, char const *, int const);
int ifconfigExec(char *);
int /*<<< orphan*/ ifconfigSplit(char *, int, char *, int, char const *,
                                 int const, char);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ strlen(char *);
int ifconfig6(const char *ifname, const int ifname_len, const char *addr,
              const int addr_len) {
  char cmd[1024];
  memset(cmd, 0, 1024);
  char ifname_s[256];
  memset(ifname_s, 0, 256);
  char ip_s[256];
  memset(ip_s, 0, 256);
  char prefixlen_s[4];
  memset(prefixlen_s, 0, 4);
  int ret;
  if (!ifconfigCheckCopyInput(ifname_s, 256, ifname, ifname_len))
    return 0;
  if (!ifconfigSplit(ip_s, 256, prefixlen_s, 4, addr, addr_len, '/'))
    return 0;
  if (strlen(prefixlen_s) == 0)
    memcpy(prefixlen_s, "128", 2);
  sprintf(cmd, "ip link set dev \"%s\" up", ifname_s);
  ret = ifconfigExec(cmd);
  if (ret == 0) {
    sprintf(cmd, "ip -6 addr flush dev \"%s\" scope global", ifname_s);
    ret = ifconfigExec(cmd);
    if (ret != 0) {
      return 0;
    }
    sprintf(cmd, "ip -6 addr add dev \"%s\" \"%s/%s\" scope global", ifname_s,
            ip_s, prefixlen_s);
    ret = ifconfigExec(cmd);
    if (ret != 0) {
      return 0;
    }
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ifconfig6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x640,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x530(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    -0x630(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    -0x634(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
lea    -0x530(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x100,%esi
call   1030 <ifconfigCheckCopyInput@plt>
cmp    $0x0,%eax
jne    1202 <ifconfig6+0x92>
movl   $0x0,-0x4(%rbp)
jmp    135b <ifconfig6+0x1eb>
lea    -0x630(%rbp),%rdi
lea    -0x634(%rbp),%rdx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
mov    $0x100,%esi
mov    $0x4,%ecx
movl   $0x2f,(%rsp)
call   1050 <ifconfigSplit@plt>
cmp    $0x0,%eax
jne    1243 <ifconfig6+0xd3>
movl   $0x0,-0x4(%rbp)
jmp    135b <ifconfig6+0x1eb>
lea    -0x634(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    1271 <ifconfig6+0x101>
lea    -0x634(%rbp),%rdi
lea    0xd99(%rip),%rsi
mov    $0x2,%edx
call   1080 <memcpy@plt>
lea    -0x430(%rbp),%rdi
lea    -0x530(%rbp),%rdx
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x430(%rbp),%rdi
call   1060 <ifconfigExec@plt>
mov    %eax,-0x638(%rbp)
cmpl   $0x0,-0x638(%rbp)
jne    1354 <ifconfig6+0x1e4>
lea    -0x430(%rbp),%rdi
lea    -0x530(%rbp),%rdx
lea    0xd5b(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x430(%rbp),%rdi
call   1060 <ifconfigExec@plt>
mov    %eax,-0x638(%rbp)
cmpl   $0x0,-0x638(%rbp)
je     12f3 <ifconfig6+0x183>
movl   $0x0,-0x4(%rbp)
jmp    135b <ifconfig6+0x1eb>
lea    -0x430(%rbp),%rdi
lea    -0x530(%rbp),%rdx
lea    -0x630(%rbp),%rcx
lea    -0x634(%rbp),%r8
lea    0xd2d(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x430(%rbp),%rdi
call   1060 <ifconfigExec@plt>
mov    %eax,-0x638(%rbp)
cmpl   $0x0,-0x638(%rbp)
je     1348 <ifconfig6+0x1d8>
movl   $0x0,-0x4(%rbp)
jmp    135b <ifconfig6+0x1eb>
movl   $0x1,-0x4(%rbp)
jmp    135b <ifconfig6+0x1eb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x640,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ifconfig6>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x618,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x210(%rsp),%rdi
xor    %r12d,%r12d
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    0x10(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    0x110(%rsp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    %r13,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1030 <ifconfigCheckCopyInput@plt>
test   %eax,%eax
je     12ca <ifconfig6+0x16a>
movl   $0x2f,(%rsp)
lea    0x110(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0x100,%esi
mov    $0x4,%ecx
mov    %r15,%r8
mov    %r14d,%r9d
call   1040 <ifconfigSplit@plt>
test   %eax,%eax
je     12ca <ifconfig6+0x16a>
cmpb   $0x0,0xc(%rsp)
jne    1234 <ifconfig6+0xd4>
lea    0xddb(%rip),%rsi
lea    0xc(%rsp),%rdi
mov    $0x2,%edx
call   1070 <memcpy@plt>
lea    0xdc9(%rip),%rsi
xor    %r12d,%r12d
lea    0x210(%rsp),%rbx
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <ifconfigExec@plt>
test   %eax,%eax
jne    12ca <ifconfig6+0x16a>
lea    0xdb4(%rip),%rsi
xor    %r12d,%r12d
lea    0x210(%rsp),%rbx
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <ifconfigExec@plt>
test   %eax,%eax
jne    12ca <ifconfig6+0x16a>
lea    0xdae(%rip),%rsi
lea    0x210(%rsp),%rbx
lea    0x10(%rsp),%rdx
lea    0x110(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <ifconfigExec@plt>
xor    %r12d,%r12d
test   %eax,%eax
sete   %r12b
mov    %r12d,%eax
add    $0x618,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"128\00"
@.str.1 = [24 x i8] c"ip link set dev \22%s\22 up\00"
@.str.2 = [39 x i8] c"ip -6 addr flush dev \22%s\22 scope global\00"
@.str.3 = [45 x i8] c"ip -6 addr add dev \22%s\22 \22%s/%s\22 scope global\00"
define i32 @ifconfig6(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca [256 x i8]
%12 = alloca [256 x i8]
%13 = alloca [4 x i8]
%14 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 1024)
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 256)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 256)
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i32 0, i32 4)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = call i32 @ifconfigCheckCopyInput(i8* %23, i32 256, i8* %24, i32 %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %4
store i32 0, i32* %5
br label %74
29: ; preds = %4
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%32 = load i8*, i8** %8
%33 = load i32, i32* %9
%34 = call i32 @ifconfigSplit(i8* %30, i32 256, i8* %31, i32 4, i8* %32, i32 %33, i8 signext 47)
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %29
store i32 0, i32* %5
br label %74
37: ; preds = %29
%38 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%39 = call i64 @strlen(i8* %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%43 = call i32 @memcpy(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 2)
br label %44
44: ; preds = %41, %37
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%47 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %45, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %46)
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%49 = call i32 @ifconfigExec(i8* %48)
store i32 %49, i32* %14
%50 = load i32, i32* %14
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %73
52: ; preds = %44
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%55 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %53, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %54)
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%57 = call i32 @ifconfigExec(i8* %56)
store i32 %57, i32* %14
%58 = load i32, i32* %14
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %52
store i32 0, i32* %5
br label %74
61: ; preds = %52
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%65 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%66 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %62, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %63, i8* %64, i8* %65)
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%68 = call i32 @ifconfigExec(i8* %67)
store i32 %68, i32* %14
%69 = load i32, i32* %14
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %61
store i32 0, i32* %5
br label %74
72: ; preds = %61
store i32 1, i32* %5
br label %74
73: ; preds = %44
store i32 0, i32* %5
br label %74
74: ; preds = %73, %72, %71, %60, %36, %28
%75 = load i32, i32* %5
ret i32 %75
}

LLVM IR (-O2):
@.str = [4 x i8] c"128\00"
@.str.1 = [24 x i8] c"ip link set dev \22%s\22 up\00"
@.str.2 = [39 x i8] c"ip -6 addr flush dev \22%s\22 scope global\00"
@.str.3 = [45 x i8] c"ip -6 addr add dev \22%s\22 \22%s/%s\22 scope global\00"
define i32 @ifconfig6(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [1024 x i8]
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca [4 x i8]
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 1024)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 256)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 256)
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 4)
%17 = call i32 @ifconfigCheckCopyInput(i8* %11, i32 256, i8* %0, i32 %1)
%18 = icmp eq i32 %17, 0
br i1 %18, label %40, label %19
19: ; preds = %4
%20 = call i32 @ifconfigSplit(i8* %13, i32 256, i8* %15, i32 4, i8* %2, i32 %3, i8 signext 47)
%21 = icmp eq i32 %20, 0
br i1 %21, label %40, label %22
22: ; preds = %19
%23 = load i8, i8* %15
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @memcpy(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 2)
br label %27
27: ; preds = %25, %22
%28 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%29 = call i32 @ifconfigExec(i8* %9)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%33 = call i32 @ifconfigExec(i8* %9)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %11, i8* %13, i8* %15)
%37 = call i32 @ifconfigExec(i8* %9)
%38 = icmp eq i32 %37, 0
%39 = zext i1 %38 to i32
br label %40
40: ; preds = %27, %35, %31, %19, %4
%41 = phi i32 [ 0, %4 ], [ 0, %19 ], [ 0, %31 ], [ %39, %35 ], [ 0, %27 ]
ret i32 %41
}