#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 EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
scalar_t__ mysh6_system(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sh6_exec_bash(char *);
scalar_t__ sh6_is_exit(char *);
scalar_t__ sh6_modify_path(char *);
char *sh6_path_to_custom_programs(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  int i;
  char *path_to_pgr;
  char *pgr_name;
  char *cmd_line = NULL;
  size_t cmd_line_len = 0;
  pgr_name = argv[0];
  if ((path_to_pgr = sh6_path_to_custom_programs(argv[0])) == NULL) {
    perror(pgr_name);
    return EXIT_FAILURE;
  }
  if (sh6_modify_path(path_to_pgr)) {
    perror(pgr_name);
    return EXIT_FAILURE;
  }
  free(path_to_pgr);
  if (argc >= 2) {
    for (i = 1; i < argc; i++)
      sh6_exec_bash(argv[i]);
  } else {
    while (1) {
      if (feof(stdin)) {
        printf("\n");
        break;
      }
      printf("sh6 > ");
      if (getline(&cmd_line, &cmd_line_len, stdin) > -1) {
        if (sh6_is_exit(cmd_line))
          break;
        if (mysh6_system(cmd_line) < 0)
          fprintf(stderr, "Error when executing '%s'\n", cmd_line);
      }
    }
  }
  free(cmd_line);
  printf("Bye!\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <sh6_path_to_custom_programs@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1215 <main+0x65>
mov    -0x28(%rbp),%rdi
call   10c0 <perror@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1359 <main+0x1a9>
mov    -0x20(%rbp),%rdi
call   1080 <sh6_modify_path@plt>
cmp    $0x0,%rax
je     1242 <main+0x92>
mov    -0x28(%rbp),%rdi
call   10c0 <perror@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1359 <main+0x1a9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x2,-0x8(%rbp)
jl     128c <main+0xdc>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1287 <main+0xd7>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10a0 <sh6_exec_bash@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    125c <main+0xac>
jmp    1338 <main+0x188>
jmp    1291 <main+0xe1>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     12ba <main+0x10a>
lea    0xd76(%rip),%rdi
call   1050 <printf@plt>
jmp    1333 <main+0x183>
lea    0xd3f(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10d0 <getline@plt>
cmp    $0xffffffff,%eax
jle    132e <main+0x17e>
mov    -0x30(%rbp),%rdi
call   1040 <sh6_is_exit@plt>
cmp    $0x0,%rax
je     12fd <main+0x14d>
jmp    1333 <main+0x183>
mov    -0x30(%rbp),%rdi
call   1090 <mysh6_system@plt>
cmp    $0x0,%rax
jge    1329 <main+0x179>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xce3(%rip),%rsi
call   1060 <fprintf@plt>
jmp    132e <main+0x17e>
jmp    1291 <main+0xe1>
jmp    1338 <main+0x188>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
lea    0xcda(%rip),%rdi
call   1050 <printf@plt>
mov    0x2c74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %edi,%r14d
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    (%rsi),%r15
mov    %r15,%rdi
call   10d0 <sh6_path_to_custom_programs@plt>
test   %rax,%rax
je     132c <main+0x15c>
mov    %rax,%rbp
mov    %rax,%rdi
call   10a0 <sh6_modify_path@plt>
test   %rax,%rax
jne    132c <main+0x15c>
mov    %rbp,%rdi
call   1030 <free@plt>
cmp    $0x2,%r14d
jl     1254 <main+0x84>
mov    %r14d,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%rbx,8),%rdi
call   10c0 <sh6_exec_bash@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1240 <main+0x70>
jmp    1272 <main+0xa2>
mov    0x2d8d(%rip),%rbp
mov    0x0(%rbp),%edi
call   1090 <feof@plt>
test   %rax,%rax
je     12a0 <main+0xd0>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
lea    0xd9f(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd59(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%rbx
mov    0x2d20(%rip),%r13
lea    0xd48(%rip),%r12
jmp    12dd <main+0x10d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
call   1090 <feof@plt>
test   %rax,%rax
jne    1268 <main+0x98>
mov    %r14,%rdi
call   1070 <printf@plt>
mov    0x0(%rbp),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   10f0 <getline@plt>
test   %eax,%eax
js     12d0 <main+0x100>
mov    0x8(%rsp),%rdi
call   1060 <sh6_is_exit@plt>
test   %rax,%rax
jne    1272 <main+0xa2>
mov    0x8(%rsp),%rdi
call   10b0 <mysh6_system@plt>
test   %rax,%rax
jns    12d0 <main+0x100>
mov    0x0(%r13),%edi
mov    0x8(%rsp),%rdx
mov    %r12,%rsi
call   1080 <fprintf@plt>
jmp    12d0 <main+0x100>
mov    %r15,%rdi
call   10e0 <perror@plt>
mov    0x2c95(%rip),%rax
jmp    128f <main+0xbf>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [7 x i8] c"sh6 > \00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Error when executing '%s'\0A\00"
@.str.3 = [6 x i8] c"Bye!\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %9
store i64 0, i64* %10
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
store i8* %13, i8** %8
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i8* @sh6_path_to_custom_programs(i8* %16)
store i8* %17, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i8*, i8** %8
%21 = call i32 @perror(i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %3
br label %85
23: ; preds = %2
%24 = load i8*, i8** %7
%25 = call i64 @sh6_modify_path(i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i8*, i8** %8
%29 = call i32 @perror(i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %85
31: ; preds = %23
%32 = load i8*, i8** %7
%33 = call i32 @free(i8* %32)
%34 = load i32, i32* %4
%35 = icmp sge i32 %34, 2
br i1 %35, label %36, label %52
36: ; preds = %31
store i32 1, i32* %6
br label %37
37: ; preds = %48, %36
%38 = load i32, i32* %6
%39 = load i32, i32* %4
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %51
41: ; preds = %37
%42 = load i8**, i8*** %5
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
%47 = call i32 @sh6_exec_bash(i8* %46)
br label %48
48: ; preds = %41
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %37
51: ; preds = %37
br label %80
52: ; preds = %31
br label %53
53: ; preds = %52, %78
%54 = load i32, i32* @stdin
%55 = call i64 @feof(i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %79
59: ; preds = %53
%60 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%61 = load i32, i32* @stdin
%62 = call i32 @getline(i8** %9, i64* %10, i32 %61)
%63 = icmp sgt i32 %62, -1
br i1 %63, label %64, label %78
64: ; preds = %59
%65 = load i8*, i8** %9
%66 = call i64 @sh6_is_exit(i8* %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %64
br label %79
69: ; preds = %64
%70 = load i8*, i8** %9
%71 = call i64 @mysh6_system(i8* %70)
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %77
73: ; preds = %69
%74 = load i32, i32* @stderr
%75 = load i8*, i8** %9
%76 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %75)
br label %77
77: ; preds = %73, %69
br label %78
78: ; preds = %77, %59
br label %53
79: ; preds = %68, %57
br label %80
80: ; preds = %79, %51
%81 = load i8*, i8** %9
%82 = call i32 @free(i8* %81)
%83 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%84 = load i32, i32* @EXIT_SUCCESS
store i32 %84, i32* %3
br label %85
85: ; preds = %80, %27, %19
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@.str.1 = [7 x i8] c"sh6 > \00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Error when executing '%s'\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [5 x i8] c"Bye!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = load i8*, i8** %1
%8 = tail call i8* @sh6_path_to_custom_programs(i8* %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @perror(i8* %7)
br label %60
12: ; preds = %2
%13 = tail call i64 @sh6_modify_path(i8* %8)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @perror(i8* %7)
br label %60
17: ; preds = %12
%18 = tail call i32 @free(i8* %8)
%19 = icmp sgt i32 %0, 1
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = zext i32 %0 to i64
br label %26
22: ; preds = %17
%23 = load i32, i32* @stdin
%24 = call i64 @feof(i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %35, label %33
26: ; preds = %20, %26
%27 = phi i64 [ 1, %20 ], [ %31, %26 ]
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = load i8*, i8** %28
%30 = tail call i32 @sh6_exec_bash(i8* %29)
%31 = add nuw nsw i64 %27, 1
%32 = icmp eq i64 %31, %21
br i1 %32, label %56, label %26
33: ; preds = %52, %22
%34 = call i32 @putchar(i32 10)
br label %56
35: ; preds = %22, %52
%36 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @stdin
%38 = call i32 @getline(i8** %3, i64* %4, i32 %37)
%39 = icmp sgt i32 %38, -1
br i1 %39, label %40, label %52
40: ; preds = %35
%41 = load i8*, i8** %3
%42 = call i64 @sh6_is_exit(i8* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %56
44: ; preds = %40
%45 = load i8*, i8** %3
%46 = call i64 @mysh6_system(i8* %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %3
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %44, %48, %35
%53 = load i32, i32* @stdin
%54 = call i64 @feof(i32 %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %35, label %33
56: ; preds = %40, %26, %33
%57 = load i8*, i8** %3
%58 = call i32 @free(i8* %57)
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %60
60: ; preds = %56, %15, %10
%61 = phi i32* [ @EXIT_FAILURE, %10 ], [ @EXIT_FAILURE, %15 ], [ @EXIT_SUCCESS, %56 ]
%62 = load i32, i32* %61
ret i32 %62
}