#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 */
char EOF;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ clearerr(int /*<<< orphan*/ *);
int /*<<< orphan*/ fail(char *);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ fflush(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fputc(int, int /*<<< orphan*/ *);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ pr(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
char ungetc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(char *);
void test_sio2(void) {
  FILE *f;
  int i;
  pr("fileno");
  if (fileno(stdin) != 0)
    fail("fileno-1");
  if (fileno(stdout) != 1)
    fail("fileno-2");
  if (fileno(stderr) != 2)
    fail("fileno-3");
  if ((f = fopen("stdio.tmp", "w+")) == NULL) {
    fail("fopen-4");
    return;
  }
  pr("fputc");
  for (i = 'A'; i <= 'Z'; i++)
    if (fputc(i, f) != i)
      fail("fputc-1");
  pr("fflush");
  if (fflush(f) < 0)
    fail("fflush-1");
  if (lseek(fileno(f), 0, SEEK_END) != 26)
    fail("fflush-2");
  pr("rewind");
  rewind(f);
  if (lseek(fileno(f), 0, SEEK_CUR) != 0)
    fail("rewind-1");
  pr("fgets");
  for (i = 'A'; i <= 'Z'; i++) {
    if (fgetc(f) != i) {
      fail("fgetc-1");
      break;
    }
  }
  if (fgetc(f) != EOF)
    fail("fgetc-2");
  pr("ungetc");
  clearerr(f);
  rewind(f);
  if (fgetc(f) != 'A')
    fail("ungetc-0");
  if (ungetc('X', f) != 'X')
    fail("ungetc-1");
  if (fgetc(f) != 'X')
    fail("ungetc-2");
  if (fgetc(f) != 'B')
    fail("ungetc-3");
  if (ungetc('X', f) != 'X')
    fail("ungetc-4");
  if (fgetc(f) != 'X')
    fail("ungetc-5");
  if (fclose(f))
    fail("fclose-5");
  unlink("stdio.tmp");
}


x86 assembly (clang, -O0):
<test_sio2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe21(%rip),%rdi
call   1080 <pr@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%rdi
call   10c0 <fileno@plt>
cmp    $0x0,%eax
je     1208 <test_sio2+0x38>
lea    0xe04(%rip),%rdi
call   1040 <fail@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%rdi
call   10c0 <fileno@plt>
cmp    $0x1,%eax
je     122c <test_sio2+0x5c>
lea    0xde9(%rip),%rdi
call   1040 <fail@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%rdi
call   10c0 <fileno@plt>
cmp    $0x2,%eax
je     1250 <test_sio2+0x80>
lea    0xdce(%rip),%rdi
call   1040 <fail@plt>
lea    0xdcb(%rip),%rdi
lea    0xdce(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1282 <test_sio2+0xb2>
lea    0xdb7(%rip),%rdi
call   1040 <fail@plt>
jmp    150c <test_sio2+0x33c>
lea    0xdae(%rip),%rdi
call   1080 <pr@plt>
movl   $0x41,-0xc(%rbp)
cmpl   $0x5a,-0xc(%rbp)
jg     12d3 <test_sio2+0x103>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   10a0 <fputc@plt>
cmp    -0xc(%rbp),%eax
je     12c0 <test_sio2+0xf0>
lea    0xd82(%rip),%rdi
call   1040 <fail@plt>
jmp    12c5 <test_sio2+0xf5>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1295 <test_sio2+0xc5>
lea    0xd6b(%rip),%rdi
call   1080 <pr@plt>
mov    -0x8(%rbp),%rdi
call   10d0 <fflush@plt>
cmp    $0x0,%rax
jge    12fe <test_sio2+0x12e>
lea    0xd53(%rip),%rdi
call   1040 <fail@plt>
mov    -0x8(%rbp),%rdi
call   10c0 <fileno@plt>
mov    %eax,%edi
mov    0x2cd8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
cmp    $0x1a,%eax
je     132e <test_sio2+0x15e>
lea    0xd2c(%rip),%rdi
call   1040 <fail@plt>
lea    0xd29(%rip),%rdi
call   1080 <pr@plt>
mov    -0x8(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x8(%rbp),%rdi
call   10c0 <fileno@plt>
mov    %eax,%edi
mov    0x2c8b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
cmp    $0x0,%eax
je     1373 <test_sio2+0x1a3>
lea    0xcf7(%rip),%rdi
call   1040 <fail@plt>
lea    0xcf4(%rip),%rdi
call   1080 <pr@plt>
movl   $0x41,-0xc(%rbp)
cmpl   $0x5a,-0xc(%rbp)
jg     13c9 <test_sio2+0x1f9>
mov    -0x8(%rbp),%rdi
call   1090 <fgetc@plt>
movsbl %al,%eax
cmp    -0xc(%rbp),%eax
je     13b6 <test_sio2+0x1e6>
lea    0xcc8(%rip),%rdi
call   1040 <fail@plt>
jmp    13c9 <test_sio2+0x1f9>
jmp    13bb <test_sio2+0x1eb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1386 <test_sio2+0x1b6>
mov    -0x8(%rbp),%rdi
call   1090 <fgetc@plt>
movsbl %al,%eax
mov    0x2bf4(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     13f3 <test_sio2+0x223>
lea    0xc8e(%rip),%rdi
call   1040 <fail@plt>
lea    0xc8a(%rip),%rdi
call   1080 <pr@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <clearerr@plt>
mov    -0x8(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x8(%rbp),%rdi
call   1090 <fgetc@plt>
movsbl %al,%eax
cmp    $0x41,%eax
je     1432 <test_sio2+0x262>
lea    0xc5e(%rip),%rdi
call   1040 <fail@plt>
mov    -0x8(%rbp),%rsi
mov    $0x58,%edi
call   10e0 <ungetc@plt>
movsbl %al,%eax
cmp    $0x58,%eax
je     1458 <test_sio2+0x288>
lea    0xc41(%rip),%rdi
call   1040 <fail@plt>
mov    -0x8(%rbp),%rdi
call   1090 <fgetc@plt>
movsbl %al,%eax
cmp    $0x58,%eax
je     1479 <test_sio2+0x2a9>
lea    0xc29(%rip),%rdi
call   1040 <fail@plt>
mov    -0x8(%rbp),%rdi
call   1090 <fgetc@plt>
movsbl %al,%eax
cmp    $0x42,%eax
je     149a <test_sio2+0x2ca>
lea    0xc11(%rip),%rdi
call   1040 <fail@plt>
mov    -0x8(%rbp),%rsi
mov    $0x58,%edi
call   10e0 <ungetc@plt>
movsbl %al,%eax
cmp    $0x58,%eax
je     14c0 <test_sio2+0x2f0>
lea    0xbf4(%rip),%rdi
call   1040 <fail@plt>
mov    -0x8(%rbp),%rdi
call   1090 <fgetc@plt>
movsbl %al,%eax
cmp    $0x58,%eax
je     14e1 <test_sio2+0x311>
lea    0xbdc(%rip),%rdi
call   1040 <fail@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     1500 <test_sio2+0x330>
lea    0xbc6(%rip),%rdi
call   1040 <fail@plt>
lea    0xb1b(%rip),%rdi
call   1030 <unlink@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sio2>:
push   %rbp
push   %r14
push   %rbx
lea    0xe25(%rip),%rdi
call   1080 <pr@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%rdi
call   10c0 <fileno@plt>
test   %eax,%eax
je     11ff <test_sio2+0x2f>
lea    0xe0d(%rip),%rdi
call   1040 <fail@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%rdi
call   10c0 <fileno@plt>
cmp    $0x1,%eax
je     121f <test_sio2+0x4f>
lea    0xdf6(%rip),%rdi
call   1040 <fail@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%rdi
call   10c0 <fileno@plt>
cmp    $0x2,%eax
je     123f <test_sio2+0x6f>
lea    0xddf(%rip),%rdi
call   1040 <fail@plt>
lea    0xddc(%rip),%rdi
lea    0xddf(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     1359 <test_sio2+0x189>
mov    %rax,%rbx
lea    0xdd2(%rip),%rdi
call   1080 <pr@plt>
mov    $0x41,%ebp
lea    0xdc7(%rip),%r14
jmp    1288 <test_sio2+0xb8>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x5b,%ebp
je     12a0 <test_sio2+0xd0>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10a0 <fputc@plt>
cmp    %eax,%ebp
je     1280 <test_sio2+0xb0>
mov    %r14,%rdi
call   1040 <fail@plt>
jmp    1280 <test_sio2+0xb0>
lea    0xd9e(%rip),%rdi
call   1080 <pr@plt>
mov    %rbx,%rdi
call   10d0 <fflush@plt>
test   %rax,%rax
jns    12c5 <test_sio2+0xf5>
lea    0xd8c(%rip),%rdi
call   1040 <fail@plt>
mov    %rbx,%rdi
call   10c0 <fileno@plt>
mov    0x2d14(%rip),%rcx
mov    (%rcx),%edx
mov    %eax,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
cmp    $0x1a,%eax
je     12f0 <test_sio2+0x120>
lea    0xd6a(%rip),%rdi
call   1040 <fail@plt>
lea    0xd67(%rip),%rdi
call   1080 <pr@plt>
mov    %rbx,%rdi
call   1060 <rewind@plt>
mov    %rbx,%rdi
call   10c0 <fileno@plt>
mov    0x2ccd(%rip),%rcx
mov    (%rcx),%edx
mov    %eax,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
test   %eax,%eax
je     132e <test_sio2+0x15e>
lea    0xd3c(%rip),%rdi
call   1040 <fail@plt>
lea    0xd39(%rip),%rdi
call   1080 <pr@plt>
mov    $0x41,%ebp
nop
mov    %rbx,%rdi
call   1090 <fgetc@plt>
movsbl %al,%eax
cmp    %eax,%ebp
jne    1369 <test_sio2+0x199>
add    $0x1,%ebp
cmp    $0x5b,%ebp
jne    1340 <test_sio2+0x170>
jmp    1375 <test_sio2+0x1a5>
lea    0xccf(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fail@plt>
lea    0xd04(%rip),%rdi
call   1040 <fail@plt>
mov    %rbx,%rdi
call   1090 <fgetc@plt>
mov    0x2c4c(%rip),%rcx
cmp    (%rcx),%al
je     1394 <test_sio2+0x1c4>
lea    0xced(%rip),%rdi
call   1040 <fail@plt>
lea    0xce9(%rip),%rdi
call   1080 <pr@plt>
mov    %rbx,%rdi
call   10b0 <clearerr@plt>
mov    %rbx,%rdi
call   1060 <rewind@plt>
mov    %rbx,%rdi
call   1090 <fgetc@plt>
cmp    $0x41,%al
je     13c8 <test_sio2+0x1f8>
lea    0xcc8(%rip),%rdi
call   1040 <fail@plt>
mov    $0x58,%edi
mov    %rbx,%rsi
call   10e0 <ungetc@plt>
cmp    $0x58,%al
je     13e5 <test_sio2+0x215>
lea    0xcb4(%rip),%rdi
call   1040 <fail@plt>
mov    %rbx,%rdi
call   1090 <fgetc@plt>
cmp    $0x58,%al
je     13fd <test_sio2+0x22d>
lea    0xca5(%rip),%rdi
call   1040 <fail@plt>
mov    %rbx,%rdi
call   1090 <fgetc@plt>
cmp    $0x42,%al
je     1415 <test_sio2+0x245>
lea    0xc96(%rip),%rdi
call   1040 <fail@plt>
mov    $0x58,%edi
mov    %rbx,%rsi
call   10e0 <ungetc@plt>
cmp    $0x58,%al
je     1432 <test_sio2+0x262>
lea    0xc82(%rip),%rdi
call   1040 <fail@plt>
mov    %rbx,%rdi
call   1090 <fgetc@plt>
cmp    $0x58,%al
je     144a <test_sio2+0x27a>
lea    0xc73(%rip),%rdi
call   1040 <fail@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
je     1463 <test_sio2+0x293>
lea    0xc63(%rip),%rdi
call   1040 <fail@plt>
lea    0xbb8(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <unlink@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"fileno\00"
@stdin = global i32* null
@.str.1 = [9 x i8] c"fileno-1\00"
@stdout = global i32* null
@.str.2 = [9 x i8] c"fileno-2\00"
@stderr = global i32* null
@.str.3 = [9 x i8] c"fileno-3\00"
@.str.4 = [10 x i8] c"stdio.tmp\00"
@.str.5 = [3 x i8] c"w+\00"
@.str.6 = [8 x i8] c"fopen-4\00"
@.str.7 = [6 x i8] c"fputc\00"
@.str.8 = [8 x i8] c"fputc-1\00"
@.str.9 = [7 x i8] c"fflush\00"
@.str.10 = [9 x i8] c"fflush-1\00"
@SEEK_END = global i32 0
@.str.11 = [9 x i8] c"fflush-2\00"
@.str.12 = [7 x i8] c"rewind\00"
@SEEK_CUR = global i32 0
@.str.13 = [9 x i8] c"rewind-1\00"
@.str.14 = [6 x i8] c"fgets\00"
@.str.15 = [8 x i8] c"fgetc-1\00"
@EOF = global i8 0
@.str.16 = [8 x i8] c"fgetc-2\00"
@.str.17 = [7 x i8] c"ungetc\00"
@.str.18 = [9 x i8] c"ungetc-0\00"
@.str.19 = [9 x i8] c"ungetc-1\00"
@.str.20 = [9 x i8] c"ungetc-2\00"
@.str.21 = [9 x i8] c"ungetc-3\00"
@.str.22 = [9 x i8] c"ungetc-4\00"
@.str.23 = [9 x i8] c"ungetc-5\00"
@.str.24 = [9 x i8] c"fclose-5\00"
define void @test_sio2() {
%1 = alloca i32*
%2 = alloca i32
%3 = call i32 @pr(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = load i32*, i32** @stdin
%5 = call i32 @fileno(i32* %4)
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32*, i32** @stdout
%11 = call i32 @fileno(i32* %10)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = load i32*, i32** @stderr
%17 = call i32 @fileno(i32* %16)
%18 = icmp ne i32 %17, 2
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %22, i32** %1
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @fail(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %150
26: ; preds = %21
%27 = call i32 @pr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
store i32 65, i32* %2
br label %28
28: ; preds = %40, %26
%29 = load i32, i32* %2
%30 = icmp sle i32 %29, 90
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = load i32, i32* %2
%33 = load i32*, i32** %1
%34 = call i32 @fputc(i32 %32, i32* %33)
%35 = load i32, i32* %2
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 @fail(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %39
39: ; preds = %37, %31
br label %40
40: ; preds = %39
%41 = load i32, i32* %2
%42 = add nsw i32 %41, 1
store i32 %42, i32* %2
br label %28
43: ; preds = %28
%44 = call i32 @pr(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%45 = load i32*, i32** %1
%46 = call i64 @fflush(i32* %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
br label %50
50: ; preds = %48, %43
%51 = load i32*, i32** %1
%52 = call i32 @fileno(i32* %51)
%53 = load i32, i32* @SEEK_END
%54 = call i32 @lseek(i32 %52, i32 0, i32 %53)
%55 = icmp ne i32 %54, 26
br i1 %55, label %56, label %58
56: ; preds = %50
%57 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
br label %58
58: ; preds = %56, %50
%59 = call i32 @pr(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%60 = load i32*, i32** %1
%61 = call i32 @rewind(i32* %60)
%62 = load i32*, i32** %1
%63 = call i32 @fileno(i32* %62)
%64 = load i32, i32* @SEEK_CUR
%65 = call i32 @lseek(i32 %63, i32 0, i32 %64)
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %58
%68 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0))
br label %69
69: ; preds = %67, %58
%70 = call i32 @pr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0))
store i32 65, i32* %2
br label %71
71: ; preds = %83, %69
%72 = load i32, i32* %2
%73 = icmp sle i32 %72, 90
br i1 %73, label %74, label %86
74: ; preds = %71
%75 = load i32*, i32** %1
%76 = call signext i8 @fgetc(i32* %75)
%77 = sext i8 %76 to i32
%78 = load i32, i32* %2
%79 = icmp ne i32 %77, %78
br i1 %79, label %80, label %82
80: ; preds = %74
%81 = call i32 @fail(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0))
br label %86
82: ; preds = %74
br label %83
83: ; preds = %82
%84 = load i32, i32* %2
%85 = add nsw i32 %84, 1
store i32 %85, i32* %2
br label %71
86: ; preds = %80, %71
%87 = load i32*, i32** %1
%88 = call signext i8 @fgetc(i32* %87)
%89 = sext i8 %88 to i32
%90 = load i8, i8* @EOF
%91 = sext i8 %90 to i32
%92 = icmp ne i32 %89, %91
br i1 %92, label %93, label %95
93: ; preds = %86
%94 = call i32 @fail(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.16, i64 0, i64 0))
br label %95
95: ; preds = %93, %86
%96 = call i32 @pr(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0))
%97 = load i32*, i32** %1
%98 = call i32 @clearerr(i32* %97)
%99 = load i32*, i32** %1
%100 = call i32 @rewind(i32* %99)
%101 = load i32*, i32** %1
%102 = call signext i8 @fgetc(i32* %101)
%103 = sext i8 %102 to i32
%104 = icmp ne i32 %103, 65
br i1 %104, label %105, label %107
105: ; preds = %95
%106 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.18, i64 0, i64 0))
br label %107
107: ; preds = %105, %95
%108 = load i32*, i32** %1
%109 = call signext i8 @ungetc(i8 signext 88, i32* %108)
%110 = sext i8 %109 to i32
%111 = icmp ne i32 %110, 88
br i1 %111, label %112, label %114
112: ; preds = %107
%113 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0))
br label %114
114: ; preds = %112, %107
%115 = load i32*, i32** %1
%116 = call signext i8 @fgetc(i32* %115)
%117 = sext i8 %116 to i32
%118 = icmp ne i32 %117, 88
br i1 %118, label %119, label %121
119: ; preds = %114
%120 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.20, i64 0, i64 0))
br label %121
121: ; preds = %119, %114
%122 = load i32*, i32** %1
%123 = call signext i8 @fgetc(i32* %122)
%124 = sext i8 %123 to i32
%125 = icmp ne i32 %124, 66
br i1 %125, label %126, label %128
126: ; preds = %121
%127 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.21, i64 0, i64 0))
br label %128
128: ; preds = %126, %121
%129 = load i32*, i32** %1
%130 = call signext i8 @ungetc(i8 signext 88, i32* %129)
%131 = sext i8 %130 to i32
%132 = icmp ne i32 %131, 88
br i1 %132, label %133, label %135
133: ; preds = %128
%134 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.22, i64 0, i64 0))
br label %135
135: ; preds = %133, %128
%136 = load i32*, i32** %1
%137 = call signext i8 @fgetc(i32* %136)
%138 = sext i8 %137 to i32
%139 = icmp ne i32 %138, 88
br i1 %139, label %140, label %142
140: ; preds = %135
%141 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.23, i64 0, i64 0))
br label %142
142: ; preds = %140, %135
%143 = load i32*, i32** %1
%144 = call i64 @fclose(i32* %143)
%145 = icmp ne i64 %144, 0
br i1 %145, label %146, label %148
146: ; preds = %142
%147 = call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.24, i64 0, i64 0))
br label %148
148: ; preds = %146, %142
%149 = call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %150
150: ; preds = %148, %24
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"fileno\00"
@stdin = global i32* null
@.str.1 = [9 x i8] c"fileno-1\00"
@stdout = global i32* null
@.str.2 = [9 x i8] c"fileno-2\00"
@stderr = global i32* null
@.str.3 = [9 x i8] c"fileno-3\00"
@.str.4 = [10 x i8] c"stdio.tmp\00"
@.str.5 = [3 x i8] c"w+\00"
@.str.6 = [8 x i8] c"fopen-4\00"
@.str.7 = [6 x i8] c"fputc\00"
@.str.8 = [8 x i8] c"fputc-1\00"
@.str.9 = [7 x i8] c"fflush\00"
@.str.10 = [9 x i8] c"fflush-1\00"
@SEEK_END = global i32 0
@.str.11 = [9 x i8] c"fflush-2\00"
@.str.12 = [7 x i8] c"rewind\00"
@SEEK_CUR = global i32 0
@.str.13 = [9 x i8] c"rewind-1\00"
@.str.14 = [6 x i8] c"fgets\00"
@.str.15 = [8 x i8] c"fgetc-1\00"
@EOF = global i8 0
@.str.16 = [8 x i8] c"fgetc-2\00"
@.str.17 = [7 x i8] c"ungetc\00"
@.str.18 = [9 x i8] c"ungetc-0\00"
@.str.19 = [9 x i8] c"ungetc-1\00"
@.str.20 = [9 x i8] c"ungetc-2\00"
@.str.21 = [9 x i8] c"ungetc-3\00"
@.str.22 = [9 x i8] c"ungetc-4\00"
@.str.23 = [9 x i8] c"ungetc-5\00"
@.str.24 = [9 x i8] c"fclose-5\00"
define void @test_sio2() {
%1 = tail call i32 @pr(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%2 = load i32*, i32** @stdin
%3 = tail call i32 @fileno(i32* %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = load i32*, i32** @stdout
%9 = tail call i32 @fileno(i32* %8)
%10 = icmp eq i32 %9, 1
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
%14 = load i32*, i32** @stderr
%15 = tail call i32 @fileno(i32* %14)
%16 = icmp eq i32 %15, 2
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
%20 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @fail(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %115
24: ; preds = %19
%25 = tail call i32 @pr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %26
26: ; preds = %24, %32
%27 = phi i32 [ 65, %24 ], [ %33, %32 ]
%28 = tail call i32 @fputc(i32 %27, i32* %20)
%29 = icmp eq i32 %28, %27
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = tail call i32 @fail(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %32
32: ; preds = %26, %30
%33 = add nuw nsw i32 %27, 1
%34 = icmp eq i32 %33, 91
br i1 %34, label %35, label %26
35: ; preds = %32
%36 = tail call i32 @pr(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%37 = tail call i64 @fflush(i32* %20)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
br label %41
41: ; preds = %39, %35
%42 = tail call i32 @fileno(i32* %20)
%43 = load i32, i32* @SEEK_END
%44 = tail call i32 @lseek(i32 %42, i32 0, i32 %43)
%45 = icmp eq i32 %44, 26
br i1 %45, label %48, label %46
46: ; preds = %41
%47 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
br label %48
48: ; preds = %46, %41
%49 = tail call i32 @pr(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%50 = tail call i32 @rewind(i32* %20)
%51 = tail call i32 @fileno(i32* %20)
%52 = load i32, i32* @SEEK_CUR
%53 = tail call i32 @lseek(i32 %51, i32 0, i32 %52)
%54 = icmp eq i32 %53, 0
br i1 %54, label %57, label %55
55: ; preds = %48
%56 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0))
br label %57
57: ; preds = %55, %48
%58 = tail call i32 @pr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0))
br label %62
59: ; preds = %62
%60 = add nuw nsw i32 %63, 1
%61 = icmp eq i32 %60, 91
br i1 %61, label %69, label %62
62: ; preds = %57, %59
%63 = phi i32 [ 65, %57 ], [ %60, %59 ]
%64 = tail call signext i8 @fgetc(i32* %20)
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %63, %65
br i1 %66, label %59, label %67
67: ; preds = %62
%68 = tail call i32 @fail(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0))
br label %69
69: ; preds = %59, %67
%70 = tail call signext i8 @fgetc(i32* %20)
%71 = load i8, i8* @EOF
%72 = icmp eq i8 %70, %71
br i1 %72, label %75, label %73
73: ; preds = %69
%74 = tail call i32 @fail(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.16, i64 0, i64 0))
br label %75
75: ; preds = %73, %69
%76 = tail call i32 @pr(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0))
%77 = tail call i32 @clearerr(i32* %20)
%78 = tail call i32 @rewind(i32* %20)
%79 = tail call signext i8 @fgetc(i32* %20)
%80 = icmp eq i8 %79, 65
br i1 %80, label %83, label %81
81: ; preds = %75
%82 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.18, i64 0, i64 0))
br label %83
83: ; preds = %81, %75
%84 = tail call signext i8 @ungetc(i8 signext 88, i32* %20)
%85 = icmp eq i8 %84, 88
br i1 %85, label %88, label %86
86: ; preds = %83
%87 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0))
br label %88
88: ; preds = %86, %83
%89 = tail call signext i8 @fgetc(i32* %20)
%90 = icmp eq i8 %89, 88
br i1 %90, label %93, label %91
91: ; preds = %88
%92 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.20, i64 0, i64 0))
br label %93
93: ; preds = %91, %88
%94 = tail call signext i8 @fgetc(i32* %20)
%95 = icmp eq i8 %94, 66
br i1 %95, label %98, label %96
96: ; preds = %93
%97 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.21, i64 0, i64 0))
br label %98
98: ; preds = %96, %93
%99 = tail call signext i8 @ungetc(i8 signext 88, i32* %20)
%100 = icmp eq i8 %99, 88
br i1 %100, label %103, label %101
101: ; preds = %98
%102 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.22, i64 0, i64 0))
br label %103
103: ; preds = %101, %98
%104 = tail call signext i8 @fgetc(i32* %20)
%105 = icmp eq i8 %104, 88
br i1 %105, label %108, label %106
106: ; preds = %103
%107 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.23, i64 0, i64 0))
br label %108
108: ; preds = %106, %103
%109 = tail call i64 @fclose(i32* %20)
%110 = icmp eq i64 %109, 0
br i1 %110, label %113, label %111
111: ; preds = %108
%112 = tail call i32 @fail(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.24, i64 0, i64 0))
br label %113
113: ; preds = %111, %108
%114 = tail call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %115
115: ; preds = %113, %22
ret void
}