#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 */

/* Variables and functions */
int /*<<< orphan*/ change_buf(int /*<<< orphan*/, char *);
char *getenv(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
__attribute__((constructor)) void stdbuf(void) {
  char *i_mode, *o_mode, *e_mode;
  i_mode = getenv("_STDBUF_I");
  o_mode = getenv("_STDBUF_O");
  e_mode = getenv("_STDBUF_E");
  if (e_mode != NULL)
    change_buf(stderr, e_mode);
  if (i_mode != NULL)
    change_buf(stdin, i_mode);
  if (o_mode != NULL)
    change_buf(stdout, o_mode);
}


x86 assembly (clang, -O0):
<stdbuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
lea    0xecb(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
lea    0xec5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1175 <stdbuf+0x55>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1040 <change_buf@plt>
cmpq   $0x0,-0x8(%rbp)
je     1192 <stdbuf+0x72>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1040 <change_buf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11af <stdbuf+0x8f>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1040 <change_buf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdbuf>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xed0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
lea    0xecb(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1164 <stdbuf+0x44>
mov    0x2e7e(%rip),%rcx
mov    (%rcx),%edi
mov    %rax,%rsi
call   1040 <change_buf@plt>
test   %rbx,%rbx
je     117a <stdbuf+0x5a>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1040 <change_buf@plt>
test   %r14,%r14
je     1197 <stdbuf+0x77>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <change_buf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"_STDBUF_I\00"
@.str.1 = [10 x i8] c"_STDBUF_O\00"
@.str.2 = [10 x i8] c"_STDBUF_E\00"
@stderr = global i32 0
@stdin = global i32 0
@stdout = global i32 0
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @stdbuf, i8* null }]
define void @stdbuf() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %1
%5 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i8* %5, i8** %2
%6 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %3
%12 = call i32 @change_buf(i32 %10, i8* %11)
br label %13
13: ; preds = %9, %0
%14 = load i8*, i8** %1
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* @stdin
%18 = load i8*, i8** %1
%19 = call i32 @change_buf(i32 %17, i8* %18)
br label %20
20: ; preds = %16, %13
%21 = load i8*, i8** %2
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* @stdout
%25 = load i8*, i8** %2
%26 = call i32 @change_buf(i32 %24, i8* %25)
br label %27
27: ; preds = %23, %20
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"_STDBUF_I\00"
@.str.1 = [10 x i8] c"_STDBUF_O\00"
@.str.2 = [10 x i8] c"_STDBUF_E\00"
@stderr = global i32 0
@stdin = global i32 0
@stdout = global i32 0
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @stdbuf, i8* null }]
define void @stdbuf() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @change_buf(i32 %6, i8* %3)
br label %8
8: ; preds = %5, %0
%9 = icmp eq i8* %1, null
br i1 %9, label %13, label %10
10: ; preds = %8
%11 = load i32, i32* @stdin
%12 = tail call i32 @change_buf(i32 %11, i8* %1)
br label %13
13: ; preds = %10, %8
%14 = icmp eq i8* %2, null
br i1 %14, label %18, label %15
15: ; preds = %13
%16 = load i32, i32* @stdout
%17 = tail call i32 @change_buf(i32 %16, i8* %2)
br label %18
18: ; preds = %15, %13
ret void
}