#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 /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *);
int /*<<< orphan*/ run_test(char *, int, char **);
int test_basic(int argc, char **argv) {
  char *args[] = {"./shell", NULL};
  FILE *out;
  int pid_tmp;
  run_test("/bin/echo hello\n/bin/echo world!\nexit\n", 1, args);
  out = fopen("test.out", "r");
  do {
    if (fscanf(out,
               "hello\n"
               "world!\n"
               "Shell(pid=%d)> "
               "Shell(pid=%d)> "
               "Shell(pid=%d)> ",
               &pid_tmp, &pid_tmp, &pid_tmp) != 3)
      exit(EXIT_FAILURE);
  } while (0);
  fclose(out);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<test_basic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c9a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c97(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rdx
lea    0xe88(%rip),%rdi
mov    $0x1,%esi
call   1050 <run_test@plt>
lea    0xe9e(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe8e(%rip),%rsi
lea    -0x2c(%rbp),%r8
mov    %r8,%rdx
mov    %r8,%rcx
call   1040 <fscanf@plt>
cmp    $0x3,%eax
je     11d2 <test_basic+0x82>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11d7 <test_basic+0x87>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_basic>:
push   %rbx
sub    $0x20,%rsp
movaps 0x2ca4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xea0(%rip),%rdi
lea    0x10(%rsp),%rdx
mov    $0x1,%esi
call   1050 <run_test@plt>
lea    0xeb1(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xea6(%rip),%rsi
lea    0xc(%rsp),%rcx
mov    %rax,%rdi
mov    %rcx,%rdx
mov    %rcx,%r8
call   1040 <fscanf@plt>
cmp    $0x3,%eax
jne    11c3 <test_basic+0x73>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"./shell\00"
@__const.test_basic.args = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [39 x i8] c"/bin/echo hello\0A/bin/echo world!\0Aexit\0A\00"
@.str.2 = [9 x i8] c"test.out\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [59 x i8] c"hello\0Aworld!\0AShell(pid=%d)> Shell(pid=%d)> Shell(pid=%d)> \00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @test_basic(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [2 x i8*]
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = bitcast [2 x i8*]* %5 to i8*
%9 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
%10 = call i32 @run_test(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 1, i8** %9)
%11 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %11, i32** %6
br label %12
12: ; preds = %2
%13 = load i32*, i32** %6
%14 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0), i32* %7, i32* %7, i32* %7)
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %12
br label %20
20: ; preds = %19
%21 = load i32*, i32** %6
%22 = call i32 @fclose(i32* %21)
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}

LLVM IR (-O2):
@.str = [8 x i8] c"./shell\00"
@__const.test_basic.args = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [39 x i8] c"/bin/echo hello\0A/bin/echo world!\0Aexit\0A\00"
@.str.2 = [9 x i8] c"test.out\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [59 x i8] c"hello\0Aworld!\0AShell(pid=%d)> Shell(pid=%d)> Shell(pid=%d)> \00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @test_basic(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i8*]
%4 = alloca i32
%5 = bitcast [2 x i8*]* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%8 = call i32 @run_test(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 1, i8** %7)
%9 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0), i32* %4, i32* %4, i32* %4)
%11 = icmp eq i32 %10, 3
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = call i32 @fclose(i32* %9)
%17 = load i32, i32* @EXIT_SUCCESS
ret i32 %17
}