#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 /*<<< orphan*/ EXIT_FAILURE;
int const STDERR_FILENO;
int const STDOUT_FILENO;
int /*<<< orphan*/ close(int const);
int dup2(int const, int const);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ kyua_run_exec(char const *, char const *const *);
void run_list(const char *test_program, const int stdout_fds[2]) {
  (void)close(stdout_fds[0]);
  if (stdout_fds[1] != STDOUT_FILENO) {
    if (dup2(stdout_fds[1], STDOUT_FILENO) == -1)
      err(EXIT_FAILURE, "dup2 failed");
    (void)close(stdout_fds[1]);
  }
  if (dup2(STDOUT_FILENO, STDERR_FILENO) == -1)
    err(EXIT_FAILURE, "dup2 failed");
  const char *const program_args[] = {test_program, "-l", NULL};
  kyua_run_exec(test_program, program_args);
}


x86 assembly (clang, -O0):
<run_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2e87(%rip),%rcx
cmp    (%rcx),%eax
je     11b0 <run_list+0x70>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    11a4 <run_list+0x64>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1060 <err@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <close@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    11e5 <run_list+0xa5>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
call   1060 <err@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe20(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <kyua_run_exec@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_list>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%edi
call   1050 <close@plt>
mov    0x4(%rbx),%edi
test   %edi,%edi
je     1184 <run_list+0x44>
xor    %esi,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    117c <run_list+0x3c>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1060 <err@plt>
mov    0x4(%rbx),%edi
call   1050 <close@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    11a7 <run_list+0x67>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1060 <err@plt>
mov    %r14,(%rsp)
lea    0xe62(%rip),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <kyua_run_exec@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@STDOUT_FILENO = constant i32 0
@EXIT_FAILURE = global i32 0
@.str = [12 x i8] c"dup2 failed\00"
@STDERR_FILENO = constant i32 0
@.str.1 = [3 x i8] c"-l\00"
define void @run_list(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [3 x i8*]
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %4
%7 = getelementptr inbounds i32, i32* %6, i64 0
%8 = load i32, i32* %7
%9 = call i32 @close(i32 %8)
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i64 1
%12 = load i32, i32* %11
%13 = load i32, i32* @STDOUT_FILENO
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %2
%16 = load i32*, i32** %4
%17 = getelementptr inbounds i32, i32* %16, i64 1
%18 = load i32, i32* %17
%19 = load i32, i32* @STDOUT_FILENO
%20 = call i32 @dup2(i32 %18, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @err(i32 %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %22, %15
%26 = load i32*, i32** %4
%27 = getelementptr inbounds i32, i32* %26, i64 1
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
br label %30
30: ; preds = %25, %2
%31 = load i32, i32* @STDOUT_FILENO
%32 = load i32, i32* @STDERR_FILENO
%33 = call i32 @dup2(i32 %31, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @err(i32 %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %38
38: ; preds = %35, %30
%39 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%40 = load i8*, i8** %3
store i8* %40, i8** %39
%41 = getelementptr inbounds i8*, i8** %39, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %41
%42 = getelementptr inbounds i8*, i8** %41, i64 1
store i8* null, i8** %42
%43 = load i8*, i8** %3
%44 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%45 = call i32 @kyua_run_exec(i8* %43, i8** %44)
ret void
}

LLVM IR (-O2):
@STDOUT_FILENO = constant i32 0
@EXIT_FAILURE = global i32 0
@.str = [12 x i8] c"dup2 failed\00"
@STDERR_FILENO = constant i32 0
@.str.1 = [3 x i8] c"-l\00"
define void @run_list(i8* %0, i32* nocapture %1) {
%3 = alloca [3 x i8*]
%4 = load i32, i32* %1
%5 = tail call i32 @close(i32 %4)
%6 = getelementptr inbounds i32, i32* %1, i64 1
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %2
%10 = tail call i32 @dup2(i32 %7, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @err(i32 %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %12, %9
%16 = load i32, i32* %6
%17 = tail call i32 @close(i32 %16)
br label %18
18: ; preds = %15, %2
%19 = tail call i32 @dup2(i32 0, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @err(i32 %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %21, %18
%25 = bitcast [3 x i8*]* %3 to i8*
%26 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
store i8* %0, i8** %26
%27 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %27
%28 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 2
store i8* null, i8** %28
%29 = call i32 @kyua_run_exec(i8* %0, i8** %26)
ret void
}