#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 */
struct popen_noshell_clone_arg {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ close(int /*<<< orphan*/);
scalar_t__ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ warn(char *);
void _popen_noshell_child_process_cleanup_fail_and_exit(
    int exit_code, struct popen_noshell_clone_arg *arg_ptr) {
  if (fflush(stdout) != 0) {
    warn("fflush(stdout)");
    _exit(255);
  };
  if (fflush(stderr) != 0) {
    warn("fflush(stderr)");
    _exit(255);
  };
  close(STDIN_FILENO);
  close(STDOUT_FILENO);
  close(STDERR_FILENO);
  _exit(exit_code);
}


x86 assembly (clang, -O0):
<_popen_noshell_child_process_cleanup_fail_and_exit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
cmp    $0x0,%rax
je     117d <_popen_noshell_child_process_cleanup_fail_and_exit+0x3d>
lea    0xe92(%rip),%rdi
call   1040 <warn@plt>
mov    $0xff,%edi
call   1030 <_exit@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
cmp    $0x0,%rax
je     11ab <_popen_noshell_child_process_cleanup_fail_and_exit+0x6b>
lea    0xe73(%rip),%rdi
call   1040 <warn@plt>
mov    $0xff,%edi
call   1030 <_exit@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<_popen_noshell_child_process_cleanup_fail_and_exit>:
push   %rbx
mov    %edi,%ebx
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
test   %rax,%rax
jne    119a <_popen_noshell_child_process_cleanup_fail_and_exit+0x5a>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
test   %rax,%rax
jne    11a3 <_popen_noshell_child_process_cleanup_fail_and_exit+0x63>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    %ebx,%edi
call   1030 <_exit@plt>
lea    0xe5f(%rip),%rdi
jmp    11aa <_popen_noshell_child_process_cleanup_fail_and_exit+0x6a>
lea    0xe65(%rip),%rdi
call   1040 <warn@plt>
mov    $0xff,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.popen_noshell_clone_arg = type { i32 }
@stdout = global i32 0
@.str = [15 x i8] c"fflush(stdout)\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"fflush(stderr)\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define void @_popen_noshell_child_process_cleanup_fail_and_exit(i32 %0, %struct.popen_noshell_clone_arg* %1) {
%3 = alloca i32
%4 = alloca %struct.popen_noshell_clone_arg*
store i32 %0, i32* %3
store %struct.popen_noshell_clone_arg* %1, %struct.popen_noshell_clone_arg** %4
%5 = load i32, i32* @stdout
%6 = call i64 @fflush(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @_exit(i32 255)
unreachable
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i64 @fflush(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @_exit(i32 255)
unreachable
18: ; preds = %11
%19 = load i32, i32* @STDIN_FILENO
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* @STDOUT_FILENO
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* @STDERR_FILENO
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %3
%26 = call i32 @_exit(i32 %25)
unreachable
}

LLVM IR (-O2):
%struct.popen_noshell_clone_arg = type { i32 }
@stdout = global i32 0
@.str = [15 x i8] c"fflush(stdout)\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"fflush(stderr)\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define void @_popen_noshell_child_process_cleanup_fail_and_exit(i32 %0, %struct.popen_noshell_clone_arg* nocapture readnone %1) {
%3 = load i32, i32* @stdout
%4 = tail call i64 @fflush(i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @_exit(i32 255)
unreachable
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i64 @fflush(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = tail call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @_exit(i32 255)
unreachable
16: ; preds = %9
%17 = load i32, i32* @STDIN_FILENO
%18 = tail call i32 @close(i32 %17)
%19 = load i32, i32* @STDOUT_FILENO
%20 = tail call i32 @close(i32 %19)
%21 = load i32, i32* @STDERR_FILENO
%22 = tail call i32 @close(i32 %21)
%23 = tail call i32 @_exit(i32 %0)
unreachable
}