#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 execv(char *, char **);
int /*<<< orphan*/ getegid();
int /*<<< orphan*/ geteuid();
int /*<<< orphan*/ setregid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ setreuid(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  if (argc > 2) {
    return 3;
  }
  setreuid(geteuid(), geteuid());
  setregid(getegid(), getegid());
  if (strcmp(argv[1], "check-updates") == 0) {
    char c[] = "slackpkg check-updates";
    strcpy(argv[0], strtok(c, " "));
    argv[1] = strtok(0, " ");
    return execv("/usr/sbin/slackpkg", argv);
  } else if (strcmp(argv[1], "update") == 0) {
    char c[] = "slackpkg update";
    strcpy(argv[0], strtok(c, " "));
    argv[1] = strtok(0, " ");
    return execv("/usr/sbin/slackpkg", argv);
  } else if (strcmp(argv[1], "upgrade-all") == 0) {
    char c[] = "slackpkg -dialog=off -default_answer=n -batch=on upgrade-all";
    strcpy(argv[0], strtok(c, " "));
    argv[1] = strtok(0, " ");
    argv[2] = strtok(0, " ");
    argv[3] = strtok(0, " ");
    argv[4] = strtok(0, " ");
    return execv("/usr/sbin/slackpkg", argv);
  }
  return 3;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11bf <main+0x2f>
movl   $0x3,-0x4(%rbp)
jmp    143b <main+0x2ab>
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %eax,-0x88(%rbp)
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    -0x88(%rbp),%edi
mov    %eax,%esi
call   1080 <setreuid@plt>
mov    $0x0,%al
call   1070 <getegid@plt>
mov    %eax,-0x84(%rbp)
mov    $0x0,%al
call   1070 <getegid@plt>
mov    -0x84(%rbp),%edi
mov    %eax,%esi
call   1090 <setregid@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf0(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12b2 <main+0x122>
mov    0xe1a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe17(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe15(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xe0f(%rip),%ax
mov    %ax,-0x1c(%rbp)
mov    0xe07(%rip),%al
mov    %al,-0x1a(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x90(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xda3(%rip),%rsi
call   10a0 <strtok@plt>
mov    -0x90(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd84(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rsi
lea    0xd6b(%rip),%rdi
call   10b0 <execv@plt>
mov    %eax,-0x4(%rbp)
jmp    143b <main+0x2ab>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd62(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1346 <main+0x1b6>
mov    0xd89(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xd86(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x98(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xd0f(%rip),%rsi
call   10a0 <strtok@plt>
mov    -0x98(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xcf0(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rsi
lea    0xcd7(%rip),%rdi
call   10b0 <execv@plt>
mov    %eax,-0x4(%rbp)
jmp    143b <main+0x2ab>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcd5(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    142a <main+0x29a>
lea    -0x80(%rbp),%rdi
lea    0xd01(%rip),%rsi
mov    $0x3d,%edx
call   1060 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xc7c(%rip),%rsi
call   10a0 <strtok@plt>
mov    -0xa0(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc5d(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xc42(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xc27(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x18(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xc0c(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x10(%rbp),%rsi
lea    0xbf3(%rip),%rdi
call   10b0 <execv@plt>
mov    %eax,-0x4(%rbp)
jmp    143b <main+0x2ab>
jmp    142f <main+0x29f>
jmp    1434 <main+0x2a4>
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    $0x3,%ebp
cmp    $0x2,%edi
jg     1305 <main+0x185>
mov    %rsi,%r14
xor    %eax,%eax
call   1040 <geteuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <geteuid@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1070 <setreuid@plt>
xor    %eax,%eax
call   1060 <getegid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getegid@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1080 <setregid@plt>
mov    0x8(%r14),%rdi
lea    0xe2a(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     129f <main+0x11f>
mov    0x8(%r14),%rdi
lea    0xe34(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     12bb <main+0x13b>
mov    0x8(%r14),%rdi
lea    0xe22(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1305 <main+0x185>
movups 0xe80(%rip),%xmm0
movups %xmm0,0x2d(%rsp)
movaps 0xe67(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe4b(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe2f(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    (%r14),%rbx
lea    0xdbf(%rip),%rbp
mov    %rsp,%rdi
mov    %rbp,%rsi
call   1090 <strtok@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1090 <strtok@plt>
mov    %rax,0x8(%r14)
xor    %edi,%edi
mov    %rbp,%rsi
call   1090 <strtok@plt>
mov    %rax,0x10(%r14)
xor    %edi,%edi
mov    %rbp,%rsi
call   1090 <strtok@plt>
mov    %rax,0x18(%r14)
xor    %edi,%edi
mov    %rbp,%rsi
call   1090 <strtok@plt>
mov    %rax,0x20(%r14)
jmp    12f4 <main+0x174>
movaps 0xd9a(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x73657461647075,%rax
mov    %rax,0xf(%rsp)
jmp    12c6 <main+0x146>
movaps 0xd9e(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    (%r14),%rbx
lea    0xd3e(%rip),%rbp
mov    %rsp,%rdi
mov    %rbp,%rsi
call   1090 <strtok@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1090 <strtok@plt>
mov    %rax,0x8(%r14)
lea    0xd15(%rip),%rdi
mov    %r14,%rsi
call   10a0 <execv@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"check-updates\00"
@__const.main.c = [23 x i8] c"slackpkg check-updates\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [19 x i8] c"/usr/sbin/slackpkg\00"
@.str.3 = [7 x i8] c"update\00"
@__const.main.c.4 = [16 x i8] c"slackpkg update\00"
@.str.5 = [12 x i8] c"upgrade-all\00"
@__const.main.c.6 = [61 x i8] c"slackpkg -dialog=off -default_answer=n -batch=on upgrade-all\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [23 x i8]
%7 = alloca [16 x i8]
%8 = alloca [61 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 3, i32* %3
br label %87
12: ; preds = %2
%13 = call i32 (...) @geteuid()
%14 = call i32 (...) @geteuid()
%15 = call i32 @setreuid(i32 %13, i32 %14)
%16 = call i32 (...) @getegid()
%17 = call i32 (...) @getegid()
%18 = call i32 @setregid(i32 %16, i32 %17)
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %37
24: ; preds = %12
%25 = bitcast [23 x i8]* %6 to i8*
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = getelementptr inbounds [23 x i8], [23 x i8]* %6, i64 0, i64 0
%30 = call i8* @strtok(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @strcpy(i8* %28, i8* %30)
%32 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
store i8* %32, i8** %34
%35 = load i8**, i8*** %5
%36 = call i32 @execv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8** %35)
store i32 %36, i32* %3
br label %87
37: ; preds = %12
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %56
43: ; preds = %37
%44 = bitcast [16 x i8]* %7 to i8*
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%49 = call i8* @strtok(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 @strcpy(i8* %47, i8* %49)
%51 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
store i8* %51, i8** %53
%54 = load i8**, i8*** %5
%55 = call i32 @execv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8** %54)
store i32 %55, i32* %3
br label %87
56: ; preds = %37
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %84
62: ; preds = %56
%63 = bitcast [61 x i8]* %8 to i8*
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 0
%66 = load i8*, i8** %65
%67 = getelementptr inbounds [61 x i8], [61 x i8]* %8, i64 0, i64 0
%68 = call i8* @strtok(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%69 = call i32 @strcpy(i8* %66, i8* %68)
%70 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
store i8* %70, i8** %72
%73 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 2
store i8* %73, i8** %75
%76 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 3
store i8* %76, i8** %78
%79 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 4
store i8* %79, i8** %81
%82 = load i8**, i8*** %5
%83 = call i32 @execv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8** %82)
store i32 %83, i32* %3
br label %87
84: ; preds = %56
br label %85
85: ; preds = %84
br label %86
86: ; preds = %85
store i32 3, i32* %3
br label %87
87: ; preds = %86, %62, %43, %24, %11
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@.str = [14 x i8] c"check-updates\00"
@__const.main.c = [23 x i8] c"slackpkg check-updates\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [19 x i8] c"/usr/sbin/slackpkg\00"
@.str.3 = [7 x i8] c"update\00"
@__const.main.c.4 = [16 x i8] c"slackpkg update\00"
@.str.5 = [12 x i8] c"upgrade-all\00"
@__const.main.c.6 = [61 x i8] c"slackpkg -dialog=off -default_answer=n -batch=on upgrade-all\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [23 x i8]
%4 = alloca [16 x i8]
%5 = alloca [61 x i8]
%6 = icmp sgt i32 %0, 2
br i1 %6, label %53, label %7
7: ; preds = %2
%8 = tail call i32 (...) @geteuid()
%9 = tail call i32 (...) @geteuid()
%10 = tail call i32 @setreuid(i32 %8, i32 %9)
%11 = tail call i32 (...) @getegid()
%12 = tail call i32 (...) @getegid()
%13 = tail call i32 @setregid(i32 %11, i32 %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %7
%19 = getelementptr inbounds [23 x i8], [23 x i8]* %3, i64 0, i64 0
%20 = load i8*, i8** %1
%21 = call i8* @strtok(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @strcpy(i8* %20, i8* %21)
%23 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %23, i8** %14
%24 = call i32 @execv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8** %1)
br label %53
25: ; preds = %7
%26 = load i8*, i8** %14
%27 = tail call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%31 = load i8*, i8** %1
%32 = call i8* @strtok(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %34, i8** %14
%35 = call i32 @execv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8** %1)
br label %53
36: ; preds = %25
%37 = load i8*, i8** %14
%38 = tail call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %53
40: ; preds = %36
%41 = getelementptr inbounds [61 x i8], [61 x i8]* %5, i64 0, i64 0
%42 = load i8*, i8** %1
%43 = call i8* @strtok(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%44 = call i32 @strcpy(i8* %42, i8* %43)
%45 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %45, i8** %14
%46 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%47 = getelementptr inbounds i8*, i8** %1, i64 2
store i8* %46, i8** %47
%48 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%49 = getelementptr inbounds i8*, i8** %1, i64 3
store i8* %48, i8** %49
%50 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%51 = getelementptr inbounds i8*, i8** %1, i64 4
store i8* %50, i8** %51
%52 = call i32 @execv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8** %1)
br label %53
53: ; preds = %36, %2, %40, %29, %18
%54 = phi i32 [ %24, %18 ], [ %35, %29 ], [ %52, %40 ], [ 3, %2 ], [ 3, %36 ]
ret i32 %54
}