#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*/ assert(int);
int atoi(char *);
int execvp(char *, char **);
scalar_t__ setgid(int);
scalar_t__ setgroups(int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ setregid(int, int);
scalar_t__ setreuid(int, int);
scalar_t__ setuid(int);
int main(int argc, char **argv) {
  assert(argc > 3);
  int uid = atoi(argv[1]);
  int gid = atoi(argv[2]);
  assert(uid);
  if (gid == 0)
    gid = 65534;
  if (gid > 0) {
    assert(setgid(gid) == 0);
    assert(setregid(gid, gid) == 0);
    assert(setgroups(0, NULL) == 0);
  }
  assert(setuid(uid) == 0);
  assert(setreuid(uid, uid) == 0);
  return execvp(argv[3], argv + 3);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <assert@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11e0 <main+0x60>
movl   $0xfffe,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    123b <main+0xbb>
mov    -0x18(%rbp),%edi
call   1070 <setgid@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <setregid@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <setgroups@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x14(%rbp),%edi
call   10a0 <setuid@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <setreuid@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x18,%rsi
call   1080 <execvp@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
xor    %eax,%eax
cmp    $0x4,%edi
setge  %al
mov    %eax,%edi
call   1040 <assert@plt>
mov    0x8(%r15),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%r15),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
mov    %r14d,%edi
call   1040 <assert@plt>
test   %ebx,%ebx
mov    $0xfffe,%ebp
cmovne %ebx,%ebp
test   %ebp,%ebp
jle    1209 <main+0x89>
mov    %ebp,%edi
call   1070 <setgid@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    %ebp,%edi
mov    %ebp,%esi
call   1060 <setregid@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <setgroups@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    %r14d,%edi
call   10a0 <setuid@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    %r14d,%edi
mov    %r14d,%esi
call   1050 <setreuid@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    0x18(%r15),%rdi
add    $0x18,%r15
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <execvp@plt>

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 3
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %7
%20 = load i32, i32* %6
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %2
store i32 65534, i32* %7
br label %25
25: ; preds = %24, %2
%26 = load i32, i32* %7
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %25
%29 = load i32, i32* %7
%30 = call i64 @setgid(i32 %29)
%31 = icmp eq i64 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i32, i32* %7
%35 = load i32, i32* %7
%36 = call i64 @setregid(i32 %34, i32 %35)
%37 = icmp eq i64 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = call i64 @setgroups(i32 0, i32* null)
%41 = icmp eq i64 %40, 0
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
br label %44
44: ; preds = %28, %25
%45 = load i32, i32* %6
%46 = call i64 @setuid(i32 %45)
%47 = icmp eq i64 %46, 0
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i32, i32* %6
%51 = load i32, i32* %6
%52 = call i64 @setreuid(i32 %50, i32 %51)
%53 = icmp eq i64 %52, 0
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 3
%58 = load i8*, i8** %57
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 3
%61 = call i32 @execvp(i8* %58, i8** %60)
ret i32 %61
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** %1) {
%3 = icmp sgt i32 %0, 3
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = tail call i32 @assert(i32 %8)
%13 = icmp eq i32 %11, 0
%14 = select i1 %13, i32 65534, i32 %11
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %2
%17 = tail call i64 @setgid(i32 %14)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = tail call i64 @setregid(i32 %14, i32 %14)
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = tail call i64 @setgroups(i32 0, i32* null)
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = tail call i32 @assert(i32 %27)
br label %29
29: ; preds = %16, %2
%30 = tail call i64 @setuid(i32 %8)
%31 = icmp eq i64 %30, 0
%32 = zext i1 %31 to i32
%33 = tail call i32 @assert(i32 %32)
%34 = tail call i64 @setreuid(i32 %8, i32 %8)
%35 = icmp eq i64 %34, 0
%36 = zext i1 %35 to i32
%37 = tail call i32 @assert(i32 %36)
%38 = getelementptr inbounds i8*, i8** %1, i64 3
%39 = load i8*, i8** %38
%40 = tail call i32 @execvp(i8* %39, i8** %38)
ret i32 %40
}