#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stderr;
int main(int argc, char **argv) {
  int i;
  FILE *f = fopen("out", "w+");
  for (i = 0; i < 2; i++) {
    printf("I wrote Forbidden IO\n");
    fprintf(f, "Forbidden IO\n");
    fflush(f);
  }
  rewind(f);
  for (i = 0; i < 2; i++) {
    char str[256];
    fscanf(f, "%s", str);
    printf("I read %s\n", str);
  }
  for (i = 0; i < 2; i++) {
    printf("Correct IO\n");
    fprintf(stderr, "Correct IO\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    11d6 <main+0x76>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <fflush@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1197 <main+0x37>
mov    -0x20(%rbp),%rdi
call   1040 <rewind@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    122a <main+0xca>
mov    -0x20(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xe1b(%rip),%rsi
call   1050 <fscanf@plt>
lea    -0x120(%rbp),%rsi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e6 <main+0x86>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    126d <main+0x10d>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%rdi
lea    0xdd1(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1231 <main+0xd1>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe7b(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe9f(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xe5d(%rip),%r15
mov    $0xd,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0xd,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    %rbx,%rdi
call   1050 <rewind@plt>
lea    0xe1a(%rip),%r14
mov    %rsp,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <fscanf@plt>
lea    0xe05(%rip),%r12
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <fscanf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xded(%rip),%r15
mov    %r15,%rdi
call   1030 <puts@plt>
mov    0x2d8f(%rip),%rbx
mov    (%rbx),%rcx
lea    0xdc8(%rip),%r14
mov    $0xb,%esi
mov    $0x1,%edx
mov    %r14,%rdi
call   1090 <fwrite@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    (%rbx),%rcx
mov    $0xb,%esi
mov    $0x1,%edx
mov    %r14,%rdi
call   1090 <fwrite@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"out\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [22 x i8] c"I wrote Forbidden IO\0A\00"
@.str.3 = [14 x i8] c"Forbidden IO\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [11 x i8] c"I read %s\0A\00"
@.str.6 = [12 x i8] c"Correct IO\0A\00"
@stderr = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %7
store i32 0, i32* %6
br label %10
10: ; preds = %19, %2
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32*, i32** %7
%16 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32*, i32** %7
%18 = call i32 @fflush(i32* %17)
br label %19
19: ; preds = %13
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %10
22: ; preds = %10
%23 = load i32*, i32** %7
%24 = call i32 @rewind(i32* %23)
store i32 0, i32* %6
br label %25
25: ; preds = %34, %22
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 2
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i32*, i32** %7
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%31 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %28
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %25
37: ; preds = %25
store i32 0, i32* %6
br label %38
38: ; preds = %45, %37
%39 = load i32, i32* %6
%40 = icmp slt i32 %39, 2
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%43 = load i32*, i32** @stderr
%44 = call i32 @fprintf(i32* %43, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %45
45: ; preds = %41
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %38
48: ; preds = %38
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [4 x i8] c"out\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.3 = [14 x i8] c"Forbidden IO\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [11 x i8] c"I read %s\0A\00"
@.str.6 = [12 x i8] c"Correct IO\0A\00"
@stderr = global i32* null
@str = [11 x i8] c"Correct IO\00"
@str.7 = [21 x i8] c"I wrote Forbidden IO\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0))
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i64 13, i64 1, i32* %4)
%7 = tail call i32 @fflush(i32* %4)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0))
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i64 13, i64 1, i32* %4)
%10 = tail call i32 @fflush(i32* %4)
%11 = tail call i32 @rewind(i32* %4)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %12)
%15 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %12)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%18 = load i32*, i32** @stderr
%19 = call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i64 11, i64 1, i32* %18)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%21 = load i32*, i32** @stderr
%22 = call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i64 11, i64 1, i32* %21)
ret i32 0
}