#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*/ atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ setreuid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ slip_down(char *, char *, int /*<<< orphan*/ *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ slip_name(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ slip_up(int /*<<< orphan*/, char *, char *,
                           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(char *, char *);
void slip_v0_v2(int argc, char **argv) {
  char *op = argv[0], dev[sizeof("slnnnnn\0")];
  if (setreuid(0, 0) < 0) {
    perror("slip - setreuid failed");
    exit(1);
  }
  if (!strcmp(op, "up"))
    slip_up(atoi(argv[1]), argv[2], argv[3], NULL, NULL);
  else if (!strcmp(op, "down")) {
    slip_name(atoi(argv[1]), dev, NULL);
    slip_down(dev, argv[2], NULL, NULL);
  } else {
    printf("slip - Unknown op '%s'\n", op);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<slip_v0_v2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
xor    %esi,%esi
mov    %esi,%edi
call   1060 <setreuid@plt>
cmp    $0x0,%rax
jge    11d3 <slip_v0_v2+0x43>
lea    0xe3c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    121d <slip_v0_v2+0x8d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1090 <slip_up@plt>
jmp    128e <slip_v0_v2+0xfe>
mov    -0x18(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    126f <slip_v0_v2+0xdf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
lea    -0x21(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <slip_name@plt>
lea    -0x21(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1080 <slip_down@plt>
jmp    1289 <slip_v0_v2+0xf9>
mov    -0x18(%rbp),%rsi
lea    0xda5(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    128e <slip_v0_v2+0xfe>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slip_v0_v2>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    (%rsi),%r14
xor    %edi,%edi
xor    %esi,%esi
call   1060 <setreuid@plt>
test   %rax,%rax
js     1227 <slip_v0_v2+0x97>
lea    0xe65(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1203 <slip_v0_v2+0x73>
lea    0xe55(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    123d <slip_v0_v2+0xad>
mov    0x8(%rbx),%rdi
call   10a0 <atoi@plt>
lea    0xf(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <slip_name@plt>
mov    0x10(%rbx),%rsi
mov    %r14,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1080 <slip_down@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x8(%rbx),%rdi
call   10a0 <atoi@plt>
mov    0x10(%rbx),%rsi
mov    0x18(%rbx),%rdx
mov    %eax,%edi
xor    %ecx,%ecx
xor    %r8d,%r8d
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1090 <slip_up@plt>
lea    0xdd2(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xddb(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"slip - setreuid failed\00"
@.str.1 = [3 x i8] c"up\00"
@.str.2 = [5 x i8] c"down\00"
@.str.3 = [24 x i8] c"slip - Unknown op '%s'\0A\00"
define void @slip_v0_v2(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca [9 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i8**, i8*** %4
%8 = getelementptr inbounds i8*, i8** %7, i64 0
%9 = load i8*, i8** %8
store i8* %9, i8** %5
%10 = call i64 @setreuid(i32 0, i32 0)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = call i32 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %31, label %19
19: ; preds = %15
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
%24 = load i8**, i8*** %4
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %4
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i32 @slip_up(i32 %23, i8* %26, i8* %29, i32* null, i32* null)
br label %52
31: ; preds = %15
%32 = load i8*, i8** %5
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp ne i32 %33, 0
br i1 %34, label %47, label %35
35: ; preds = %31
%36 = load i8**, i8*** %4
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
%40 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%41 = call i32 @slip_name(i32 %39, i8* %40, i32* null)
%42 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%43 = load i8**, i8*** %4
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @slip_down(i8* %42, i8* %45, i32* null, i32* null)
br label %51
47: ; preds = %31
%48 = load i8*, i8** %5
%49 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %35
br label %52
52: ; preds = %51, %19
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"slip - setreuid failed\00"
@.str.1 = [3 x i8] c"up\00"
@.str.2 = [5 x i8] c"down\00"
@.str.3 = [24 x i8] c"slip - Unknown op '%s'\0A\00"
define void @slip_v0_v2(i32 %0, i8** nocapture %1) {
%3 = alloca [9 x i8]
%4 = load i8*, i8** %1
%5 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%6 = tail call i64 @setreuid(i32 0, i32 0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = tail call i32 @slip_up(i32 %17, i8* %19, i8* %21, i32* null, i32* null)
br label %37
23: ; preds = %11
%24 = tail call i32 @strcmp(i8* dereferenceable(1) %4, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = tail call i32 @atoi(i8* %28)
%30 = call i32 @slip_name(i32 %29, i8* %5, i32* null)
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @slip_down(i8* %5, i8* %32, i32* null, i32* null)
br label %37
34: ; preds = %23
%35 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %26, %14
ret void
}