#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 chdir(char *);
int chroot(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int system(char *);
int main(int argc, char *argv[]) {
  if (argc != 7) {
    fprintf(stderr,
            "Usage: %s chdir_1 chroot_1 system_1 chdir_2 chroot_2 system_2\n",
            argv[0]);
    exit(2);
  }
  fprintf(stderr, "*** chdir[1]\n");
  if (*argv[1] && chdir(argv[1]) == -1) {
    perror("chdir[1]");
    exit(1);
  }
  fprintf(stderr, "*** chroot[1]\n");
  if (chroot(argv[2]) == -1) {
    perror("chroot[1]");
    exit(1);
  }
  fprintf(stderr, "*** system[1]\n");
  if (system(argv[3]) == -1) {
    perror("system[1]");
    exit(1);
  }
  fprintf(stderr, "*** chdir[2]\n");
  if (*argv[4] && chdir(argv[4]) == -1) {
    perror("chdir[2]");
    exit(1);
  }
  fprintf(stderr, "*** chroot[1]\n");
  if (chroot(argv[5]) == -1) {
    perror("chroot[2]");
    exit(1);
  }
  fprintf(stderr, "*** system[1]\n");
  if (system(argv[6]) == -1) {
    perror("system[2]");
    exit(1);
  }
  return 0;
}


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   $0x7,-0x8(%rbp)
je     11a8 <main+0x48>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ff <main+0x9f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11ff <main+0x9f>
lea    0xe5d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
jne    1242 <main+0xe2>
lea    0xe32(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
jne    1285 <main+0x125>
lea    0xe08(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12dc <main+0x17c>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    12dc <main+0x17c>
lea    0xdc9(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
jne    131f <main+0x1bf>
lea    0xd8f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
jne    1362 <main+0x202>
lea    0xd56(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%eax
mov    0x2e70(%rip),%r14
mov    (%r14),%edi
cmp    $0x7,%eax
jne    1257 <main+0xf7>
lea    0xebc(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rbx),%rdi
cmpb   $0x0,(%rdi)
je     11a1 <main+0x41>
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     1296 <main+0x136>
mov    (%r14),%edi
lea    0xeab(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x10(%rbx),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
je     1272 <main+0x112>
mov    (%r14),%edi
lea    0xea1(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x18(%rbx),%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
je     127b <main+0x11b>
mov    (%r14),%edi
lea    0xe97(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x20(%rbx),%rdi
cmpb   $0x0,(%rdi)
je     120f <main+0xaf>
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     129f <main+0x13f>
mov    (%r14),%edi
lea    0xe3d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x28(%rbx),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
je     1284 <main+0x124>
mov    (%r14),%edi
lea    0xe37(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x30(%rbx),%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
je     128d <main+0x12d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rbx),%rdx
lea    0xd9f(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
lea    0xdec(%rip),%rdi
jmp    12a6 <main+0x146>
lea    0xdfc(%rip),%rdi
jmp    12a6 <main+0x146>
lea    0xe14(%rip),%rdi
jmp    12a6 <main+0x146>
lea    0xe15(%rip),%rdi
jmp    12a6 <main+0x146>
lea    0xdb0(%rip),%rdi
jmp    12a6 <main+0x146>
lea    0xdf0(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [63 x i8] c"Usage: %s chdir_1 chroot_1 system_1 chdir_2 chroot_2 system_2\0A\00"
@.str.1 = [14 x i8] c"*** chdir[1]\0A\00"
@.str.2 = [9 x i8] c"chdir[1]\00"
@.str.3 = [15 x i8] c"*** chroot[1]\0A\00"
@.str.4 = [10 x i8] c"chroot[1]\00"
@.str.5 = [15 x i8] c"*** system[1]\0A\00"
@.str.6 = [10 x i8] c"system[1]\00"
@.str.7 = [14 x i8] c"*** chdir[2]\0A\00"
@.str.8 = [9 x i8] c"chdir[2]\00"
@.str.9 = [10 x i8] c"chroot[2]\00"
@.str.10 = [10 x i8] c"system[2]\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 ne i32 %6, 7
br i1 %7, label %8, label %15
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 2)
unreachable
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @chdir(i8* %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %24, %15
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @chroot(i8* %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %33
%42 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %33
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32 @system(i8* %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %44
%53 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %44
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 4
%60 = load i8*, i8** %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %73
64: ; preds = %55
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 4
%67 = load i8*, i8** %66
%68 = call i32 @chdir(i8* %67)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %73
70: ; preds = %64
%71 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %64, %55
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 5
%78 = load i8*, i8** %77
%79 = call i32 @chroot(i8* %78)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %84
81: ; preds = %73
%82 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %73
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 6
%89 = load i8*, i8** %88
%90 = call i32 @system(i8* %89)
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %95
92: ; preds = %84
%93 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %84
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [63 x i8] c"Usage: %s chdir_1 chroot_1 system_1 chdir_2 chroot_2 system_2\0A\00"
@.str.1 = [14 x i8] c"*** chdir[1]\0A\00"
@.str.2 = [9 x i8] c"chdir[1]\00"
@.str.3 = [15 x i8] c"*** chroot[1]\0A\00"
@.str.4 = [10 x i8] c"chroot[1]\00"
@.str.5 = [15 x i8] c"*** system[1]\0A\00"
@.str.6 = [10 x i8] c"system[1]\00"
@.str.7 = [14 x i8] c"*** chdir[2]\0A\00"
@.str.8 = [9 x i8] c"chdir[2]\00"
@.str.9 = [10 x i8] c"chroot[2]\00"
@.str.10 = [10 x i8] c"system[2]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 7
%4 = load i32, i32* @stderr
br i1 %3, label %9, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 2)
unreachable
9: ; preds = %2
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = tail call i32 @chdir(i8* %12)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %15, %9
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i32 @chroot(i8* %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %21
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%34 = getelementptr inbounds i8*, i8** %1, i64 3
%35 = load i8*, i8** %34
%36 = tail call i32 @system(i8* %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %31
%39 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %31
%42 = load i32, i32* @stderr
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%44 = getelementptr inbounds i8*, i8** %1, i64 4
%45 = load i8*, i8** %44
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 0
br i1 %47, label %54, label %48
48: ; preds = %41
%49 = tail call i32 @chdir(i8* %45)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%53 = tail call i32 @exit(i32 1)
unreachable
54: ; preds = %48, %41
%55 = load i32, i32* @stderr
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%57 = getelementptr inbounds i8*, i8** %1, i64 5
%58 = load i8*, i8** %57
%59 = tail call i32 @chroot(i8* %58)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %64
61: ; preds = %54
%62 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%63 = tail call i32 @exit(i32 1)
unreachable
64: ; preds = %54
%65 = load i32, i32* @stderr
%66 = tail call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%67 = getelementptr inbounds i8*, i8** %1, i64 6
%68 = load i8*, i8** %67
%69 = tail call i32 @system(i8* %68)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
%73 = tail call i32 @exit(i32 1)
unreachable
74: ; preds = %64
ret i32 0
}