#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*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, scalar_t__, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, scalar_t__, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strlen(char *);
int main() {
  FILE *fp;
  char c[] = "Linkerist Heracles";
  char buffer[20];
  fp = fopen("file.txt", "w+");
  fwrite(c, strlen(c) + 1, 1, fp);
  fseek(fp, SEEK_SET, 0);
  fread(buffer, strlen(c) + 1, 1, fp);
  printf("%s\n", buffer);
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe74(%rip),%ax
mov    %ax,-0x20(%rbp)
mov    0xe6c(%rip),%al
mov    %al,-0x1e(%rbp)
lea    0xe63(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    -0x10(%rbp),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <fseek@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x50(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movaps 0xe82(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x73656c,0xf(%rsp)
lea    0xe82(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1070 <fseek@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rsi
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0xe25(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.c = [19 x i8] c"Linkerist Heracles\00"
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@SEEK_SET = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [19 x i8]
%4 = alloca [20 x i8]
store i32 0, i32* %1
%5 = bitcast [19 x i8]* %3 to i8*
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = getelementptr inbounds [19 x i8], [19 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [19 x i8], [19 x i8]* %3, i64 0, i64 0
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 1
%11 = load i32*, i32** %2
%12 = call i32 @fwrite(i8* %7, i64 %10, i32 1, i32* %11)
%13 = load i32*, i32** %2
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @fseek(i32* %13, i32 %14, i32 0)
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%17 = getelementptr inbounds [19 x i8], [19 x i8]* %3, i64 0, i64 0
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %18, 1
%20 = load i32*, i32** %2
%21 = call i32 @fread(i8* %16, i64 %19, i32 1, i32* %20)
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i32*, i32** %2
%25 = call i32 @fclose(i32* %24)
ret i32 0
}

LLVM IR (-O2):
@__const.main.c = [19 x i8] c"Linkerist Heracles\00"
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@SEEK_SET = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [19 x i8]
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [19 x i8], [19 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = call i64 @strlen(i8* %3)
%7 = add nsw i64 %6, 1
%8 = call i32 @fwrite(i8* %3, i64 %7, i32 1, i32* %5)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %5, i32 %9, i32 0)
%11 = call i64 @strlen(i8* %3)
%12 = add nsw i64 %11, 1
%13 = call i32 @fread(i8* %4, i64 %12, i32 1, i32* %5)
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%15 = call i32 @fclose(i32* %5)
ret i32 0
}