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


x86 assembly (clang, -O0):
<prefix_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%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)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <delete_radvd_conf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1050 <add_radvd_conf@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    $0x7f,%esi
lea    0xe2c(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0xe0(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    0xe1b(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
mov    0x2de0(%rip),%rax
or     (%rax),%esi
lea    -0x50(%rbp),%rcx
mov    $0x3,%edx
call   1060 <iproute_modify@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jne    1239 <prefix_update+0xc9>
movl   $0x0,-0x4(%rbp)
jmp    1270 <prefix_update+0x100>
mov    $0x0,%al
call   1070 <error_message@plt>
mov    %eax,-0xe4(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0xe4(%rbp),%edi
mov    %rax,%rdx
lea    0xda6(%rip),%rsi
call   1080 <sprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prefix_update>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa0,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %rdi,%r12
mov    %rdx,%rsi
mov    %ecx,%edx
call   1030 <delete_radvd_conf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1050 <add_radvd_conf@plt>
lea    0xe4f(%rip),%rdx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x7f,%esi
mov    %rbx,%rcx
mov    %ebp,%r8d
call   1040 <snprintf@plt>
mov    %r14,(%rsp)
lea    0xe32(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %r12,0x10(%rsp)
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    0x2df2(%rip),%rax
mov    0x2dfb(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rsp,%rcx
mov    $0x3,%edx
call   1060 <iproute_modify@plt>
test   %eax,%eax
je     1239 <prefix_update+0xc9>
xor    %eax,%eax
call   1070 <error_message@plt>
mov    %eax,%ebx
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xde2(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <sprintf@plt>
mov    $0xffffffff,%eax
jmp    123b <prefix_update+0xcb>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r12
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_REPLACE = global i32 0
@.str.2 = [28 x i8] c"Unable to update prefix: %s\00"
@errno = global i32 0
define i32 @prefix_update(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 [3 x i8*]
%15 = alloca i32
%16 = alloca [128 x i8]
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
%17 = load i8*, i8** %8
%18 = load i8*, i8** %10
%19 = load i32, i32* %11
%20 = call i32 @delete_radvd_conf(i8* %17, i8* %18, i32 %19)
%21 = load i8*, i8** %8
%22 = load i8*, i8** %10
%23 = load i32, i32* %11
%24 = load i64, i64* %12
%25 = load i64, i64* %13
%26 = call i32 @add_radvd_conf(i8* %21, i8* %22, i32 %23, i64 %24, i64 %25)
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%28 = load i8*, i8** %10
%29 = load i32, i32* %11
%30 = call i32 @snprintf(i8* %27, i32 127, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %28, i32 %29)
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%32 = getelementptr inbounds [3 x i8*], [3 x i8*]* %14, i64 0, i64 0
store i8* %31, i8** %32
%33 = getelementptr inbounds [3 x i8*], [3 x i8*]* %14, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %33
%34 = load i8*, i8** %8
%35 = getelementptr inbounds [3 x i8*], [3 x i8*]* %14, i64 0, i64 2
store i8* %34, i8** %35
%36 = load i32, i32* @RTM_NEWROUTE
%37 = load i32, i32* @NLM_F_CREATE
%38 = load i32, i32* @NLM_F_REPLACE
%39 = or i32 %37, %38
%40 = getelementptr inbounds [3 x i8*], [3 x i8*]* %14, i64 0, i64 0
%41 = call i32 @iproute_modify(i32 %36, i32 %39, i32 3, i8** %40)
store i32 %41, i32* %15
%42 = load i32, i32* %15
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %6
store i32 0, i32* %7
br label %50
45: ; preds = %6
%46 = call i32 (...) @error_message()
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 @sprintf(i32 %46, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %48)
store i32 -1, i32* %7
br label %50
50: ; preds = %45, %44
%51 = load i32, i32* %7
ret i32 %51
}

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_REPLACE = global i32 0
@.str.2 = [28 x i8] c"Unable to update prefix: %s\00"
@errno = global i32 0
define i32 @prefix_update(i8* %0, i32 %1, i8* %2, i32 %3, i64 %4, i64 %5) {
%7 = alloca [3 x i8*]
%8 = alloca [128 x i8]
%9 = bitcast [3 x i8*]* %7 to i8*
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%11 = tail call i32 @delete_radvd_conf(i8* %0, i8* %2, i32 %3)
%12 = tail call i32 @add_radvd_conf(i8* %0, i8* %2, i32 %3, i64 %4, i64 %5)
%13 = 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)
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
store i8* %10, i8** %14
%15 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 2
store i8* %0, i8** %16
%17 = load i32, i32* @RTM_NEWROUTE
%18 = load i32, i32* @NLM_F_CREATE
%19 = load i32, i32* @NLM_F_REPLACE
%20 = or i32 %19, %18
%21 = call i32 @iproute_modify(i32 %17, i32 %20, i32 3, i8** %14)
%22 = icmp eq i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %6
%24 = call i32 (...) @error_message()
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 @sprintf(i32 %24, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %6, %23
%29 = phi i32 [ -1, %23 ], [ 0, %6 ]
ret i32 %29
}