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

/* Variables and functions */
int N_SLIP;
int /*<<< orphan*/ SIOCSIFENCAP;
int /*<<< orphan*/ TIOCSETD;
scalar_t__ do_exec(char **, int, struct output *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ forward_ip(struct output *);
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ output_errno(struct output *, char *);
int /*<<< orphan*/ route_and_arp(char *, char *, char *, int /*<<< orphan*/,
                                 struct output *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ write_output(int, struct output *);
void slip_up(int fd, char *gate_addr, char *remote_addr, char *netmask,
             struct output *output) {
  char slip_name[sizeof("slxxxx\0")];
  char *up_argv[] = {"ifconfig", slip_name, gate_addr, "mtu",
                     "1500",     "up",      NULL};
  int disc, sencap, n;
  disc = N_SLIP;
  if ((n = ioctl(fd, TIOCSETD, &disc)) < 0) {
    output_errno(output, "Setting slip line discipline");
    write_output(1, output);
    exit(1);
  }
  sencap = 0;
  if (ioctl(fd, SIOCSIFENCAP, &sencap) < 0) {
    output_errno(output, "Setting slip encapsulation");
    write_output(1, output);
    exit(1);
  }
  snprintf(slip_name, sizeof(slip_name) - 1, "sl%d", n);
  if (do_exec(up_argv, 1, output)) {
    write_output(1, output);
    exit(1);
  }
  forward_ip(output);
  if (remote_addr != NULL)
    route_and_arp(slip_name, remote_addr, netmask, 0, output);
}


x86 assembly (clang, -O0):
<slip_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
lea    0xe5b(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    0xe49(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe42(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe3c(%rip),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
lea    -0x74(%rbp),%rdx
call   1070 <ioctl@plt>
mov    %eax,-0x7c(%rbp)
cmp    $0x0,%eax
jge    1237 <slip_up+0xb7>
mov    -0x28(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1030 <output_errno@plt>
mov    -0x28(%rbp),%rsi
mov    $0x1,%edi
call   1040 <write_output@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x78(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
lea    -0x78(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%eax
jge    1284 <slip_up+0x104>
mov    -0x28(%rbp),%rdi
lea    0xdcb(%rip),%rsi
call   1030 <output_errno@plt>
mov    -0x28(%rbp),%rsi
mov    $0x1,%edi
call   1040 <write_output@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x30(%rbp),%rdi
mov    -0x7c(%rbp),%ecx
mov    $0x7,%esi
lea    0xdb6(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x70(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x1,%esi
call   1050 <do_exec@plt>
cmp    $0x0,%rax
je     12d0 <slip_up+0x150>
mov    -0x28(%rbp),%rsi
mov    $0x1,%edi
call   1040 <write_output@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1090 <forward_ip@plt>
cmpq   $0x0,-0x18(%rbp)
je     12fb <slip_up+0x17b>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%r8
xor    %ecx,%ecx
call   1080 <route_and_arp@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slip_up>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %r8,%r12
mov    %rcx,%r14
mov    %rdx,%r15
mov    %edi,%ebp
lea    0xe62(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    %rsi,0x20(%rsp)
lea    0xe50(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xe48(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe41(%rip),%rax
mov    %rax,0x38(%rsp)
movq   $0x0,0x40(%rsp)
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
call   1070 <ioctl@plt>
test   %eax,%eax
js     1281 <slip_up+0x101>
mov    %eax,%ebx
movl   $0x0,(%rsp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1070 <ioctl@plt>
test   %eax,%eax
js     128a <slip_up+0x10a>
lea    0xe23(%rip),%rdx
lea    0x8(%rsp),%rdi
mov    $0x7,%esi
mov    %ebx,%ecx
call   1060 <snprintf@plt>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    %r12,%rdx
call   1050 <do_exec@plt>
test   %rax,%rax
jne    1299 <slip_up+0x119>
mov    %r12,%rdi
call   1090 <forward_ip@plt>
test   %r15,%r15
je     1274 <slip_up+0xf4>
lea    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
mov    %r12,%r8
call   1080 <route_and_arp@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8d(%rip),%rsi
jmp    1291 <slip_up+0x111>
lea    0xda1(%rip),%rsi
mov    %r12,%rdi
call   1030 <output_errno@plt>
mov    $0x1,%edi
mov    %r12,%rsi
call   1040 <write_output@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.output = type { i32 }
@.str = [9 x i8] c"ifconfig\00"
@.str.1 = [4 x i8] c"mtu\00"
@.str.2 = [5 x i8] c"1500\00"
@.str.3 = [3 x i8] c"up\00"
@N_SLIP = global i32 0
@TIOCSETD = global i32 0
@.str.4 = [29 x i8] c"Setting slip line discipline\00"
@SIOCSIFENCAP = global i32 0
@.str.5 = [27 x i8] c"Setting slip encapsulation\00"
@.str.6 = [5 x i8] c"sl%d\00"
define void @slip_up(i32 %0, i8* %1, i8* %2, i8* %3, %struct.output* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.output*
%11 = alloca [8 x i8]
%12 = alloca [7 x i8*]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store %struct.output* %4, %struct.output** %10
%16 = getelementptr inbounds [7 x i8*], [7 x i8*]* %12, i64 0, i64 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
store i8* %18, i8** %17
%19 = getelementptr inbounds i8*, i8** %17, i64 1
%20 = load i8*, i8** %7
store i8* %20, i8** %19
%21 = getelementptr inbounds i8*, i8** %19, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds i8*, i8** %21, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %22
%23 = getelementptr inbounds i8*, i8** %22, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %23
%24 = getelementptr inbounds i8*, i8** %23, i64 1
store i8* null, i8** %24
%25 = load i32, i32* @N_SLIP
store i32 %25, i32* %13
%26 = load i32, i32* %6
%27 = load i32, i32* @TIOCSETD
%28 = call i32 @ioctl(i32 %26, i32 %27, i32* %13)
store i32 %28, i32* %15
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %5
%31 = load %struct.output*, %struct.output** %10
%32 = call i32 @output_errno(%struct.output* %31, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%33 = load %struct.output*, %struct.output** %10
%34 = call i32 @write_output(i32 1, %struct.output* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %5
store i32 0, i32* %14
%37 = load i32, i32* %6
%38 = load i32, i32* @SIOCSIFENCAP
%39 = call i32 @ioctl(i32 %37, i32 %38, i32* %14)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %36
%42 = load %struct.output*, %struct.output** %10
%43 = call i32 @output_errno(%struct.output* %42, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%44 = load %struct.output*, %struct.output** %10
%45 = call i32 @write_output(i32 1, %struct.output* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %36
%48 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%49 = load i32, i32* %15
%50 = call i32 @snprintf(i8* %48, i32 7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds [7 x i8*], [7 x i8*]* %12, i64 0, i64 0
%52 = load %struct.output*, %struct.output** %10
%53 = call i64 @do_exec(i8** %51, i32 1, %struct.output* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %47
%56 = load %struct.output*, %struct.output** %10
%57 = call i32 @write_output(i32 1, %struct.output* %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %47
%60 = load %struct.output*, %struct.output** %10
%61 = call i32 @forward_ip(%struct.output* %60)
%62 = load i8*, i8** %8
%63 = icmp ne i8* %62, null
br i1 %63, label %64, label %70
64: ; preds = %59
%65 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%66 = load i8*, i8** %8
%67 = load i8*, i8** %9
%68 = load %struct.output*, %struct.output** %10
%69 = call i32 @route_and_arp(i8* %65, i8* %66, i8* %67, i32 0, %struct.output* %68)
br label %70
70: ; preds = %64, %59
ret void
}

LLVM IR (-O2):
%struct.output = type { i32 }
@.str = [9 x i8] c"ifconfig\00"
@.str.1 = [4 x i8] c"mtu\00"
@.str.2 = [5 x i8] c"1500\00"
@.str.3 = [3 x i8] c"up\00"
@N_SLIP = global i32 0
@TIOCSETD = global i32 0
@.str.4 = [29 x i8] c"Setting slip line discipline\00"
@SIOCSIFENCAP = global i32 0
@.str.5 = [27 x i8] c"Setting slip encapsulation\00"
@.str.6 = [5 x i8] c"sl%d\00"
define void @slip_up(i32 %0, i8* %1, i8* %2, i8* %3, %struct.output* %4) {
%6 = alloca [8 x i8]
%7 = alloca [7 x i8*]
%8 = alloca i32
%9 = alloca i32
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%11 = bitcast [7 x i8*]* %7 to i8*
%12 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 1
store i8* %10, i8** %13
%14 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 2
store i8* %1, i8** %14
%15 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 6
store i8* null, i8** %18
%19 = bitcast i32* %8 to i8*
%20 = bitcast i32* %9 to i8*
%21 = load i32, i32* @N_SLIP
store i32 %21, i32* %8
%22 = load i32, i32* @TIOCSETD
%23 = call i32 @ioctl(i32 %0, i32 %22, i32* %8)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %5
%26 = call i32 @output_errno(%struct.output* %4, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @write_output(i32 1, %struct.output* %4)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %5
store i32 0, i32* %9
%30 = load i32, i32* @SIOCSIFENCAP
%31 = call i32 @ioctl(i32 %0, i32 %30, i32* %9)
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = call i32 @output_errno(%struct.output* %4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 @write_output(i32 1, %struct.output* %4)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %29
%38 = call i32 @snprintf(i8* %10, i32 7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %23)
%39 = call i64 @do_exec(i8** %12, i32 1, %struct.output* %4)
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %37
%42 = call i32 @write_output(i32 1, %struct.output* %4)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %37
%45 = call i32 @forward_ip(%struct.output* %4)
%46 = icmp eq i8* %2, null
br i1 %46, label %49, label %47
47: ; preds = %44
%48 = call i32 @route_and_arp(i8* %10, i8* %2, i8* %3, i32 0, %struct.output* %4)
br label %49
49: ; preds = %47, %44
ret void
}