#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*/ chdir(char *);
int execv(char *, char *const *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ setegid(int);
int /*<<< orphan*/ setenv(char *, char *, int);
scalar_t__ seteuid(int);
scalar_t__ setgid(int);
scalar_t__ setuid(int);
int main(int argc, char *const argv[]) {
  if (setgid(1003)) {
    perror("setgid failed\n");
    exit(-1);
  }
  if (setuid(1003)) {
    perror("setuid failed\n");
    exit(-1);
  }
  if (setegid(1003)) {
    perror("setegid failed\n");
    exit(-1);
  }
  if (seteuid(1003)) {
    perror("seteuid failed\n");
    exit(-1);
  }
  setenv("HOME", "/home/brscanner", 1);
  chdir("/home/brscanner");
  return execv("/home/danlyke/scanning/import.pl", argv);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x3eb,%edi
call   1050 <setgid@plt>
cmp    $0x0,%rax
je     11d0 <main+0x40>
lea    0xe3f(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    $0x3eb,%edi
call   1080 <setuid@plt>
cmp    $0x0,%rax
je     11fa <main+0x6a>
lea    0xe24(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    $0x3eb,%edi
call   10a0 <setegid@plt>
cmp    $0x0,%rax
je     1224 <main+0x94>
lea    0xe09(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    $0x3eb,%edi
call   10b0 <seteuid@plt>
cmp    $0x0,%rax
je     124e <main+0xbe>
lea    0xdef(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xde9(%rip),%rdi
lea    0xde7(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
lea    0xdd6(%rip),%rdi
call   1040 <chdir@plt>
mov    -0x10(%rbp),%rsi
lea    0xdd6(%rip),%rdi
call   1090 <execv@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    $0x3eb,%edi
call   1050 <setgid@plt>
test   %rax,%rax
jne    120c <main+0x7c>
mov    $0x3eb,%edi
call   1080 <setuid@plt>
test   %rax,%rax
jne    1215 <main+0x85>
mov    $0x3eb,%edi
call   10a0 <setegid@plt>
test   %rax,%rax
jne    121e <main+0x8e>
mov    $0x3eb,%edi
call   10b0 <seteuid@plt>
test   %rax,%rax
jne    1227 <main+0x97>
lea    0xe64(%rip),%rdi
lea    0xe62(%rip),%rbx
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    %rbx,%rdi
call   1040 <chdir@plt>
lea    0xe56(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <execv@plt>
lea    0xded(%rip),%rdi
jmp    122e <main+0x9e>
lea    0xdf3(%rip),%rdi
jmp    122e <main+0x9e>
lea    0xdf9(%rip),%rdi
jmp    122e <main+0x9e>
lea    0xe00(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"setgid failed\0A\00"
@.str.1 = [15 x i8] c"setuid failed\0A\00"
@.str.2 = [16 x i8] c"setegid failed\0A\00"
@.str.3 = [16 x i8] c"seteuid failed\0A\00"
@.str.4 = [5 x i8] c"HOME\00"
@.str.5 = [16 x i8] c"/home/brscanner\00"
@.str.6 = [33 x i8] c"/home/danlyke/scanning/import.pl\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i64 @setgid(i32 1003)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = call i64 @setuid(i32 1003)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %11
%18 = call i64 @setegid(i32 1003)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %17
%24 = call i64 @seteuid(i32 1003)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %23
%30 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 1)
%31 = call i32 @chdir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%32 = load i8**, i8*** %5
%33 = call i32 @execv(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8** %32)
ret i32 %33
}

LLVM IR (-O2):
@.str = [15 x i8] c"setgid failed\0A\00"
@.str.1 = [15 x i8] c"setuid failed\0A\00"
@.str.2 = [16 x i8] c"setegid failed\0A\00"
@.str.3 = [16 x i8] c"seteuid failed\0A\00"
@.str.4 = [5 x i8] c"HOME\00"
@.str.5 = [16 x i8] c"/home/brscanner\00"
@.str.6 = [33 x i8] c"/home/danlyke/scanning/import.pl\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 @setgid(i32 1003)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = tail call i64 @setuid(i32 1003)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %8
%15 = tail call i64 @setegid(i32 1003)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %14
%21 = tail call i64 @seteuid(i32 1003)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%25 = tail call i32 @exit(i32 -1)
unreachable
26: ; preds = %20
%27 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 1)
%28 = tail call i32 @chdir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%29 = tail call i32 @execv(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8** %1)
ret i32 %29
}