#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*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int dup2(int, int);
int fcntl(int, int /*<<< orphan*/, ...);
void _testbench_set_pipe_dup(int stream) {
  int stream_1_dup = dup2(stream, 1);
  int stream_2_dup = dup2(stream, 2);
  fcntl(stream_1_dup, F_SETFL, fcntl(stream_1_dup, F_GETFL) | O_NONBLOCK);
  fcntl(stream_2_dup, F_SETFL, fcntl(stream_2_dup, F_GETFL) | O_NONBLOCK);
}


x86 assembly (clang, -O0):
<_testbench_set_pipe_dup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x2,%esi
call   1040 <dup2@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    %eax,%edx
mov    0x2e69(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    %eax,%edx
mov    0x2e2c(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_testbench_set_pipe_dup>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    $0x2,%esi
call   1040 <dup2@plt>
mov    %eax,%ebx
mov    0x2e8a(%rip),%r15
mov    (%r15),%r14d
mov    0x2e78(%rip),%r12
mov    (%r12),%esi
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    0x2e7c(%rip),%r13
or     0x0(%r13),%eax
mov    %ebp,%edi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    (%r15),%ebp
mov    (%r12),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
or     0x0(%r13),%eax
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fcntl@plt>

LLVM IR (-O0):
@F_SETFL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
define void @_testbench_set_pipe_dup(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @dup2(i32 %5, i32 1)
store i32 %6, i32* %3
%7 = load i32, i32* %2
%8 = call i32 @dup2(i32 %7, i32 2)
store i32 %8, i32* %4
%9 = load i32, i32* %3
%10 = load i32, i32* @F_SETFL
%11 = load i32, i32* %3
%12 = load i32, i32* @F_GETFL
%13 = call i32 (i32, i32, ...) @fcntl(i32 %11, i32 %12)
%14 = load i32, i32* @O_NONBLOCK
%15 = or i32 %13, %14
%16 = call i32 (i32, i32, ...) @fcntl(i32 %9, i32 %10, i32 %15)
%17 = load i32, i32* %4
%18 = load i32, i32* @F_SETFL
%19 = load i32, i32* %4
%20 = load i32, i32* @F_GETFL
%21 = call i32 (i32, i32, ...) @fcntl(i32 %19, i32 %20)
%22 = load i32, i32* @O_NONBLOCK
%23 = or i32 %21, %22
%24 = call i32 (i32, i32, ...) @fcntl(i32 %17, i32 %18, i32 %23)
ret void
}

LLVM IR (-O2):
@F_SETFL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
define void @_testbench_set_pipe_dup(i32 %0) {
%2 = tail call i32 @dup2(i32 %0, i32 1)
%3 = tail call i32 @dup2(i32 %0, i32 2)
%4 = load i32, i32* @F_SETFL
%5 = load i32, i32* @F_GETFL
%6 = tail call i32 (i32, i32, ...) @fcntl(i32 %2, i32 %5)
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %7, %6
%9 = tail call i32 (i32, i32, ...) @fcntl(i32 %2, i32 %4, i32 %8)
%10 = load i32, i32* @F_SETFL
%11 = load i32, i32* @F_GETFL
%12 = tail call i32 (i32, i32, ...) @fcntl(i32 %3, i32 %11)
%13 = load i32, i32* @O_NONBLOCK
%14 = or i32 %13, %12
%15 = tail call i32 (i32, i32, ...) @fcntl(i32 %3, i32 %10, i32 %14)
ret void
}