#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*/ _check_args(int, char **);
int /*<<< orphan*/ _gid(char *);
char *_split_group_from_user(char *);
int /*<<< orphan*/ _uid(char *);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ setgid(int /*<<< orphan*/);
scalar_t__ setuid(int /*<<< orphan*/);
int main(int argc, char **argv) {
  _check_args(argc, argv);
  char *user = argv[1];
  char *group = _split_group_from_user(user);
  if (0 != setgid(_gid(group))) {
    perror("resu");
    exit(1);
  }
  if (0 != setuid(_uid(user))) {
    perror("resu");
    exit(1);
  }
  execvp(argv[3], argv + 3);
  perror("resu");
  return 1;
}


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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <_check_args@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <_split_group_from_user@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <_gid@plt>
mov    %eax,%edi
call   1060 <setgid@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11ff <main+0x6f>
lea    0xe10(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1070 <_uid@plt>
mov    %eax,%edi
call   10b0 <setuid@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1233 <main+0xa3>
lea    0xddc(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x18,%rsi
call   1090 <execvp@plt>
lea    0xdb1(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1050 <_check_args@plt>
mov    0x8(%rbx),%r14
mov    %r14,%rdi
call   1040 <_split_group_from_user@plt>
mov    %rax,%rdi
call   1030 <_gid@plt>
mov    %eax,%edi
call   1060 <setgid@plt>
test   %rax,%rax
jne    11f9 <main+0x69>
mov    %r14,%rdi
call   1070 <_uid@plt>
mov    %eax,%edi
call   10b0 <setuid@plt>
test   %rax,%rax
jne    11f9 <main+0x69>
mov    0x18(%rbx),%rdi
add    $0x18,%rbx
mov    %rbx,%rsi
call   1090 <execvp@plt>
lea    0xe19(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe00(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"resu\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i32 @_check_args(i32 %8, i8** %9)
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = call i8* @_split_group_from_user(i8* %14)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = call i32 @_gid(i8* %16)
%18 = call i64 @setgid(i32 %17)
%19 = icmp ne i64 0, %18
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8*, i8** %6
%25 = call i32 @_uid(i8* %24)
%26 = call i64 @setuid(i32 %25)
%27 = icmp ne i64 0, %26
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %23
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = call i32 @execvp(i8* %34, i8** %36)
%38 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [5 x i8] c"resu\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @_check_args(i32 %0, i8** %1)
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i8* @_split_group_from_user(i8* %5)
%7 = tail call i32 @_gid(i8* %6)
%8 = tail call i64 @setgid(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = tail call i32 @_uid(i8* %5)
%15 = tail call i64 @setuid(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %13
%21 = getelementptr inbounds i8*, i8** %1, i64 3
%22 = load i8*, i8** %21
%23 = tail call i32 @execvp(i8* %22, i8** %21)
%24 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
ret i32 1
}