#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 /*<<< orphan*/ run_test(char *, int, char **);
int test_error(int argc, char **argv) {
  char *args[] = {"./shell", NULL};
  FILE *err;
  int pid_tmp, status_tmp;
  run_test("/bin/ls -z \nexit\n", 1, args);
  err = fopen("test.err", "r");
  do {
    if (fscanf(err,
               "/bin/ls: invalid option -- 'z'\n"
               "Try `/bin/ls --help' for more information.\n"
               "shell: Process %d exited with status %d\n",
               &pid_tmp, &status_tmp) != 2)
      exit(EXIT_FAILURE);
  } while (0);
  fclose(err);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<test_error>:
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    0xe89(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe77(%rip),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1040 <fscanf@plt>
cmp    $0x2,%eax
je     11d0 <test_error+0x80>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11d5 <test_error+0x85>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_error>:
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    0xe9c(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe8f(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x2,%eax
jne    11c2 <test_error+0x72>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"./shell\00"
@__const.test_error.args = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [18 x i8] c"/bin/ls -z \0Aexit\0A\00"
@.str.2 = [9 x i8] c"test.err\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [115 x i8] c"/bin/ls: invalid option -- 'z'\0ATry `/bin/ls --help' for more information.\0Ashell: Process %d exited with status %d\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @test_error(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [2 x i8*]
%6 = alloca i32*
%7 = alloca i32
%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 ([18 x i8], [18 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 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([115 x i8], [115 x i8]* @.str.4, i64 0, i64 0), i32* %7, i32* %8)
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %13
br label %21
21: ; preds = %20
%22 = load i32*, i32** %6
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* @EXIT_SUCCESS
ret i32 %24
}

LLVM IR (-O2):
@.str = [8 x i8] c"./shell\00"
@__const.test_error.args = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [18 x i8] c"/bin/ls -z \0Aexit\0A\00"
@.str.2 = [9 x i8] c"test.err\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [115 x i8] c"/bin/ls: invalid option -- 'z'\0ATry `/bin/ls --help' for more information.\0Ashell: Process %d exited with status %d\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @test_error(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i8*]
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [2 x i8*]* %3 to i8*
%7 = bitcast i32* %4 to i8*
%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 ([18 x i8], [18 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 ([115 x i8], [115 x i8]* @.str.4, i64 0, i64 0), i32* %4, i32* %5)
%13 = icmp eq i32 %12, 2
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
}