#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 */
scalar_t__ EOF;
int /*<<< orphan*/ _IOFBF;
int /*<<< orphan*/ _IOLBF;
int /*<<< orphan*/ _IONBF;
int __fbufsize(int /*<<< orphan*/ *);
scalar_t__ __flbf(int /*<<< orphan*/ *);
int /*<<< orphan*/ __fpending(int /*<<< orphan*/ *);
int /*<<< orphan*/ __fpurge(int /*<<< orphan*/ *);
scalar_t__ __freadable(int /*<<< orphan*/ *);
scalar_t__ __freading(int /*<<< orphan*/ *);
scalar_t__ __fwritable(int /*<<< orphan*/ *);
scalar_t__ __fwriting(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
scalar_t__ setvbuf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/, int);
scalar_t__ strcmp(char *, char const *);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ *tmpfile();
int main(void) {
  FILE *fp;
  const char teststring[] = "hello world";
  char buf[3072];
  int result = 0;
  char readbuf[256];
  fp = tmpfile();
  if (setvbuf(fp, buf, _IOFBF, sizeof buf) == EOF) {
    printf("setvbuf failed: %m\n");
    exit(1);
  }
  if (__fbufsize(fp) != sizeof buf) {
    printf("__fbusize() reported a buffer size of %Zd bytes;"
           " we installed a buffer with %Zd bytes\n",
           __fbufsize(fp), sizeof buf);
    result = 1;
  }
  if (fputs(teststring, fp) == EOF) {
    printf("writing to new stream failed: %m\n");
    exit(1);
  }
  rewind(fp);
  if (fgets(readbuf, sizeof readbuf, fp) == NULL) {
    printf("reading from new stream failed: %m\n");
    exit(1);
  }
  if (strcmp(readbuf, teststring) != 0) {
    puts("not the correct string read");
    exit(1);
  }
  if (__freading(fp) == 0) {
    puts("__freading() reported stream is not last read from");
    result = 1;
  }
  if (__fwriting(fp) != 0) {
    puts("__fwriting() reported stream is write-only or last written to");
    result = 1;
  }
  rewind(fp);
  if (fputs(teststring, fp) == EOF) {
    printf("writing(2) to new stream failed: %m\n");
    exit(1);
  }
  if (__fwriting(fp) == 0) {
    puts("__fwriting() doe snot reported stream is last written to");
    result = 1;
  }
  if (__freading(fp) != 0) {
    puts("__freading() reported stream is last read from");
    result = 1;
  }
  if (__freadable(fp) == 0) {
    puts("__freading() reported stream is last readable");
    result = 1;
  }
  if (__fwritable(fp) == 0) {
    puts("__freading() reported stream is last writable");
    result = 1;
  }
  if (__fpending(fp) != strlen(teststring)) {
    printf("__fpending() returned %Zd; expected %Zd\n", __fpending(fp),
           strlen(teststring));
    result = 1;
  }
  __fpurge(fp);
  if (__fpending(fp) != 0) {
    printf("__fpending() returned %Zd; expected 0\n", __fpending(fp));
    result = 1;
  }
  if (__flbf(fp) != 0) {
    puts("__flbf() reports line buffered but it is fully buffered");
    result = 1;
  }
  if (setvbuf(fp, buf, _IOLBF, sizeof buf) == EOF) {
    printf("setvbuf(2) failed: %m\n");
    exit(1);
  }
  if (__flbf(fp) == 0) {
    puts("__flbf() reports file is not line buffered");
    result = 1;
  }
  if (setvbuf(fp, NULL, _IONBF, 0) == EOF) {
    printf("setvbuf(3) failed: %m\n");
    exit(1);
  }
  if (__flbf(fp) != 0) {
    puts("__flbf() reports line buffered but it is not buffered");
    result = 1;
  }
  fclose(fp);
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xdb7(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    0xdb5(%rip),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0xc24(%rbp)
mov    $0x0,%al
call   10e0 <tmpfile@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0xc20(%rbp),%rsi
mov    0x2d4b(%rip),%rax
mov    (%rax),%edx
mov    $0xc00,%ecx
call   1120 <setvbuf@plt>
mov    0x2d58(%rip),%rcx
cmp    (%rcx),%rax
jne    12b1 <main+0x81>
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1140 <__fbufsize@plt>
cltq
cmp    $0xc00,%rax
je     12f0 <main+0xc0>
mov    -0x10(%rbp),%rdi
call   1140 <__fbufsize@plt>
mov    %eax,%esi
lea    0xd46(%rip),%rdi
mov    $0xc00,%edx
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0xc24(%rbp)
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <fputs@plt>
mov    0x2ce4(%rip),%rcx
cmp    (%rcx),%rax
jne    1325 <main+0xf5>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1090 <rewind@plt>
lea    -0xd30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   10d0 <fgets@plt>
cmp    $0x0,%rax
jne    1365 <main+0x135>
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    -0xd30(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   10f0 <strcmp@plt>
cmp    $0x0,%rax
je     1395 <main+0x165>
lea    0xd37(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1100 <__freading@plt>
cmp    $0x0,%rax
jne    13be <main+0x18e>
lea    0xd2a(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0xc24(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <__fwriting@plt>
cmp    $0x0,%rax
je     13e7 <main+0x1b7>
lea    0xd34(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0xc24(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <rewind@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <fputs@plt>
mov    0x2be4(%rip),%rcx
cmp    (%rcx),%rax
jne    1425 <main+0x1f5>
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <__fwriting@plt>
cmp    $0x0,%rax
jne    144e <main+0x21e>
lea    0xd30(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0xc24(%rbp)
mov    -0x10(%rbp),%rdi
call   1100 <__freading@plt>
cmp    $0x0,%rax
je     1477 <main+0x247>
lea    0xd40(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0xc24(%rbp)
mov    -0x10(%rbp),%rdi
call   1150 <__freadable@plt>
cmp    $0x0,%rax
jne    14a0 <main+0x270>
lea    0xd46(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0xc24(%rbp)
mov    -0x10(%rbp),%rdi
call   1110 <__fwritable@plt>
cmp    $0x0,%rax
jne    14c9 <main+0x299>
lea    0xd4b(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0xc24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <__fpending@plt>
mov    %eax,-0xd34(%rbp)
lea    -0x1c(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0xd34(%rbp),%eax
cmp    %ecx,%eax
je     1529 <main+0x2f9>
mov    -0x10(%rbp),%rdi
call   1030 <__fpending@plt>
mov    %eax,-0xd38(%rbp)
lea    -0x1c(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xd38(%rbp),%esi
mov    %eax,%edx
lea    0xd1b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0xc24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <__fpurge@plt>
mov    -0x10(%rbp),%rdi
call   1030 <__fpending@plt>
cmp    $0x0,%eax
je     1567 <main+0x337>
mov    -0x10(%rbp),%rdi
call   1030 <__fpending@plt>
mov    %eax,%esi
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0xc24(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <__flbf@plt>
cmp    $0x0,%rax
je     1590 <main+0x360>
lea    0xd02(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0xc24(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0xc20(%rbp),%rsi
mov    0x2a2e(%rip),%rax
mov    (%rax),%edx
mov    $0xc00,%ecx
call   1120 <setvbuf@plt>
mov    0x2a33(%rip),%rcx
cmp    (%rcx),%rax
jne    15d6 <main+0x3a6>
lea    0xcf6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x10(%rbp),%rdi
call   10c0 <__flbf@plt>
cmp    $0x0,%rax
jne    15ff <main+0x3cf>
lea    0xce2(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0xc24(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x29d6(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1120 <setvbuf@plt>
mov    0x29ca(%rip),%rcx
cmp    (%rcx),%rax
jne    163f <main+0x40f>
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x10(%rbp),%rdi
call   10c0 <__flbf@plt>
cmp    $0x0,%rax
je     1668 <main+0x438>
lea    0xcbb(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0xc24(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0xc24(%rbp),%eax
add    $0xd40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xd18,%rsp
movabs $0x6f77206f6c6c6568,%rax
20 77 6f
mov    %rax,(%rsp)
movl   $0x646c72,0x8(%rsp)
xor    %r14d,%r14d
xor    %eax,%eax
call   10e0 <tmpfile@plt>
mov    %rax,%rbx
mov    0x2d61(%rip),%rax
mov    (%rax),%edx
lea    0x110(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xc00,%ecx
call   1120 <setvbuf@plt>
mov    0x2d63(%rip),%r15
cmp    (%r15),%rax
je     150c <main+0x2dc>
mov    %rbx,%rdi
call   1140 <__fbufsize@plt>
cmp    $0xc00,%eax
je     12c0 <main+0x90>
mov    %rbx,%rdi
call   1140 <__fbufsize@plt>
lea    0xd74(%rip),%rdi
mov    $0xc00,%edx
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%r14d
mov    %rsp,%rdi
mov    %rbx,%rsi
call   10a0 <fputs@plt>
cmp    (%r15),%rax
je     1515 <main+0x2e5>
mov    %rbx,%rdi
call   1090 <rewind@plt>
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   10d0 <fgets@plt>
test   %rax,%rax
je     151e <main+0x2ee>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   10f0 <strcmp@plt>
test   %rax,%rax
jne    1527 <main+0x2f7>
mov    %rbx,%rdi
call   1100 <__freading@plt>
test   %rax,%rax
jne    132c <main+0xfc>
lea    0xdb8(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   10b0 <__fwriting@plt>
test   %rax,%rax
je     134b <main+0x11b>
lea    0xdcc(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1090 <rewind@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   10a0 <fputs@plt>
cmp    (%r15),%rax
je     153d <main+0x30d>
mov    %rbx,%rdi
call   10b0 <__fwriting@plt>
test   %rax,%rax
jne    1386 <main+0x156>
lea    0xdf4(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1100 <__freading@plt>
test   %rax,%rax
je     13a5 <main+0x175>
lea    0xe0e(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1150 <__freadable@plt>
test   %rax,%rax
jne    13c4 <main+0x194>
lea    0xe1e(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1110 <__fwritable@plt>
test   %rax,%rax
jne    13e3 <main+0x1b3>
lea    0xe2d(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1030 <__fpending@plt>
mov    %eax,%ebp
mov    %rsp,%rdi
call   1070 <strlen@plt>
cmp    %eax,%ebp
je     1423 <main+0x1f3>
mov    %rbx,%rdi
call   1030 <__fpending@plt>
mov    %eax,%ebp
mov    %rsp,%rdi
call   1070 <strlen@plt>
lea    0xe21(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1050 <__fpurge@plt>
mov    %rbx,%rdi
call   1030 <__fpending@plt>
test   %eax,%eax
je     1455 <main+0x225>
mov    %rbx,%rdi
call   1030 <__fpending@plt>
lea    0xe16(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   10c0 <__flbf@plt>
test   %rax,%rax
je     1474 <main+0x244>
lea    0xe1a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
mov    0x2b55(%rip),%rax
mov    (%rax),%edx
lea    0x110(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xc00,%ecx
call   1120 <setvbuf@plt>
cmp    (%r15),%rax
je     1546 <main+0x316>
mov    %rbx,%rdi
call   10c0 <__flbf@plt>
test   %rax,%rax
jne    14ba <main+0x28a>
lea    0xe23(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
mov    0x2b1f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %ecx,%ecx
call   1120 <setvbuf@plt>
cmp    (%r15),%rax
je     154f <main+0x31f>
mov    %rbx,%rdi
call   10c0 <__flbf@plt>
test   %rax,%rax
je     14f3 <main+0x2c3>
lea    0xe2c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14d,%eax
add    $0xd18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xaf9(%rip),%rdi
jmp    1556 <main+0x326>
lea    0xb5b(%rip),%rdi
jmp    1556 <main+0x326>
lea    0xb74(%rip),%rdi
jmp    1556 <main+0x326>
lea    0xb8f(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0xc06(%rip),%rdi
jmp    1556 <main+0x326>
lea    0xd6e(%rip),%rdi
jmp    1556 <main+0x326>
lea    0xda7(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
@__const.main.teststring = [12 x i8] c"hello world\00"
@_IOFBF = global i32 0
@EOF = global i64 0
@.str = [20 x i8] c"setvbuf failed: %m\0A\00"
@.str.1 = [87 x i8] c"__fbusize() reported a buffer size of %Zd bytes; we installed a buffer with %Zd bytes\0A\00"
@.str.2 = [34 x i8] c"writing to new stream failed: %m\0A\00"
@.str.3 = [36 x i8] c"reading from new stream failed: %m\0A\00"
@.str.4 = [28 x i8] c"not the correct string read\00"
@.str.5 = [51 x i8] c"__freading() reported stream is not last read from\00"
@.str.6 = [62 x i8] c"__fwriting() reported stream is write-only or last written to\00"
@.str.7 = [37 x i8] c"writing(2) to new stream failed: %m\0A\00"
@.str.8 = [57 x i8] c"__fwriting() doe snot reported stream is last written to\00"
@.str.9 = [47 x i8] c"__freading() reported stream is last read from\00"
@.str.10 = [46 x i8] c"__freading() reported stream is last readable\00"
@.str.11 = [46 x i8] c"__freading() reported stream is last writable\00"
@.str.12 = [41 x i8] c"__fpending() returned %Zd; expected %Zd\0A\00"
@.str.13 = [39 x i8] c"__fpending() returned %Zd; expected 0\0A\00"
@.str.14 = [56 x i8] c"__flbf() reports line buffered but it is fully buffered\00"
@_IOLBF = global i32 0
@.str.15 = [23 x i8] c"setvbuf(2) failed: %m\0A\00"
@.str.16 = [43 x i8] c"__flbf() reports file is not line buffered\00"
@_IONBF = global i32 0
@.str.17 = [23 x i8] c"setvbuf(3) failed: %m\0A\00"
@.str.18 = [54 x i8] c"__flbf() reports line buffered but it is not buffered\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [12 x i8]
%4 = alloca [3072 x i8]
%5 = alloca i32
%6 = alloca [256 x i8]
store i32 0, i32* %1
%7 = bitcast [12 x i8]* %3 to i8*
store i32 0, i32* %5
%8 = call i32* (...) @tmpfile()
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = getelementptr inbounds [3072 x i8], [3072 x i8]* %4, i64 0, i64 0
%11 = load i32, i32* @_IOFBF
%12 = call i64 @setvbuf(i32* %9, i8* %10, i32 %11, i32 3072)
%13 = load i64, i64* @EOF
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = load i32*, i32** %2
%20 = call i32 @__fbufsize(i32* %19)
%21 = sext i32 %20 to i64
%22 = icmp ne i64 %21, 3072
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32*, i32** %2
%25 = call i32 @__fbufsize(i32* %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.1, i64 0, i64 0), i32 %25, i64 3072)
store i32 1, i32* %5
br label %27
27: ; preds = %23, %18
%28 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%29 = load i32*, i32** %2
%30 = call i64 @fputs(i8* %28, i32* %29)
%31 = load i64, i64* @EOF
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %27
%37 = load i32*, i32** %2
%38 = call i32 @rewind(i32* %37)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%40 = load i32*, i32** %2
%41 = call i32* @fgets(i8* %39, i32 256, i32* %40)
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %36
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %36
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%48 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%49 = call i64 @strcmp(i8* %47, i8* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %46
%55 = load i32*, i32** %2
%56 = call i64 @__freading(i32* %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 @puts(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %5
br label %60
60: ; preds = %58, %54
%61 = load i32*, i32** %2
%62 = call i64 @__fwriting(i32* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = call i32 @puts(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %5
br label %66
66: ; preds = %64, %60
%67 = load i32*, i32** %2
%68 = call i32 @rewind(i32* %67)
%69 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%70 = load i32*, i32** %2
%71 = call i64 @fputs(i8* %69, i32* %70)
%72 = load i64, i64* @EOF
%73 = icmp eq i64 %71, %72
br i1 %73, label %74, label %77
74: ; preds = %66
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %66
%78 = load i32*, i32** %2
%79 = call i64 @__fwriting(i32* %78)
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %77
%82 = call i32 @puts(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %5
br label %83
83: ; preds = %81, %77
%84 = load i32*, i32** %2
%85 = call i64 @__freading(i32* %84)
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %83
%88 = call i32 @puts(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %5
br label %89
89: ; preds = %87, %83
%90 = load i32*, i32** %2
%91 = call i64 @__freadable(i32* %90)
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %89
%94 = call i32 @puts(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %5
br label %95
95: ; preds = %93, %89
%96 = load i32*, i32** %2
%97 = call i64 @__fwritable(i32* %96)
%98 = icmp eq i64 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %95
%100 = call i32 @puts(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %5
br label %101
101: ; preds = %99, %95
%102 = load i32*, i32** %2
%103 = call i32 @__fpending(i32* %102)
%104 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%105 = call i32 @strlen(i8* %104)
%106 = icmp ne i32 %103, %105
br i1 %106, label %107, label %113
107: ; preds = %101
%108 = load i32*, i32** %2
%109 = call i32 @__fpending(i32* %108)
%110 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%111 = call i32 @strlen(i8* %110)
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.12, i64 0, i64 0), i32 %109, i32 %111)
store i32 1, i32* %5
br label %113
113: ; preds = %107, %101
%114 = load i32*, i32** %2
%115 = call i32 @__fpurge(i32* %114)
%116 = load i32*, i32** %2
%117 = call i32 @__fpending(i32* %116)
%118 = icmp ne i32 %117, 0
br i1 %118, label %119, label %123
119: ; preds = %113
%120 = load i32*, i32** %2
%121 = call i32 @__fpending(i32* %120)
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.13, i64 0, i64 0), i32 %121)
store i32 1, i32* %5
br label %123
123: ; preds = %119, %113
%124 = load i32*, i32** %2
%125 = call i64 @__flbf(i32* %124)
%126 = icmp ne i64 %125, 0
br i1 %126, label %127, label %129
127: ; preds = %123
%128 = call i32 @puts(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.14, i64 0, i64 0))
store i32 1, i32* %5
br label %129
129: ; preds = %127, %123
%130 = load i32*, i32** %2
%131 = getelementptr inbounds [3072 x i8], [3072 x i8]* %4, i64 0, i64 0
%132 = load i32, i32* @_IOLBF
%133 = call i64 @setvbuf(i32* %130, i8* %131, i32 %132, i32 3072)
%134 = load i64, i64* @EOF
%135 = icmp eq i64 %133, %134
br i1 %135, label %136, label %139
136: ; preds = %129
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.15, i64 0, i64 0))
%138 = call i32 @exit(i32 1)
unreachable
139: ; preds = %129
%140 = load i32*, i32** %2
%141 = call i64 @__flbf(i32* %140)
%142 = icmp eq i64 %141, 0
br i1 %142, label %143, label %145
143: ; preds = %139
%144 = call i32 @puts(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.16, i64 0, i64 0))
store i32 1, i32* %5
br label %145
145: ; preds = %143, %139
%146 = load i32*, i32** %2
%147 = load i32, i32* @_IONBF
%148 = call i64 @setvbuf(i32* %146, i8* null, i32 %147, i32 0)
%149 = load i64, i64* @EOF
%150 = icmp eq i64 %148, %149
br i1 %150, label %151, label %154
151: ; preds = %145
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.17, i64 0, i64 0))
%153 = call i32 @exit(i32 1)
unreachable
154: ; preds = %145
%155 = load i32*, i32** %2
%156 = call i64 @__flbf(i32* %155)
%157 = icmp ne i64 %156, 0
br i1 %157, label %158, label %160
158: ; preds = %154
%159 = call i32 @puts(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.18, i64 0, i64 0))
store i32 1, i32* %5
br label %160
160: ; preds = %158, %154
%161 = load i32*, i32** %2
%162 = call i32 @fclose(i32* %161)
%163 = load i32, i32* %5
ret i32 %163
}

LLVM IR (-O2):
@__const.main.teststring = [12 x i8] c"hello world\00"
@_IOFBF = global i32 0
@EOF = global i64 0
@.str = [20 x i8] c"setvbuf failed: %m\0A\00"
@.str.1 = [87 x i8] c"__fbusize() reported a buffer size of %Zd bytes; we installed a buffer with %Zd bytes\0A\00"
@.str.2 = [34 x i8] c"writing to new stream failed: %m\0A\00"
@.str.3 = [36 x i8] c"reading from new stream failed: %m\0A\00"
@.str.4 = [28 x i8] c"not the correct string read\00"
@.str.5 = [51 x i8] c"__freading() reported stream is not last read from\00"
@.str.6 = [62 x i8] c"__fwriting() reported stream is write-only or last written to\00"
@.str.7 = [37 x i8] c"writing(2) to new stream failed: %m\0A\00"
@.str.8 = [57 x i8] c"__fwriting() doe snot reported stream is last written to\00"
@.str.9 = [47 x i8] c"__freading() reported stream is last read from\00"
@.str.10 = [46 x i8] c"__freading() reported stream is last readable\00"
@.str.11 = [46 x i8] c"__freading() reported stream is last writable\00"
@.str.12 = [41 x i8] c"__fpending() returned %Zd; expected %Zd\0A\00"
@.str.13 = [39 x i8] c"__fpending() returned %Zd; expected 0\0A\00"
@.str.14 = [56 x i8] c"__flbf() reports line buffered but it is fully buffered\00"
@_IOLBF = global i32 0
@.str.15 = [23 x i8] c"setvbuf(2) failed: %m\0A\00"
@.str.16 = [43 x i8] c"__flbf() reports file is not line buffered\00"
@_IONBF = global i32 0
@.str.17 = [23 x i8] c"setvbuf(3) failed: %m\0A\00"
@.str.18 = [54 x i8] c"__flbf() reports line buffered but it is not buffered\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca [3072 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [3072 x i8], [3072 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = tail call i32* (...) @tmpfile()
%8 = load i32, i32* @_IOFBF
%9 = call i64 @setvbuf(i32* %7, i8* %5, i32 %8, i32 3072)
%10 = load i64, i64* @EOF
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i32 @__fbufsize(i32* %7)
%17 = icmp eq i32 %16, 3072
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = call i32 @__fbufsize(i32* %7)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @.str.1, i64 0, i64 0), i32 %19, i64 3072)
br label %21
21: ; preds = %18, %15
%22 = phi i32 [ 1, %18 ], [ 0, %15 ]
%23 = call i64 @fputs(i8* %4, i32* %7)
%24 = load i64, i64* @EOF
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = call i32 @rewind(i32* %7)
%31 = call i32* @fgets(i8* %6, i32 256, i32* %7)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %29
%37 = call i64 @strcmp(i8* %6, i8* %4)
%38 = icmp eq i64 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %36
%43 = call i64 @__freading(i32* %7)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
%48 = phi i32 [ 1, %45 ], [ %22, %42 ]
%49 = call i64 @__fwriting(i32* %7)
%50 = icmp eq i64 %49, 0
br i1 %50, label %53, label %51
51: ; preds = %47
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0))
br label %53
53: ; preds = %51, %47
%54 = phi i32 [ 1, %51 ], [ %48, %47 ]
%55 = call i32 @rewind(i32* %7)
%56 = call i64 @fputs(i8* %4, i32* %7)
%57 = load i64, i64* @EOF
%58 = icmp eq i64 %56, %57
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %53
%63 = call i64 @__fwriting(i32* %7)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.8, i64 0, i64 0))
br label %67
67: ; preds = %65, %62
%68 = phi i32 [ 1, %65 ], [ %54, %62 ]
%69 = call i64 @__freading(i32* %7)
%70 = icmp eq i64 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %67
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.9, i64 0, i64 0))
br label %73
73: ; preds = %71, %67
%74 = phi i32 [ 1, %71 ], [ %68, %67 ]
%75 = call i64 @__freadable(i32* %7)
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %73
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0))
br label %79
79: ; preds = %77, %73
%80 = phi i32 [ 1, %77 ], [ %74, %73 ]
%81 = call i64 @__fwritable(i32* %7)
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.11, i64 0, i64 0))
br label %85
85: ; preds = %83, %79
%86 = phi i32 [ 1, %83 ], [ %80, %79 ]
%87 = call i32 @__fpending(i32* %7)
%88 = call i32 @strlen(i8* %4)
%89 = icmp eq i32 %87, %88
br i1 %89, label %94, label %90
90: ; preds = %85
%91 = call i32 @__fpending(i32* %7)
%92 = call i32 @strlen(i8* %4)
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.12, i64 0, i64 0), i32 %91, i32 %92)
br label %94
94: ; preds = %90, %85
%95 = phi i32 [ 1, %90 ], [ %86, %85 ]
%96 = call i32 @__fpurge(i32* %7)
%97 = call i32 @__fpending(i32* %7)
%98 = icmp eq i32 %97, 0
br i1 %98, label %102, label %99
99: ; preds = %94
%100 = call i32 @__fpending(i32* %7)
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.13, i64 0, i64 0), i32 %100)
br label %102
102: ; preds = %99, %94
%103 = phi i32 [ 1, %99 ], [ %95, %94 ]
%104 = call i64 @__flbf(i32* %7)
%105 = icmp eq i64 %104, 0
br i1 %105, label %108, label %106
106: ; preds = %102
%107 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.14, i64 0, i64 0))
br label %108
108: ; preds = %106, %102
%109 = phi i32 [ 1, %106 ], [ %103, %102 ]
%110 = load i32, i32* @_IOLBF
%111 = call i64 @setvbuf(i32* %7, i8* %5, i32 %110, i32 3072)
%112 = load i64, i64* @EOF
%113 = icmp eq i64 %111, %112
br i1 %113, label %114, label %117
114: ; preds = %108
%115 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.15, i64 0, i64 0))
%116 = call i32 @exit(i32 1)
unreachable
117: ; preds = %108
%118 = call i64 @__flbf(i32* %7)
%119 = icmp eq i64 %118, 0
br i1 %119, label %120, label %122
120: ; preds = %117
%121 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.16, i64 0, i64 0))
br label %122
122: ; preds = %120, %117
%123 = phi i32 [ 1, %120 ], [ %109, %117 ]
%124 = load i32, i32* @_IONBF
%125 = call i64 @setvbuf(i32* %7, i8* null, i32 %124, i32 0)
%126 = load i64, i64* @EOF
%127 = icmp eq i64 %125, %126
br i1 %127, label %128, label %131
128: ; preds = %122
%129 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.17, i64 0, i64 0))
%130 = call i32 @exit(i32 1)
unreachable
131: ; preds = %122
%132 = call i64 @__flbf(i32* %7)
%133 = icmp eq i64 %132, 0
br i1 %133, label %136, label %134
134: ; preds = %131
%135 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.18, i64 0, i64 0))
br label %136
136: ; preds = %134, %131
%137 = phi i32 [ 1, %134 ], [ %123, %131 ]
%138 = call i32 @fclose(i32* %7)
ret i32 %137
}