#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*/ _IOLBF;
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/,
                   int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
char *strerror(scalar_t__);
__attribute__((constructor)) void linebuffer() {
  errno = 0;
  if (setvbuf(stdout, NULL, _IOLBF, 0)) {
    printf("setvbuf(stdout, NULL, _IOLBUF, 0) failed\n");
    printf("%s\n", strerror(errno));
  } else {
    printf("stdio set to line buffer mode.\n");
  }
}


x86 assembly (clang, -O0):
<linebuffer>:
push   %rbp
mov    %rsp,%rbp
mov    0x2ea5(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
mov    0x2e86(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1040 <setvbuf@plt>
cmp    $0x0,%rax
je     119c <linebuffer+0x6c>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11aa <linebuffer+0x7a>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<linebuffer>:
push   %rbx
mov    0x2ea8(%rip),%rbx
movq   $0x0,(%rbx)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1040 <setvbuf@plt>
test   %rax,%rax
je     117c <linebuffer+0x4c>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
call   1050 <strerror@plt>
mov    %rax,%rdi
pop    %rbx
jmp    1030 <puts@plt>
lea    0xe7d(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@errno = global i64 0
@stdout = global i32 0
@_IOLBF = global i32 0
@.str = [42 x i8] c"setvbuf(stdout, NULL, _IOLBUF, 0) failed\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [32 x i8] c"stdio set to line buffer mode.\0A\00"
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @linebuffer, i8* null }]
define void @linebuffer() {
store i64 0, i64* @errno
%1 = load i32, i32* @stdout
%2 = load i32, i32* @_IOLBF
%3 = call i64 @setvbuf(i32 %1, i32* null, i32 %2, i32 0)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%7 = load i64, i64* @errno
%8 = call i8* @strerror(i64 %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %5
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@stdout = global i32 0
@_IOLBF = global i32 0
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @linebuffer, i8* null }]
@str = [31 x i8] c"stdio set to line buffer mode.\00"
@str.3 = [41 x i8] c"setvbuf(stdout, NULL, _IOLBUF, 0) failed\00"
define void @linebuffer() {
store i64 0, i64* @errno
%1 = load i32, i32* @stdout
%2 = load i32, i32* @_IOLBF
%3 = tail call i64 @setvbuf(i32 %1, i32* null, i32 %2, i32 0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.3, i64 0, i64 0))
%7 = load i64, i64* @errno
%8 = tail call i8* @strerror(i64 %7)
br label %9
9: ; preds = %0, %5
%10 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0), %0 ]
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
ret void
}