#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__ setgroups(int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ setregid(int, int /*<<< orphan*/);
scalar_t__ setreuid(int, int /*<<< orphan*/);
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(setregid(gid, 0) == 0);
    assert(setgroups(0, NULL) == 0);
  }
  assert(setreuid(uid, 0) == 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   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <assert@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11c0 <main+0x60>
movl   $0xfffe,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1201 <main+0xa1>
mov    -0x18(%rbp),%edi
xor    %esi,%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
xor    %esi,%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   1070 <execvp@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x4,%edi
setge  %al
mov    %eax,%edi
call   1040 <assert@plt>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    %r14d,%edi
call   1040 <assert@plt>
test   %ebp,%ebp
mov    $0xfffe,%edi
cmovne %ebp,%edi
test   %edi,%edi
jle    11cf <main+0x6f>
xor    %esi,%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
xor    %esi,%esi
call   1050 <setreuid@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    0x18(%rbx),%rdi
add    $0x18,%rbx
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <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 %38
28: ; preds = %25
%29 = load i32, i32* %7
%30 = call i64 @setregid(i32 %29, i32 0)
%31 = icmp eq i64 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = call i64 @setgroups(i32 0, i32* null)
%35 = icmp eq i64 %34, 0
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
br label %38
38: ; preds = %28, %25
%39 = load i32, i32* %6
%40 = call i64 @setreuid(i32 %39, i32 0)
%41 = icmp eq i64 %40, 0
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 3
%46 = load i8*, i8** %45
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = call i32 @execvp(i8* %46, i8** %48)
ret i32 %49
}

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 %25
16: ; preds = %2
%17 = tail call i64 @setregid(i32 %14, i32 0)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = tail call i64 @setgroups(i32 0, i32* null)
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
br label %25
25: ; preds = %16, %2
%26 = tail call i64 @setreuid(i32 %8, i32 0)
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = tail call i32 @assert(i32 %28)
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = tail call i32 @execvp(i8* %31, i8** %30)
ret i32 %32
}