#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*/ EBADF;
int STDERR_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ S_IFCHR;
int /*<<< orphan*/ errno;
int _fstat(int file, struct stat *st) {
  if ((STDOUT_FILENO == file) || (STDERR_FILENO == file)) {
    st->st_mode = S_IFCHR;
    return 0;
  } else {
    errno = EBADF;
    return -1;
  }
}


x86 assembly (clang, -O0):
<_fstat>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ede(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
je     112f <_fstat+0x2f>
mov    0x2ea4(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    114a <_fstat+0x4a>
mov    0x2ea2(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1163 <_fstat+0x63>
mov    0x2e6f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e76(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_fstat>:
mov    0x2ee9(%rip),%rax
cmp    %edi,(%rax)
je     112e <_fstat+0x2e>
mov    0x2eb6(%rip),%rax
cmp    %edi,(%rax)
je     112e <_fstat+0x2e>
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    0x2eaa(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsi)
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@S_IFCHR = global i32 0
@EBADF = global i32 0
@errno = global i32 0
define i32 @_fstat(i32 %0, %struct.stat* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat*
store i32 %0, i32* %4
store %struct.stat* %1, %struct.stat** %5
%6 = load i32, i32* @STDOUT_FILENO
%7 = load i32, i32* %4
%8 = icmp eq i32 %6, %7
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @STDERR_FILENO
%11 = load i32, i32* %4
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %9, %2
%14 = load i32, i32* @S_IFCHR
%15 = load %struct.stat*, %struct.stat** %5
%16 = getelementptr inbounds %struct.stat, %struct.stat* %15, i32 0, i32 0
store i32 %14, i32* %16
store i32 0, i32* %3
br label %19
17: ; preds = %9
%18 = load i32, i32* @EBADF
store i32 %18, i32* @errno
store i32 -1, i32* %3
br label %19
19: ; preds = %17, %13
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@S_IFCHR = global i32 0
@EBADF = global i32 0
@errno = global i32 0
define i32 @_fstat(i32 %0, %struct.stat* nocapture writeonly %1) {
%3 = load i32, i32* @STDOUT_FILENO
%4 = icmp eq i32 %3, %0
%5 = load i32, i32* @STDERR_FILENO
%6 = icmp eq i32 %5, %0
%7 = select i1 %4, i1 true, i1 %6
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @S_IFCHR
%10 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
store i32 %9, i32* %10
br label %13
11: ; preds = %2
%12 = load i32, i32* @EBADF
store i32 %12, i32* @errno
br label %13
13: ; preds = %11, %8
%14 = phi i32 [ 0, %8 ], [ -1, %11 ]
ret i32 %14
}