#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 NLM_F_CREATE;
int NLM_F_EXCL;
int /*<<< orphan*/ RTM_NEWROUTE;
int /*<<< orphan*/ add_radvd_conf(char const *, char const *, int,
                                  unsigned long, unsigned long);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error_message();
int iproute_modify(int /*<<< orphan*/, int, int, char **);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, int);
int /*<<< orphan*/ sprintf(int /*<<< orphan*/, char *, char *);
char *strerror(int /*<<< orphan*/);
int prefix_add(const char *ifname, int ifindex, const char *prefixPlain,
               int prefixLength, unsigned long preferred, unsigned long valid) {
  char *argv[5];
  int result;
  char buf[128];
  int numargs = 0;
  add_radvd_conf(ifname, prefixPlain, prefixLength, preferred, valid);
  snprintf(buf, 127, "%s/%d", prefixPlain, prefixLength);
  argv[0] = buf;
  argv[1] = "dev";
  argv[2] = (char *)ifname;
  numargs = 3;
  result =
      iproute_modify(RTM_NEWROUTE, NLM_F_CREATE | NLM_F_EXCL, numargs, argv);
  if (result == 0)
    return 0;
  else {
    sprintf(error_message(), "Unable to add prefix: %s", strerror(errno));
    return -1;
  }
}


x86 assembly (clang, -O0):
<prefix_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movl   $0x0,-0xf4(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1040 <add_radvd_conf@plt>
lea    -0xf0(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    $0x7f,%esi
lea    0xe42(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0xf0(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    0xe31(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
movl   $0x3,-0xf4(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
mov    0x2dd4(%rip),%rax
or     (%rax),%esi
mov    -0xf4(%rbp),%edx
lea    -0x60(%rbp),%rcx
call   1050 <iproute_modify@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jne    122e <prefix_add+0xce>
movl   $0x0,-0x4(%rbp)
jmp    1265 <prefix_add+0x105>
mov    $0x0,%al
call   1060 <error_message@plt>
mov    %eax,-0xf8(%rbp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0xf8(%rbp),%edi
mov    %rax,%rdx
lea    0xdb1(%rip),%rsi
call   1070 <sprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prefix_add>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xb8,%rsp
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %rdi,%r14
mov    %rdx,%rsi
mov    %ecx,%edx
mov    %r8,%rcx
mov    %r9,%r8
call   1040 <add_radvd_conf@plt>
lea    0xe74(%rip),%rdx
lea    0x30(%rsp),%r15
mov    %r15,%rdi
mov    $0x7f,%esi
mov    %rbx,%rcx
mov    %ebp,%r8d
call   1030 <snprintf@plt>
mov    %r15,(%rsp)
lea    0xe57(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    0x2e1f(%rip),%rax
mov    0x2e08(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rsp,%rcx
mov    $0x3,%edx
call   1050 <iproute_modify@plt>
test   %eax,%eax
je     1214 <prefix_add+0xb4>
xor    %eax,%eax
call   1060 <error_message@plt>
mov    %eax,%ebx
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe07(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <sprintf@plt>
mov    $0xffffffff,%eax
jmp    1216 <prefix_add+0xb6>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%d\00"
@.str.1 = [4 x i8] c"dev\00"
@RTM_NEWROUTE = global i32 0
@NLM_F_CREATE = global i32 0
@NLM_F_EXCL = global i32 0
@.str.2 = [25 x i8] c"Unable to add prefix: %s\00"
@errno = global i32 0
define i32 @prefix_add(i8* %0, i32 %1, i8* %2, i32 %3, i64 %4, i64 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca [5 x i8*]
%15 = alloca i32
%16 = alloca [128 x i8]
%17 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i64 %4, i64* %12
store i64 %5, i64* %13
store i32 0, i32* %17
%18 = load i8*, i8** %8
%19 = load i8*, i8** %10
%20 = load i32, i32* %11
%21 = load i64, i64* %12
%22 = load i64, i64* %13
%23 = call i32 @add_radvd_conf(i8* %18, i8* %19, i32 %20, i64 %21, i64 %22)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%25 = load i8*, i8** %10
%26 = load i32, i32* %11
%27 = call i32 @snprintf(i8* %24, i32 127, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %26)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%29 = getelementptr inbounds [5 x i8*], [5 x i8*]* %14, i64 0, i64 0
store i8* %28, i8** %29
%30 = getelementptr inbounds [5 x i8*], [5 x i8*]* %14, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %30
%31 = load i8*, i8** %8
%32 = getelementptr inbounds [5 x i8*], [5 x i8*]* %14, i64 0, i64 2
store i8* %31, i8** %32
store i32 3, i32* %17
%33 = load i32, i32* @RTM_NEWROUTE
%34 = load i32, i32* @NLM_F_CREATE
%35 = load i32, i32* @NLM_F_EXCL
%36 = or i32 %34, %35
%37 = load i32, i32* %17
%38 = getelementptr inbounds [5 x i8*], [5 x i8*]* %14, i64 0, i64 0
%39 = call i32 @iproute_modify(i32 %33, i32 %36, i32 %37, i8** %38)
store i32 %39, i32* %15
%40 = load i32, i32* %15
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %6
store i32 0, i32* %7
br label %48
43: ; preds = %6
%44 = call i32 (...) @error_message()
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 @sprintf(i32 %44, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %46)
store i32 -1, i32* %7
br label %48
48: ; preds = %43, %42
%49 = load i32, i32* %7
ret i32 %49
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%d\00"
@.str.1 = [4 x i8] c"dev\00"
@RTM_NEWROUTE = global i32 0
@NLM_F_CREATE = global i32 0
@NLM_F_EXCL = global i32 0
@.str.2 = [25 x i8] c"Unable to add prefix: %s\00"
@errno = global i32 0
define i32 @prefix_add(i8* %0, i32 %1, i8* %2, i32 %3, i64 %4, i64 %5) {
%7 = alloca [5 x i8*]
%8 = alloca [128 x i8]
%9 = bitcast [5 x i8*]* %7 to i8*
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%11 = tail call i32 @add_radvd_conf(i8* %0, i8* %2, i32 %3, i64 %4, i64 %5)
%12 = call i32 @snprintf(i8* %10, i32 127, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %3)
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i64 0, i64 0
store i8* %10, i8** %13
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i64 0, i64 2
store i8* %0, i8** %15
%16 = load i32, i32* @RTM_NEWROUTE
%17 = load i32, i32* @NLM_F_CREATE
%18 = load i32, i32* @NLM_F_EXCL
%19 = or i32 %18, %17
%20 = call i32 @iproute_modify(i32 %16, i32 %19, i32 3, i8** %13)
%21 = icmp eq i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %6
%23 = call i32 (...) @error_message()
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @sprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %6, %22
%28 = phi i32 [ -1, %22 ], [ 0, %6 ]
ret i32 %28
}