#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 output {
  int dummy;
};
typedef int /*<<< orphan*/ echo;

/* Variables and functions */
int /*<<< orphan*/ add_output(struct output *, char *, int);
scalar_t__ do_exec(char **, int, struct output *);
int /*<<< orphan*/ is_a_device(char *);
int /*<<< orphan*/ local_net_do(char **, int, char *, char *, char *,
                                struct output *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int route_and_arp(char *dev, char *addr, char *netmask, int need_route,
                  struct output *output) {
  char echo[sizeof("echo 1 > /proc/sys/net/ipv4/conf/XXXXXXXXX/proxy_arp")];
  char *echo_argv[] = {"bash", "-c", echo, NULL};
  char *route_argv[] = {"route", "add", "-host", addr, "dev", dev, NULL};
  char *arp_argv[] = {"arp", "-Ds", addr, "eth0", "pub", NULL};
  if (!is_a_device(dev)) {
    add_output(output, "Device doesn't contain only alphanumeric characters\n",
               -1);
    return (-1);
  }
  if (do_exec(route_argv, need_route, output))
    return (-1);
  snprintf(echo, sizeof(echo) - 1,
           "echo 1 > /proc/sys/net/ipv4/conf/%.9s/proxy_arp", dev);
  do_exec(echo_argv, 0, output);
  if (netmask)
    local_net_do(arp_argv, 3, addr, netmask, dev, output);
  else
    do_exec(arp_argv, 0, output);
  return (0);
}


x86 assembly (clang, -O0):
<route_and_arp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
lea    0xe8b(%rip),%rax
mov    %rax,-0x90(%rbp)
lea    0xe82(%rip),%rax
mov    %rax,-0x88(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
movq   $0x0,-0x78(%rbp)
lea    0xe67(%rip),%rax
mov    %rax,-0xd0(%rbp)
lea    0xe5f(%rip),%rax
mov    %rax,-0xc8(%rbp)
lea    0xe55(%rip),%rax
mov    %rax,-0xc0(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    0xe42(%rip),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xa8(%rbp)
movq   $0x0,-0xa0(%rbp)
lea    0xe90(%rip),%rax
mov    %rax,-0x100(%rbp)
lea    0xe14(%rip),%rax
mov    %rax,-0xf8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    0xdff(%rip),%rax
mov    %rax,-0xe8(%rbp)
lea    0xdf6(%rip),%rax
mov    %rax,-0xe0(%rbp)
movq   $0x0,-0xd8(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <is_a_device@plt>
cmp    $0x0,%eax
jne    1274 <route_and_arp+0x124>
mov    -0x30(%rbp),%rdi
lea    0xdcb(%rip),%rsi
mov    $0xffffffff,%edx
call   1050 <add_output@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1312 <route_and_arp+0x1c2>
lea    -0xd0(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1030 <do_exec@plt>
cmp    $0x0,%rax
je     129d <route_and_arp+0x14d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1312 <route_and_arp+0x1c2>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x34,%esi
lea    0xdad(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x30(%rbp),%rdx
xor    %esi,%esi
call   1030 <do_exec@plt>
cmpq   $0x0,-0x20(%rbp)
je     12f9 <route_and_arp+0x1a9>
lea    -0x100(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    $0x3,%esi
call   1070 <local_net_do@plt>
jmp    130b <route_and_arp+0x1bb>
lea    -0x100(%rbp),%rdi
mov    -0x30(%rbp),%rdx
xor    %esi,%esi
call   1030 <do_exec@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<route_and_arp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xd0,%rsp
mov    %r8,%r15
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0xe8c(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe85(%rip),%rax
mov    %rax,0x38(%rsp)
lea    0x90(%rsp),%rax
mov    %rax,0x40(%rsp)
movq   $0x0,0x48(%rsp)
lea    0xe66(%rip),%rax
mov    %rax,0x50(%rsp)
lea    0xe60(%rip),%rax
mov    %rax,0x58(%rsp)
lea    0xe58(%rip),%rax
mov    %rax,0x60(%rsp)
mov    %rsi,0x68(%rsp)
lea    0xe4d(%rip),%rax
mov    %rax,0x70(%rsp)
mov    %rdi,0x78(%rsp)
movq   $0x0,0x80(%rsp)
lea    0xea2(%rip),%rax
mov    %rax,(%rsp)
lea    0xe29(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %rsi,0x10(%rsp)
lea    0xe1c(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe15(%rip),%rax
mov    %rax,0x20(%rsp)
movq   $0x0,0x28(%rsp)
call   1060 <is_a_device@plt>
test   %eax,%eax
je     128d <route_and_arp+0x13d>
lea    0x50(%rsp),%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   1030 <do_exec@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    12b4 <route_and_arp+0x164>
lea    0xe17(%rip),%rdx
lea    0x90(%rsp),%rdi
mov    $0x34,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
lea    0x30(%rsp),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    %r15,%rdx
call   1030 <do_exec@plt>
mov    %rsp,%rdi
test   %r14,%r14
je     12a8 <route_and_arp+0x158>
mov    $0x3,%esi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
mov    %r15,%r9
call   1070 <local_net_do@plt>
jmp    12b4 <route_and_arp+0x164>
lea    0xd95(%rip),%rsi
mov    $0xffffffff,%ebp
mov    %r15,%rdi
mov    $0xffffffff,%edx
call   1050 <add_output@plt>
jmp    12b4 <route_and_arp+0x164>
xor    %ebp,%ebp
xor    %esi,%esi
mov    %r15,%rdx
call   1030 <do_exec@plt>
mov    %ebp,%eax
add    $0xd0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.output = type { i32 }
@.str = [5 x i8] c"bash\00"
@.str.1 = [3 x i8] c"-c\00"
@.str.2 = [6 x i8] c"route\00"
@.str.3 = [4 x i8] c"add\00"
@.str.4 = [6 x i8] c"-host\00"
@.str.5 = [4 x i8] c"dev\00"
@.str.6 = [4 x i8] c"arp\00"
@.str.7 = [4 x i8] c"-Ds\00"
@.str.8 = [5 x i8] c"eth0\00"
@.str.9 = [4 x i8] c"pub\00"
@.str.10 = [53 x i8] c"Device doesn't contain only alphanumeric characters\0A\00"
@.str.11 = [48 x i8] c"echo 1 > /proc/sys/net/ipv4/conf/%.9s/proxy_arp\00"
define i32 @route_and_arp(i8* %0, i8* %1, i8* %2, i32 %3, %struct.output* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca %struct.output*
%12 = alloca [53 x i8]
%13 = alloca [4 x i8*]
%14 = alloca [7 x i8*]
%15 = alloca [6 x i8*]
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store %struct.output* %4, %struct.output** %11
%16 = getelementptr inbounds [4 x i8*], [4 x i8*]* %13, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds i8*, i8** %16, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = getelementptr inbounds [53 x i8], [53 x i8]* %12, i64 0, i64 0
store i8* %19, i8** %18
%20 = getelementptr inbounds i8*, i8** %18, i64 1
store i8* null, i8** %20
%21 = getelementptr inbounds [7 x i8*], [7 x i8*]* %14, i64 0, i64 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds i8*, i8** %21, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %22
%23 = getelementptr inbounds i8*, i8** %22, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %23
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %8
store i8* %25, i8** %24
%26 = getelementptr inbounds i8*, i8** %24, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %26
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %7
store i8* %28, i8** %27
%29 = getelementptr inbounds i8*, i8** %27, i64 1
store i8* null, i8** %29
%30 = getelementptr inbounds [6 x i8*], [6 x i8*]* %15, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8** %30
%31 = getelementptr inbounds i8*, i8** %30, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8** %31
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %8
store i8* %33, i8** %32
%34 = getelementptr inbounds i8*, i8** %32, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8** %34
%35 = getelementptr inbounds i8*, i8** %34, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8** %35
%36 = getelementptr inbounds i8*, i8** %35, i64 1
store i8* null, i8** %36
%37 = load i8*, i8** %7
%38 = call i32 @is_a_device(i8* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %5
%41 = load %struct.output*, %struct.output** %11
%42 = call i32 @add_output(%struct.output* %41, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0), i32 -1)
store i32 -1, i32* %6
br label %71
43: ; preds = %5
%44 = getelementptr inbounds [7 x i8*], [7 x i8*]* %14, i64 0, i64 0
%45 = load i32, i32* %10
%46 = load %struct.output*, %struct.output** %11
%47 = call i64 @do_exec(i8** %44, i32 %45, %struct.output* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %43
store i32 -1, i32* %6
br label %71
50: ; preds = %43
%51 = getelementptr inbounds [53 x i8], [53 x i8]* %12, i64 0, i64 0
%52 = load i8*, i8** %7
%53 = call i32 @snprintf(i8* %51, i32 52, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.11, i64 0, i64 0), i8* %52)
%54 = getelementptr inbounds [4 x i8*], [4 x i8*]* %13, i64 0, i64 0
%55 = load %struct.output*, %struct.output** %11
%56 = call i64 @do_exec(i8** %54, i32 0, %struct.output* %55)
%57 = load i8*, i8** %9
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %66
59: ; preds = %50
%60 = getelementptr inbounds [6 x i8*], [6 x i8*]* %15, i64 0, i64 0
%61 = load i8*, i8** %8
%62 = load i8*, i8** %9
%63 = load i8*, i8** %7
%64 = load %struct.output*, %struct.output** %11
%65 = call i32 @local_net_do(i8** %60, i32 3, i8* %61, i8* %62, i8* %63, %struct.output* %64)
br label %70
66: ; preds = %50
%67 = getelementptr inbounds [6 x i8*], [6 x i8*]* %15, i64 0, i64 0
%68 = load %struct.output*, %struct.output** %11
%69 = call i64 @do_exec(i8** %67, i32 0, %struct.output* %68)
br label %70
70: ; preds = %66, %59
store i32 0, i32* %6
br label %71
71: ; preds = %70, %49, %40
%72 = load i32, i32* %6
ret i32 %72
}

LLVM IR (-O2):
%struct.output = type { i32 }
@.str = [5 x i8] c"bash\00"
@.str.1 = [3 x i8] c"-c\00"
@.str.2 = [6 x i8] c"route\00"
@.str.3 = [4 x i8] c"add\00"
@.str.4 = [6 x i8] c"-host\00"
@.str.5 = [4 x i8] c"dev\00"
@.str.6 = [4 x i8] c"arp\00"
@.str.7 = [4 x i8] c"-Ds\00"
@.str.8 = [5 x i8] c"eth0\00"
@.str.9 = [4 x i8] c"pub\00"
@.str.10 = [53 x i8] c"Device doesn't contain only alphanumeric characters\0A\00"
@.str.11 = [48 x i8] c"echo 1 > /proc/sys/net/ipv4/conf/%.9s/proxy_arp\00"
define i32 @route_and_arp(i8* %0, i8* %1, i8* %2, i32 %3, %struct.output* %4) {
%6 = alloca [53 x i8]
%7 = alloca [4 x i8*]
%8 = alloca [7 x i8*]
%9 = alloca [6 x i8*]
%10 = getelementptr inbounds [53 x i8], [53 x i8]* %6, i64 0, i64 0
%11 = bitcast [4 x i8*]* %7 to i8*
%12 = getelementptr inbounds [4 x i8*], [4 x i8*]* %7, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [4 x i8*], [4 x i8*]* %7, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [4 x i8*], [4 x i8*]* %7, i64 0, i64 2
store i8* %10, i8** %14
%15 = getelementptr inbounds [4 x i8*], [4 x i8*]* %7, i64 0, i64 3
store i8* null, i8** %15
%16 = bitcast [7 x i8*]* %8 to i8*
%17 = getelementptr inbounds [7 x i8*], [7 x i8*]* %8, i64 0, i64 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds [7 x i8*], [7 x i8*]* %8, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %18
%19 = getelementptr inbounds [7 x i8*], [7 x i8*]* %8, i64 0, i64 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %19
%20 = getelementptr inbounds [7 x i8*], [7 x i8*]* %8, i64 0, i64 3
store i8* %1, i8** %20
%21 = getelementptr inbounds [7 x i8*], [7 x i8*]* %8, i64 0, i64 4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds [7 x i8*], [7 x i8*]* %8, i64 0, i64 5
store i8* %0, i8** %22
%23 = getelementptr inbounds [7 x i8*], [7 x i8*]* %8, i64 0, i64 6
store i8* null, i8** %23
%24 = bitcast [6 x i8*]* %9 to i8*
%25 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8** %25
%26 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8** %26
%27 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i64 0, i64 2
store i8* %1, i8** %27
%28 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i64 0, i64 3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8** %28
%29 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i64 0, i64 4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8** %29
%30 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i64 0, i64 5
store i8* null, i8** %30
%31 = call i32 @is_a_device(i8* %0)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %5
%34 = call i32 @add_output(%struct.output* %4, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0), i32 -1)
br label %46
35: ; preds = %5
%36 = call i64 @do_exec(i8** %17, i32 %3, %struct.output* %4)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %35
%39 = call i32 @snprintf(i8* %10, i32 52, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.11, i64 0, i64 0), i8* %0)
%40 = call i64 @do_exec(i8** %12, i32 0, %struct.output* %4)
%41 = icmp eq i8* %2, null
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = call i32 @local_net_do(i8** %25, i32 3, i8* %1, i8* %2, i8* %0, %struct.output* %4)
br label %46
44: ; preds = %38
%45 = call i64 @do_exec(i8** %25, i32 0, %struct.output* %4)
br label %46
46: ; preds = %42, %44, %35, %33
%47 = phi i32 [ -1, %33 ], [ -1, %35 ], [ 0, %44 ], [ 0, %42 ]
ret i32 %47
}