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


x86 assembly (clang, -O0):
<test_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    0xe9b(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x32(%rbp),%rdx
lea    0xe87(%rip),%rsi
lea    -0x38(%rbp),%r9
mov    %r9,%rcx
mov    %r9,%r8
call   1040 <fscanf@plt>
cmp    $0x4,%eax
je     11d6 <test_path+0x86>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11db <test_path+0x8b>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_path>:
push   %rbx
sub    $0x30,%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    0xeae(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xea3(%rip),%rsi
lea    0x26(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rax,%rdi
mov    %rcx,%r8
mov    %rcx,%r9
call   1040 <fscanf@plt>
cmp    $0x4,%eax
jne    11c8 <test_path+0x78>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbx
ret
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

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

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