#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 stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int fcntl_dupfd(int /*<<< orphan*/, int);
int fstat(int /*<<< orphan*/, struct stat *);
int /*<<< orphan*/ store_pageinfo(int);
void handle_stdout(void) {
  int fd;
  struct stat st;
  if (fstat(STDOUT_FILENO, &st) == -1 || !S_ISREG(st.st_mode))
    return;
  fd = fcntl_dupfd(STDOUT_FILENO, 23);
  if (fd == -1)
    return;
  store_pageinfo(fd);
}


x86 assembly (clang, -O0):
<handle_stdout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1060 <fstat@plt>
cmp    $0xffffffff,%eax
je     1174 <handle_stdout+0x34>
mov    -0x8(%rbp),%edi
call   1040 <S_ISREG@plt>
cmp    $0x0,%eax
jne    1179 <handle_stdout+0x39>
jmp    11a6 <handle_stdout+0x66>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    $0x17,%esi
call   1030 <fcntl_dupfd@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    119e <handle_stdout+0x5e>
jmp    11a6 <handle_stdout+0x66>
mov    -0x4(%rbp),%edi
call   1050 <store_pageinfo@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_stdout>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ea4(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1060 <fstat@plt>
cmp    $0xffffffff,%eax
je     1187 <handle_stdout+0x47>
mov    0x8(%rsp),%edi
call   1040 <S_ISREG@plt>
test   %eax,%eax
je     1187 <handle_stdout+0x47>
mov    (%rbx),%edi
mov    $0x17,%esi
call   1030 <fcntl_dupfd@plt>
cmp    $0xffffffff,%eax
je     1187 <handle_stdout+0x47>
mov    %eax,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1050 <store_pageinfo@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@STDOUT_FILENO = global i32 0
define void @handle_stdout() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = load i32, i32* @STDOUT_FILENO
%4 = call i32 @fstat(i32 %3, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %11, label %6
6: ; preds = %0
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%8 = load i32, i32* %7
%9 = call i32 @S_ISREG(i32 %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %6, %0
br label %21
12: ; preds = %6
%13 = load i32, i32* @STDOUT_FILENO
%14 = call i32 @fcntl_dupfd(i32 %13, i32 23)
store i32 %14, i32* %1
%15 = load i32, i32* %1
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %12
br label %21
18: ; preds = %12
%19 = load i32, i32* %1
%20 = call i32 @store_pageinfo(i32 %19)
br label %21
21: ; preds = %18, %17, %11
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@STDOUT_FILENO = global i32 0
define void @handle_stdout() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = load i32, i32* @STDOUT_FILENO
%4 = call i32 @fstat(i32 %3, %struct.stat* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %17, label %6
6: ; preds = %0
%7 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i32 @S_ISREG(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %6
%12 = load i32, i32* @STDOUT_FILENO
%13 = tail call i32 @fcntl_dupfd(i32 %12, i32 23)
%14 = icmp eq i32 %13, -1
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @store_pageinfo(i32 %13)
br label %17
17: ; preds = %11, %0, %6, %15
ret void
}