#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 *, 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);
  };
  if (*argv[1] && chdir(argv[1]) == -1) {
    perror("chdir[1]");
    exit(1);
  };
  if (chroot(argv[2]) == -1) {
    perror("chroot[1]");
    exit(1);
  };
  if (system(argv[3]) == -1) {
    perror("system[1]");
    exit(1);
  };
  if (*argv[4] && chdir(argv[4]) == -1) {
    perror("chdir[2]");
    exit(1);
  };
  if (chroot(argv[5]) == -1) {
    perror("chroot[2]");
    exit(1);
  };
  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     11a6 <main+0x46>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e6 <main+0x86>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11e6 <main+0x86>
lea    0xe68(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
jne    1212 <main+0xb2>
lea    0xe45(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
jne    123e <main+0xde>
lea    0xe23(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     127e <main+0x11e>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    127e <main+0x11e>
lea    0xded(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
jne    12aa <main+0x14a>
lea    0xdca(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
jne    12d6 <main+0x176>
lea    0xda8(%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   %rbx
mov    %rsi,%rbx
cmp    $0x7,%edi
jne    11cf <main+0x6f>
mov    0x8(%rbx),%rdi
cmpb   $0x0,(%rdi)
je     1180 <main+0x20>
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     1215 <main+0xb5>
mov    0x10(%rbx),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
je     11f1 <main+0x91>
mov    0x18(%rbx),%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
je     11fa <main+0x9a>
mov    0x20(%rbx),%rdi
cmpb   $0x0,(%rdi)
je     11af <main+0x4f>
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     121e <main+0xbe>
mov    0x28(%rbx),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
je     1203 <main+0xa3>
mov    0x30(%rbx),%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
je     120c <main+0xac>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe1e(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
lea    0xe50(%rip),%rdi
jmp    1225 <main+0xc5>
lea    0xe51(%rip),%rdi
jmp    1225 <main+0xc5>
lea    0xe5b(%rip),%rdi
jmp    1225 <main+0xc5>
lea    0xe5c(%rip),%rdi
jmp    1225 <main+0xc5>
lea    0xe23(%rip),%rdi
jmp    1225 <main+0xc5>
lea    0xe37(%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 = [9 x i8] c"chdir[1]\00"
@.str.2 = [10 x i8] c"chroot[1]\00"
@.str.3 = [10 x i8] c"system[1]\00"
@.str.4 = [9 x i8] c"chdir[2]\00"
@.str.5 = [10 x i8] c"chroot[2]\00"
@.str.6 = [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 @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 i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @chdir(i8* %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22, %15
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @chroot(i8* %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %31
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = call i32 @system(i8* %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %40
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 4
%52 = load i8*, i8** %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %65
56: ; preds = %49
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 4
%59 = load i8*, i8** %58
%60 = call i32 @chdir(i8* %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %65
62: ; preds = %56
%63 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %56, %49
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 5
%68 = load i8*, i8** %67
%69 = call i32 @chroot(i8* %68)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %74
71: ; preds = %65
%72 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %65
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 6
%77 = load i8*, i8** %76
%78 = call i32 @system(i8* %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %83
80: ; preds = %74
%81 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %74
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 = [9 x i8] c"chdir[1]\00"
@.str.2 = [10 x i8] c"chroot[1]\00"
@.str.3 = [10 x i8] c"system[1]\00"
@.str.4 = [9 x i8] c"chdir[2]\00"
@.str.5 = [10 x i8] c"chroot[2]\00"
@.str.6 = [10 x i8] c"system[2]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 7
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, 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 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %9
%15 = tail call i32 @chdir(i8* %11)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %14, %9
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @chroot(i8* %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = getelementptr inbounds i8*, i8** %1, i64 3
%30 = load i8*, i8** %29
%31 = tail call i32 @system(i8* %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %28
%37 = getelementptr inbounds i8*, i8** %1, i64 4
%38 = load i8*, i8** %37
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 0
br i1 %40, label %47, label %41
41: ; preds = %36
%42 = tail call i32 @chdir(i8* %38)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %41, %36
%48 = getelementptr inbounds i8*, i8** %1, i64 5
%49 = load i8*, i8** %48
%50 = tail call i32 @chroot(i8* %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%54 = tail call i32 @exit(i32 1)
unreachable
55: ; preds = %47
%56 = getelementptr inbounds i8*, i8** %1, i64 6
%57 = load i8*, i8** %56
%58 = tail call i32 @system(i8* %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %55
%61 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%62 = tail call i32 @exit(i32 1)
unreachable
63: ; preds = %55
ret i32 0
}