#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
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*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int sh6_exec_bash(char *filename) {
  FILE *file;
  char *line = NULL;
  size_t len = 0;
  file = fopen(filename, "r");
  if (file == NULL)
    return 1;
  while (getline(&line, &len, file) > -1) {
    if (strlen(line) > 1) {
      printf("sh6 > %s", line);
      if (mysh6_system(line) < 0) {
        fprintf(stderr, "Error when executing '%s'\n", line);
        return EXIT_FAILURE;
      }
    }
  }
  fclose(file);
  if (line)
    free(line);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<sh6_exec_bash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c7 <sh6_exec_bash+0x47>
movl   $0x1,-0x4(%rbp)
jmp    1278 <sh6_exec_bash+0xf8>
jmp    11cc <sh6_exec_bash+0x4c>
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10a0 <getline@plt>
cmp    $0xffffffff,%eax
jle    124f <sh6_exec_bash+0xcf>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jle    124a <sh6_exec_bash+0xca>
mov    -0x20(%rbp),%rsi
lea    0xdff(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <mysh6_system@plt>
cmp    $0x0,%rax
jge    1245 <sh6_exec_bash+0xc5>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xddc(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1278 <sh6_exec_bash+0xf8>
jmp    124a <sh6_exec_bash+0xca>
jmp    11cc <sh6_exec_bash+0x4c>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     126c <sh6_exec_bash+0xec>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sh6_exec_bash>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe5c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1262 <sh6_exec_bash+0xe2>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   10a0 <getline@plt>
test   %eax,%eax
js     1240 <sh6_exec_bash+0xc0>
lea    0xe30(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    11f2 <sh6_exec_bash+0x72>
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10a0 <getline@plt>
test   %eax,%eax
js     1240 <sh6_exec_bash+0xc0>
mov    0x8(%rsp),%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     11e0 <sh6_exec_bash+0x60>
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1060 <printf@plt>
mov    0x8(%rsp),%rdi
call   1080 <mysh6_system@plt>
test   %rax,%rax
jns    11e0 <sh6_exec_bash+0x60>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xdd9(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d9a(%rip),%rax
jmp    125e <sh6_exec_bash+0xde>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1257 <sh6_exec_bash+0xd7>
call   1030 <free@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
jmp    1267 <sh6_exec_bash+0xe7>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [9 x i8] c"sh6 > %s\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Error when executing '%s'\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @sh6_exec_bash(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i8* null, i8** %5
store i64 0, i64* %6
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 1, i32* %2
br label %44
12: ; preds = %1
br label %13
13: ; preds = %33, %12
%14 = load i32*, i32** %4
%15 = call i32 @getline(i8** %5, i64* %6, i32* %14)
%16 = icmp sgt i32 %15, -1
br i1 %16, label %17, label %34
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = icmp sgt i32 %19, 1
br i1 %20, label %21, label %33
21: ; preds = %17
%22 = load i8*, i8** %5
%23 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %5
%25 = call i64 @mysh6_system(i8* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %5
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %2
br label %44
32: ; preds = %21
br label %33
33: ; preds = %32, %17
br label %13
34: ; preds = %13
%35 = load i32*, i32** %4
%36 = call i32 @fclose(i32* %35)
%37 = load i8*, i8** %5
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = load i8*, i8** %5
%41 = call i32 @free(i8* %40)
br label %42
42: ; preds = %39, %34
%43 = load i32, i32* @EXIT_SUCCESS
store i32 %43, i32* %2
br label %44
44: ; preds = %42, %27, %11
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [9 x i8] c"sh6 > %s\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Error when executing '%s'\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @sh6_exec_bash(i8* nocapture %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %37, label %8
8: ; preds = %1
%9 = call i32 @getline(i8** %2, i64* %3, i32* %6)
%10 = icmp sgt i32 %9, -1
br i1 %10, label %11, label %29
11: ; preds = %8, %26
%12 = load i8*, i8** %2
%13 = call i32 @strlen(i8* %12)
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %2
%19 = call i64 @mysh6_system(i8* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %2
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
br label %37
26: ; preds = %15, %11
%27 = call i32 @getline(i8** %2, i64* %3, i32* %6)
%28 = icmp sgt i32 %27, -1
br i1 %28, label %11, label %29
29: ; preds = %26, %8
%30 = call i32 @fclose(i32* %6)
%31 = load i8*, i8** %2
%32 = icmp eq i8* %31, null
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = call i32 @free(i8* %31)
br label %35
35: ; preds = %33, %29
%36 = load i32, i32* @EXIT_SUCCESS
br label %37
37: ; preds = %1, %35, %21
%38 = phi i32 [ %25, %21 ], [ %36, %35 ], [ 1, %1 ]
ret i32 %38
}