#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*/ err(int, char *);
scalar_t__ execvp(char *, char **);
int /*<<< orphan*/ geteuid();
int /*<<< orphan*/ set_new_env();
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ setreuid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(void) {
  char *arg[] = {"/usr/bin/id", NULL};
  setbuf(stdin, NULL);
  setbuf(stdout, NULL);
  setbuf(stderr, NULL);
  if (setreuid(geteuid(), geteuid()) != 0)
    err(1, "setreuid");
  set_new_env();
  if (execvp(arg[0], arg) != 0)
    err(1, "execvp");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2c7a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c77(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setbuf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setbuf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setbuf@plt>
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1070 <setreuid@plt>
cmp    $0x0,%rax
je     11f1 <main+0x91>
mov    $0x1,%edi
lea    0xe20(%rip),%rsi
call   1060 <err@plt>
mov    $0x0,%al
call   1030 <set_new_env@plt>
mov    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <execvp@plt>
cmp    $0x0,%rax
je     1220 <main+0xc0>
mov    $0x1,%edi
lea    0xdfa(%rip),%rsi
call   1060 <err@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movaps 0x2c84(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <setbuf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <setbuf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <setbuf@plt>
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1070 <setreuid@plt>
test   %rax,%rax
je     11cf <main+0x6f>
lea    0xe47(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
xor    %eax,%eax
call   1030 <set_new_env@plt>
lea    0xe23(%rip),%rdi
mov    %rsp,%rsi
call   1080 <execvp@plt>
test   %rax,%rax
je     11fb <main+0x9b>
lea    0xe24(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/usr/bin/id\00"
@__const.main.arg = [2 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i8* null]
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [9 x i8] c"setreuid\00"
@.str.2 = [7 x i8] c"execvp\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i8*]
store i32 0, i32* %1
%3 = bitcast [2 x i8*]* %2 to i8*
%4 = load i32, i32* @stdin
%5 = call i32 @setbuf(i32 %4, i32* null)
%6 = load i32, i32* @stdout
%7 = call i32 @setbuf(i32 %6, i32* null)
%8 = load i32, i32* @stderr
%9 = call i32 @setbuf(i32 %8, i32* null)
%10 = call i32 (...) @geteuid()
%11 = call i32 (...) @geteuid()
%12 = call i64 @setreuid(i32 %10, i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %0
%17 = call i32 (...) @set_new_env()
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%19 = load i8*, i8** %18
%20 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%21 = call i64 @execvp(i8* %19, i8** %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %16
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"/usr/bin/id\00"
@__const.main.arg = [2 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i8* null]
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [9 x i8] c"setreuid\00"
@.str.2 = [7 x i8] c"execvp\00"
define i32 @main() {
%1 = alloca [2 x i8*]
%2 = bitcast [2 x i8*]* %1 to i8*
%3 = load i32, i32* @stdin
%4 = tail call i32 @setbuf(i32 %3, i32* null)
%5 = load i32, i32* @stdout
%6 = tail call i32 @setbuf(i32 %5, i32* null)
%7 = load i32, i32* @stderr
%8 = tail call i32 @setbuf(i32 %7, i32* null)
%9 = tail call i32 (...) @geteuid()
%10 = tail call i32 (...) @geteuid()
%11 = tail call i64 @setreuid(i32 %9, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
%16 = tail call i32 (...) @set_new_env()
%17 = getelementptr inbounds [2 x i8*], [2 x i8*]* %1, i64 0, i64 0
%18 = call i64 @execvp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
ret i32 0
}