#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EBADF;
int EOF;
int /*<<< orphan*/ errno;
int puts(char const *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int fputs(const char *s, FILE *stream) {
  if ((stream == stdin) || (stream == stdout) || (stream == stderr)) {
    return puts(s);
  } else {
    errno = EBADF;
    return EOF;
  }
}


x86 assembly (clang, -O0):
<fputs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2ebd(%rip),%rcx
cmp    (%rcx),%rax
je     115c <fputs+0x4c>
mov    -0x18(%rbp),%rax
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%rax
je     115c <fputs+0x4c>
mov    -0x18(%rbp),%rax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rax
jne    116d <fputs+0x5d>
mov    -0x10(%rbp),%rdi
call   1030 <puts@plt>
mov    %eax,-0x4(%rbp)
jmp    118b <fputs+0x7b>
mov    0x2e44(%rip),%rax
mov    (%rax),%ecx
mov    0x2e4b(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputs>:
mov    0x2ed1(%rip),%rax
cmp    %rsi,(%rax)
je     1150 <fputs+0x40>
mov    0x2e9d(%rip),%rax
cmp    %rsi,(%rax)
je     1150 <fputs+0x40>
mov    0x2ea1(%rip),%rax
cmp    %rsi,(%rax)
je     1150 <fputs+0x40>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    0x2e84(%rip),%rcx
mov    %eax,(%rcx)
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
ret
jmp    1030 <puts@plt>

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32* null
@stderr = global i32* null
@EBADF = global i32 0
@errno = global i32 0
@EOF = global i32 0
define i32 @fputs(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%6 = load i32*, i32** %5
%7 = load i32*, i32** @stdin
%8 = icmp eq i32* %6, %7
br i1 %8, label %17, label %9
9: ; preds = %2
%10 = load i32*, i32** %5
%11 = load i32*, i32** @stdout
%12 = icmp eq i32* %10, %11
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load i32*, i32** %5
%15 = load i32*, i32** @stderr
%16 = icmp eq i32* %14, %15
br i1 %16, label %17, label %20
17: ; preds = %13, %9, %2
%18 = load i8*, i8** %4
%19 = call i32 @puts(i8* %18)
store i32 %19, i32* %3
br label %23
20: ; preds = %13
%21 = load i32, i32* @EBADF
store i32 %21, i32* @errno
%22 = load i32, i32* @EOF
store i32 %22, i32* %3
br label %23
23: ; preds = %20, %17
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32* null
@stderr = global i32* null
@EBADF = global i32 0
@errno = global i32 0
@EOF = global i32 0
define i32 @fputs(i8* nocapture %0, i32* nocapture readnone %1) {
%3 = load i32*, i32** @stdin
%4 = icmp eq i32* %3, %1
%5 = load i32*, i32** @stdout
%6 = icmp eq i32* %5, %1
%7 = select i1 %4, i1 true, i1 %6
%8 = load i32*, i32** @stderr
%9 = icmp eq i32* %8, %1
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) %0)
br label %16
13: ; preds = %2
%14 = load i32, i32* @EBADF
store i32 %14, i32* @errno
%15 = load i32, i32* @EOF
br label %16
16: ; preds = %13, %11
%17 = phi i32 [ %12, %11 ], [ %15, %13 ]
ret i32 %17
}