#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*/ message;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fputs(char *, int /*<<< orphan*/ *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ ftell(int /*<<< orphan*/ *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ printf(char *, ...);
int remove(char const *);
int rename(char const *, char const *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait_enter();
int main(void) {
  const char *filepath = "rwtest.txt";
  const char *filepath2 = "rwtest2.txt";
  FILE *fout;
  FILE *fin;
  char message[80];
  int result;
  printf("fatfs_stdio\n"
         "Press Enter to continue...\n");
  wait_enter();
  printf("Write a message:\n");
  scanf("%s", message);
  printf("Writing message to %s...\n", filepath);
  fout = fopen(filepath, "w");
  if (fout == NULL) {
    perror(filepath);
    return 1;
  } else {
    result = fputs(message, fout);
    if (result < 0) {
      perror(filepath);
      return 1;
    }
  }
  result = fflush(fout);
  if (result != 0) {
    perror(filepath);
    return 1;
  }
  printf("\nftell = %ld.\n", ftell(fout));
  result = fclose(fout);
  if (result != 0) {
    perror(filepath);
    return 1;
  }
  printf("Done.\n"
         "Reading message from %s...\n",
         filepath);
  fin = fopen(filepath, "r");
  if (fout == NULL) {
    perror(filepath);
    return 1;
  } else {
    while (!feof(fin)) {
      size_t nbytes;
      char *p;
      nbytes = fread(message, 1, sizeof(message), fin);
      if (ferror(fin)) {
        perror(filepath);
        fclose(fin);
        return 1;
      }
      p = message;
      while (nbytes > 0) {
        size_t nwritten;
        nwritten = fwrite(p, 1, nbytes, stdout);
        if (nwritten > 0) {
          nbytes -= nwritten;
          p += nwritten;
        }
      }
    }
  }
  printf("\nftell = %ld.\n", ftell(fin));
  result = fclose(fin);
  if (result != 0) {
    perror(filepath);
    return 1;
  }
  printf("Done.\n"
         "Renaming file...\n");
  result = rename(filepath, filepath2);
  if (result != 0) {
    perror(filepath2);
    return 1;
  }
  printf("Done.\n"
         "Removing file...\n");
  result = remove(filepath2);
  if (result != 0) {
    perror(filepath2);
    return 1;
  }
  printf("Done.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xdf7(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xdf7(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1100 <wait_enter@plt>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   10c0 <scanf@plt>
mov    -0x10(%rbp),%rsi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1291 <main+0xa1>
mov    -0x10(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    156a <main+0x37a>
lea    -0x80(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <fputs@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jge    12c6 <main+0xd6>
mov    -0x10(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    156a <main+0x37a>
jmp    12cb <main+0xdb>
mov    -0x20(%rbp),%rdi
call   10b0 <fflush@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     12fc <main+0x10c>
mov    -0x10(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    156a <main+0x37a>
mov    -0x20(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,%esi
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     1346 <main+0x156>
mov    -0x10(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    156a <main+0x37a>
mov    -0x10(%rbp),%rsi
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xd3e(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    138c <main+0x19c>
mov    -0x10(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    156a <main+0x37a>
jmp    1391 <main+0x1a1>
mov    -0x28(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    13af <main+0x1bf>
jmp    1484 <main+0x294>
lea    -0x80(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x50,%edx
call   1050 <fread@plt>
mov    %rax,-0x90(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     13fe <main+0x20e>
mov    -0x10(%rbp),%rdi
call   10e0 <perror@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    156a <main+0x37a>
lea    -0x80(%rbp),%rax
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x90(%rbp)
jbe    147f <main+0x28f>
mov    -0x98(%rbp),%rdi
mov    -0x90(%rbp),%rdx
mov    0x2bb4(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1110 <fwrite@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
jbe    147a <main+0x28a>
mov    -0xa0(%rbp),%rcx
mov    -0x90(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x90(%rbp)
mov    -0xa0(%rbp),%rax
add    -0x98(%rbp),%rax
mov    %rax,-0x98(%rbp)
jmp    1409 <main+0x219>
jmp    1391 <main+0x1a1>
jmp    1489 <main+0x299>
mov    -0x28(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,%esi
lea    0xbd5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     14d3 <main+0x2e3>
mov    -0x10(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    156a <main+0x37a>
lea    0xbc9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10f0 <rename@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     1516 <main+0x326>
mov    -0x18(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    156a <main+0x37a>
lea    0xb9e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <remove@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     1555 <main+0x365>
mov    -0x18(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    156a <main+0x37a>
lea    0xb77(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1110 <wait_enter@plt>
lea    0xe69(%rip),%rdi
call   1040 <puts@plt>
lea    0xde4(%rip),%rdi
mov    %rsp,%rsi
call   10d0 <scanf@plt>
lea    0xdd8(%rip),%rdi
lea    0xdb7(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdda(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     13ee <main+0x1ee>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1090 <fputs@plt>
test   %eax,%eax
js     13ee <main+0x1ee>
mov    %rbx,%rdi
call   10c0 <fflush@plt>
test   %eax,%eax
jne    13ee <main+0x1ee>
mov    %rbx,%rdi
call   10a0 <ftell@plt>
lea    0xd93(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
test   %eax,%eax
jne    13ee <main+0x1ee>
lea    0xd82(%rip),%rdi
lea    0xd36(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd8c(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
je     1378 <main+0x178>
mov    %r15,%rdi
call   10a0 <ftell@plt>
lea    0xd31(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
test   %eax,%eax
jne    13ee <main+0x1ee>
lea    0xd7c(%rip),%rdi
call   1040 <puts@plt>
lea    0xccf(%rip),%rdi
lea    0xcd3(%rip),%rsi
call   1100 <rename@plt>
test   %eax,%eax
jne    13f7 <main+0x1f7>
lea    0xd6c(%rip),%rdi
call   1040 <puts@plt>
lea    0xcb3(%rip),%rdi
call   1030 <remove@plt>
test   %eax,%eax
jne    13f7 <main+0x1f7>
lea    0xd63(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    1408 <main+0x208>
mov    0x2c61(%rip),%r13
jmp    13a0 <main+0x1a0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    12f6 <main+0xf6>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x50,%edx
mov    %r15,%rcx
call   1060 <fread@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    1416 <main+0x216>
test   %r12,%r12
je     1390 <main+0x190>
mov    %r14,%rbx
nopl   (%rax)
mov    0x0(%r13),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
call   1120 <fwrite@plt>
add    %rax,%rbx
sub    %rax,%r12
jne    13d0 <main+0x1d0>
jmp    1390 <main+0x190>
lea    0xc0b(%rip),%rdi
jmp    13fe <main+0x1fe>
lea    0xc0d(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xbe3(%rip),%rdi
call   10f0 <perror@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
jmp    1403 <main+0x203>

LLVM IR (-O0):
@.str = [11 x i8] c"rwtest.txt\00"
@.str.1 = [12 x i8] c"rwtest2.txt\00"
@.str.2 = [40 x i8] c"fatfs_stdio\0APress Enter to continue...\0A\00"
@.str.3 = [18 x i8] c"Write a message:\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [26 x i8] c"Writing message to %s...\0A\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [15 x i8] c"\0Aftell = %ld.\0A\00"
@.str.8 = [34 x i8] c"Done.\0AReading message from %s...\0A\00"
@.str.9 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.10 = [24 x i8] c"Done.\0ARenaming file...\0A\00"
@.str.11 = [24 x i8] c"Done.\0ARemoving file...\0A\00"
@.str.12 = [7 x i8] c"Done.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [80 x i8]
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (...) @wait_enter()
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %2
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %19, i32** %4
%20 = load i32*, i32** %4
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %0
%23 = load i8*, i8** %2
%24 = call i32 @perror(i8* %23)
store i32 1, i32* %1
br label %136
25: ; preds = %0
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%27 = load i32*, i32** %4
%28 = call i32 @fputs(i8* %26, i32* %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i8*, i8** %2
%33 = call i32 @perror(i8* %32)
store i32 1, i32* %1
br label %136
34: ; preds = %25
br label %35
35: ; preds = %34
%36 = load i32*, i32** %4
%37 = call i32 @fflush(i32* %36)
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i8*, i8** %2
%42 = call i32 @perror(i8* %41)
store i32 1, i32* %1
br label %136
43: ; preds = %35
%44 = load i32*, i32** %4
%45 = call i32 @ftell(i32* %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %45)
%47 = load i32*, i32** %4
%48 = call i32 @fclose(i32* %47)
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %43
%52 = load i8*, i8** %2
%53 = call i32 @perror(i8* %52)
store i32 1, i32* %1
br label %136
54: ; preds = %43
%55 = load i8*, i8** %2
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i8* %55)
%57 = load i8*, i8** %2
%58 = call i32* @fopen(i8* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %58, i32** %5
%59 = load i32*, i32** %4
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %64
61: ; preds = %54
%62 = load i8*, i8** %2
%63 = call i32 @perror(i8* %62)
store i32 1, i32* %1
br label %136
64: ; preds = %54
br label %65
65: ; preds = %102, %64
%66 = load i32*, i32** %5
%67 = call i32 @feof(i32* %66)
%68 = icmp ne i32 %67, 0
%69 = xor i1 %68, true
br i1 %69, label %70, label %103
70: ; preds = %65
%71 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%72 = load i32*, i32** %5
%73 = call i64 @fread(i8* %71, i32 1, i32 80, i32* %72)
store i64 %73, i64* %8
%74 = load i32*, i32** %5
%75 = call i64 @ferror(i32* %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %82
77: ; preds = %70
%78 = load i8*, i8** %2
%79 = call i32 @perror(i8* %78)
%80 = load i32*, i32** %5
%81 = call i32 @fclose(i32* %80)
store i32 1, i32* %1
br label %136
82: ; preds = %70
%83 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
store i8* %83, i8** %9
br label %84
84: ; preds = %101, %82
%85 = load i64, i64* %8
%86 = icmp ugt i64 %85, 0
br i1 %86, label %87, label %102
87: ; preds = %84
%88 = load i8*, i8** %9
%89 = load i64, i64* %8
%90 = load i32, i32* @stdout
%91 = call i64 @fwrite(i8* %88, i32 1, i64 %89, i32 %90)
store i64 %91, i64* %10
%92 = load i64, i64* %10
%93 = icmp ugt i64 %92, 0
br i1 %93, label %94, label %101
94: ; preds = %87
%95 = load i64, i64* %10
%96 = load i64, i64* %8
%97 = sub i64 %96, %95
store i64 %97, i64* %8
%98 = load i64, i64* %10
%99 = load i8*, i8** %9
%100 = getelementptr inbounds i8, i8* %99, i64 %98
store i8* %100, i8** %9
br label %101
101: ; preds = %94, %87
br label %84
102: ; preds = %84
br label %65
103: ; preds = %65
br label %104
104: ; preds = %103
%105 = load i32*, i32** %5
%106 = call i32 @ftell(i32* %105)
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %106)
%108 = load i32*, i32** %5
%109 = call i32 @fclose(i32* %108)
store i32 %109, i32* %7
%110 = load i32, i32* %7
%111 = icmp ne i32 %110, 0
br i1 %111, label %112, label %115
112: ; preds = %104
%113 = load i8*, i8** %2
%114 = call i32 @perror(i8* %113)
store i32 1, i32* %1
br label %136
115: ; preds = %104
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%117 = load i8*, i8** %2
%118 = load i8*, i8** %3
%119 = call i32 @rename(i8* %117, i8* %118)
store i32 %119, i32* %7
%120 = load i32, i32* %7
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %125
122: ; preds = %115
%123 = load i8*, i8** %3
%124 = call i32 @perror(i8* %123)
store i32 1, i32* %1
br label %136
125: ; preds = %115
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
%127 = load i8*, i8** %3
%128 = call i32 @remove(i8* %127)
store i32 %128, i32* %7
%129 = load i32, i32* %7
%130 = icmp ne i32 %129, 0
br i1 %130, label %131, label %134
131: ; preds = %125
%132 = load i8*, i8** %3
%133 = call i32 @perror(i8* %132)
store i32 1, i32* %1
br label %136
134: ; preds = %125
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %1
br label %136
136: ; preds = %134, %131, %122, %112, %77, %61, %51, %40, %31, %22
%137 = load i32, i32* %1
ret i32 %137
}

LLVM IR (-O2):
@.str = [11 x i8] c"rwtest.txt\00"
@.str.1 = [12 x i8] c"rwtest2.txt\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [26 x i8] c"Writing message to %s...\0A\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [15 x i8] c"\0Aftell = %ld.\0A\00"
@.str.8 = [34 x i8] c"Done.\0AReading message from %s...\0A\00"
@.str.9 = [2 x i8] c"r\00"
@stdout = global i32 0
@str = [39 x i8] c"fatfs_stdio\0APress Enter to continue...\00"
@str.13 = [17 x i8] c"Write a message:\00"
@str.14 = [23 x i8] c"Done.\0ARenaming file...\00"
@str.15 = [23 x i8] c"Done.\0ARemoving file...\00"
@str.16 = [6 x i8] c"Done.\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (...) @wait_enter()
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.13, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %75
12: ; preds = %0
%13 = call i32 @fputs(i8* %2, i32* %8)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %75
17: ; preds = %12
%18 = call i32 @fflush(i32* %8)
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %75
22: ; preds = %17
%23 = call i32 @ftell(i32* %8)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %23)
%25 = call i32 @fclose(i32* %8)
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %22
%28 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %75
29: ; preds = %22
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%31 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%32 = call i32 @feof(i32* %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %54
34: ; preds = %29, %51
%35 = call i64 @fread(i8* %2, i32 1, i32 80, i32* %31)
%36 = call i64 @ferror(i32* %31)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = icmp eq i64 %35, 0
br i1 %39, label %51, label %43
40: ; preds = %34
%41 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%42 = call i32 @fclose(i32* %31)
br label %75
43: ; preds = %38, %43
%44 = phi i8* [ %49, %43 ], [ %2, %38 ]
%45 = phi i64 [ %48, %43 ], [ %35, %38 ]
%46 = load i32, i32* @stdout
%47 = call i64 @fwrite(i8* %44, i32 1, i64 %45, i32 %46)
%48 = sub i64 %45, %47
%49 = getelementptr i8, i8* %44, i64 %47
%50 = icmp eq i64 %48, 0
br i1 %50, label %51, label %43
51: ; preds = %43, %38
%52 = call i32 @feof(i32* %31)
%53 = icmp eq i32 %52, 0
br i1 %53, label %34, label %54
54: ; preds = %51, %29
%55 = call i32 @ftell(i32* %31)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %55)
%57 = call i32 @fclose(i32* %31)
%58 = icmp eq i32 %57, 0
br i1 %58, label %61, label %59
59: ; preds = %54
%60 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %75
61: ; preds = %54
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.14, i64 0, i64 0))
%63 = call i32 @rename(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%64 = icmp eq i32 %63, 0
br i1 %64, label %67, label %65
65: ; preds = %61
%66 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %75
67: ; preds = %61
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.15, i64 0, i64 0))
%69 = call i32 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%70 = icmp eq i32 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %67
%72 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %75
73: ; preds = %67
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.16, i64 0, i64 0))
br label %75
75: ; preds = %40, %73, %71, %65, %59, %27, %20, %15, %10
%76 = phi i32 [ 1, %10 ], [ 1, %15 ], [ 1, %20 ], [ 1, %27 ], [ 1, %59 ], [ 1, %65 ], [ 1, %71 ], [ 0, %73 ], [ 1, %40 ]
ret i32 %76
}