#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int getc(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void initRW() {
  FILE *file;
  char *content = malloc(sizeof(char));
  file = fopen("/tmp/hello.text", "w");
  fputs("y", file);
  fputs("o", file);
  fputs("h", file);
  fputs("j", file);
  fputs("i", file);
  fprintf(file, "marco");
  fputs("m", file);
  fputs("e", file);
  fputs("r", file);
  fputs("l", file);
  fputs("i", file);
  fclose(file);
  file = fopen("/tmp/hello.text", "r");
  printf("%c", getc(file));
  printf("%c", getc(file));
  printf("%c", getc(file));
  printf("%c", getc(file));
  printf("%c \n", getc(file));
  fscanf(file, "%s", content);
  int index = 0;
  for (index = 0; *(content + index) != 0; index++)
    printf("%c", *(content + index));
  printf("\n\n");
  fclose(file);
}


x86 assembly (clang, -O0):
<initRW>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe63(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe5a(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xe2e(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xe20(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe08(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xdfa(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xdde(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xdc0(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd93(%rip),%rdi
lea    0xdb0(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,%esi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,%esi
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,%esi
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,%esi
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,%esi
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd27(%rip),%rsi
call   1060 <fscanf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1359 <initRW+0x1d9>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xce4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    131c <initRW+0x19c>
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initRW>:
push   %r15
push   %r14
push   %rbx
mov    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
lea    0xe47(%rip),%r14
lea    0xe50(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r15
mov    $0x79,%edi
mov    %rax,%rsi
call   1080 <fputc@plt>
mov    $0x6f,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
mov    $0x68,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
mov    $0x6a,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
mov    $0x69,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
lea    0xdff(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   10b0 <fwrite@plt>
mov    $0x6d,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
mov    $0x65,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
mov    $0x72,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
mov    $0x6c,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
mov    $0x69,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
lea    0xda3(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   10c0 <getc@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   10c0 <getc@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   10c0 <getc@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   10c0 <getc@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   10c0 <getc@plt>
lea    0xd4f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd44(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1070 <fscanf@plt>
mov    (%rbx),%al
test   %al,%al
je     1303 <initRW+0x163>
add    $0x1,%rbx
movsbl %al,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    12f0 <initRW+0x150>
lea    0xd13(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <fclose@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"/tmp/hello.text\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"y\00"
@.str.3 = [2 x i8] c"o\00"
@.str.4 = [2 x i8] c"h\00"
@.str.5 = [2 x i8] c"j\00"
@.str.6 = [2 x i8] c"i\00"
@.str.7 = [6 x i8] c"marco\00"
@.str.8 = [2 x i8] c"m\00"
@.str.9 = [2 x i8] c"e\00"
@.str.10 = [2 x i8] c"r\00"
@.str.11 = [2 x i8] c"l\00"
@.str.12 = [3 x i8] c"%c\00"
@.str.13 = [5 x i8] c"%c \0A\00"
@.str.14 = [3 x i8] c"%s\00"
@.str.15 = [3 x i8] c"\0A\0A\00"
define void @initRW() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i32
%4 = call i8* @malloc(i32 1)
store i8* %4, i8** %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %1
%6 = load i32*, i32** %1
%7 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%8 = load i32*, i32** %1
%9 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%10 = load i32*, i32** %1
%11 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32* %10)
%12 = load i32*, i32** %1
%13 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* %12)
%14 = load i32*, i32** %1
%15 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32* %14)
%16 = load i32*, i32** %1
%17 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%18 = load i32*, i32** %1
%19 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32* %18)
%20 = load i32*, i32** %1
%21 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32* %20)
%22 = load i32*, i32** %1
%23 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i32* %22)
%24 = load i32*, i32** %1
%25 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i32* %24)
%26 = load i32*, i32** %1
%27 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32* %26)
%28 = load i32*, i32** %1
%29 = call i32 @fclose(i32* %28)
%30 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i32* %30, i32** %1
%31 = load i32*, i32** %1
%32 = call i32 @getc(i32* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 %32)
%34 = load i32*, i32** %1
%35 = call i32 @getc(i32* %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 %35)
%37 = load i32*, i32** %1
%38 = call i32 @getc(i32* %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 %38)
%40 = load i32*, i32** %1
%41 = call i32 @getc(i32* %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 %41)
%43 = load i32*, i32** %1
%44 = call i32 @getc(i32* %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), i32 %44)
%46 = load i32*, i32** %1
%47 = load i8*, i8** %2
%48 = call i32 @fscanf(i32* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i8* %47)
store i32 0, i32* %3
store i32 0, i32* %3
br label %49
49: ; preds = %65, %0
%50 = load i8*, i8** %2
%51 = load i32, i32* %3
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %68
57: ; preds = %49
%58 = load i8*, i8** %2
%59 = load i32, i32* %3
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %57
%66 = load i32, i32* %3
%67 = add nsw i32 %66, 1
store i32 %67, i32* %3
br label %49
68: ; preds = %49
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0))
%70 = load i32*, i32** %1
%71 = call i32 @fclose(i32* %70)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"/tmp/hello.text\00"
@.str.1 = [2 x i8] c"w\00"
@.str.7 = [6 x i8] c"marco\00"
@.str.10 = [2 x i8] c"r\00"
@.str.13 = [5 x i8] c"%c \0A\00"
@.str.14 = [3 x i8] c"%s\00"
@str = [2 x i8] c"\0A\00"
define void @initRW() {
%1 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @fputc(i32 121, i32* %2)
%4 = tail call i32 @fputc(i32 111, i32* %2)
%5 = tail call i32 @fputc(i32 104, i32* %2)
%6 = tail call i32 @fputc(i32 106, i32* %2)
%7 = tail call i32 @fputc(i32 105, i32* %2)
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i64 5, i64 1, i32* %2)
%9 = tail call i32 @fputc(i32 109, i32* %2)
%10 = tail call i32 @fputc(i32 101, i32* %2)
%11 = tail call i32 @fputc(i32 114, i32* %2)
%12 = tail call i32 @fputc(i32 108, i32* %2)
%13 = tail call i32 @fputc(i32 105, i32* %2)
%14 = tail call i32 @fclose(i32* %2)
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%16 = tail call i32 @getc(i32* %15)
%17 = tail call i32 @putchar(i32 %16)
%18 = tail call i32 @getc(i32* %15)
%19 = tail call i32 @putchar(i32 %18)
%20 = tail call i32 @getc(i32* %15)
%21 = tail call i32 @putchar(i32 %20)
%22 = tail call i32 @getc(i32* %15)
%23 = tail call i32 @putchar(i32 %22)
%24 = tail call i32 @getc(i32* %15)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), i32 %24)
%26 = tail call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i8* %1)
%27 = load i8, i8* %1
%28 = icmp eq i8 %27, 0
br i1 %28, label %38, label %29
29: ; preds = %0, %29
%30 = phi i64 [ %34, %29 ], [ 0, %0 ]
%31 = phi i8 [ %36, %29 ], [ %27, %0 ]
%32 = sext i8 %31 to i32
%33 = tail call i32 @putchar(i32 %32)
%34 = add nuw i64 %30, 1
%35 = getelementptr inbounds i8, i8* %1, i64 %34
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %29
38: ; preds = %29, %0
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%40 = tail call i32 @fclose(i32* %15)
ret void
}