#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 STDIN_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ S_IFCHR;
int /*<<< orphan*/ errno;
int _fstat(int file, struct stat *st) {
  if ((STDIN_FILENO == file) || (STDERR_FILENO == file) ||
      (STDOUT_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    0x2ea6(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
je     1141 <_fstat+0x41>
mov    0x2ea4(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
je     1141 <_fstat+0x41>
mov    0x2eba(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    115c <_fstat+0x5c>
mov    0x2e90(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1175 <_fstat+0x75>
mov    0x2e5d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e64(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_fstat>:
mov    0x2eb1(%rip),%rax
cmp    %edi,(%rax)
je     1139 <_fstat+0x39>
mov    0x2eb6(%rip),%rax
cmp    %edi,(%rax)
je     1139 <_fstat+0x39>
mov    0x2ed3(%rip),%rax
cmp    %edi,(%rax)
je     1139 <_fstat+0x39>
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
mov    0x2e9f(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsi)
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@STDIN_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@STDOUT_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* @STDIN_FILENO
%7 = load i32, i32* %4
%8 = icmp eq i32 %6, %7
br i1 %8, label %17, 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 %17, label %13
13: ; preds = %9
%14 = load i32, i32* @STDOUT_FILENO
%15 = load i32, i32* %4
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %13, %9, %2
%18 = load i32, i32* @S_IFCHR
%19 = load %struct.stat*, %struct.stat** %5
%20 = getelementptr inbounds %struct.stat, %struct.stat* %19, i32 0, i32 0
store i32 %18, i32* %20
store i32 0, i32* %3
br label %23
21: ; preds = %13
%22 = load i32, i32* @EBADF
store i32 %22, i32* @errno
store i32 -1, i32* %3
br label %23
23: ; preds = %21, %17
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@STDIN_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@STDOUT_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* @STDIN_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
%8 = load i32, i32* @STDOUT_FILENO
%9 = icmp eq i32 %8, %0
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @S_IFCHR
%13 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
store i32 %12, i32* %13
br label %16
14: ; preds = %2
%15 = load i32, i32* @EBADF
store i32 %15, i32* @errno
br label %16
16: ; preds = %14, %11
%17 = phi i32 [ 0, %11 ], [ -1, %14 ]
ret i32 %17
}