#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 */
scalar_t__ chdir(char *);
scalar_t__ chroot(char *);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ perror(char *);
scalar_t__ seteuid(int /*<<< orphan*/);
int /*<<< orphan*/ syntaxe(char *);
int main(int argc, char *argv[]) {
  if (argc < 3)
    syntaxe(argv[0]);
  if (chdir(argv[1]) != 0) {
    perror("chdir");
    exit(1);
  }
  if (chroot(argv[1]) != 0) {
    perror("chroot");
    exit(1);
  }
  if (seteuid(getuid()) < 0) {
    perror("seteuid");
    exit(1);
  }
  execvp(argv[2], argv + 2);
  perror("execvp");
  return (1);
}


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)
cmpl   $0x3,-0x8(%rbp)
jge    11ac <main+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <syntaxe@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
je     11d9 <main+0x59>
lea    0xe36(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <chroot@plt>
cmp    $0x0,%rax
je     1206 <main+0x86>
lea    0xe0f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,%edi
call   10a0 <seteuid@plt>
cmp    $0x0,%rax
jge    1234 <main+0xb4>
lea    0xde8(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
call   1080 <execvp@plt>
lea    0xdc5(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     1191 <main+0x11>
mov    (%rbx),%rdi
call   1060 <syntaxe@plt>
mov    0x8(%rbx),%rdi
call   1040 <chdir@plt>
test   %rax,%rax
jne    11e3 <main+0x63>
mov    0x8(%rbx),%rdi
call   1030 <chroot@plt>
test   %rax,%rax
jne    11ec <main+0x6c>
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%edi
call   10a0 <seteuid@plt>
test   %rax,%rax
js     11f5 <main+0x75>
mov    0x10(%rbx),%rdi
add    $0x10,%rbx
mov    %rbx,%rsi
call   1080 <execvp@plt>
lea    0xe3e(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe16(%rip),%rdi
jmp    11fc <main+0x7c>
lea    0xe13(%rip),%rdi
jmp    11fc <main+0x7c>
lea    0xe11(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"chdir\00"
@.str.1 = [7 x i8] c"chroot\00"
@.str.2 = [8 x i8] c"seteuid\00"
@.str.3 = [7 x i8] c"execvp\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 = load i32, i32* %4
%7 = icmp slt i32 %6, 3
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 @syntaxe(i8* %11)
br label %13
13: ; preds = %8, %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @chdir(i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @chroot(i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = call i32 (...) @getuid()
%33 = call i64 @seteuid(i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = call i32 @execvp(i8* %41, i8** %43)
%45 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [6 x i8] c"chdir\00"
@.str.1 = [7 x i8] c"chroot\00"
@.str.2 = [8 x i8] c"seteuid\00"
@.str.3 = [7 x i8] c"execvp\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @syntaxe(i8* %5)
br label %7
7: ; preds = %4, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @chdir(i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %7
%16 = load i8*, i8** %8
%17 = tail call i64 @chroot(i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = tail call i32 (...) @getuid()
%24 = tail call i64 @seteuid(i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %22
%30 = getelementptr inbounds i8*, i8** %1, i64 2
%31 = load i8*, i8** %30
%32 = tail call i32 @execvp(i8* %31, i8** %30)
%33 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
ret i32 1
}