#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 *);
void fread_t() {
  FILE *fp;
  char c[] = "this is tutorialspoint";
  char buffer[100];
  fp = fopen("file.txt", "w+");
  fwrite(c, strlen(c) + 1, 1, fp);
  fseek(fp, 0, SEEK_SET);
  fread(buffer, strlen(c) + 1, 1, fp);
  printf("%s\n", buffer);
  fclose(fp);
}


x86 assembly (clang, -O0):
<fread_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    0xe7e(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe7b(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe79(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xe73(%rip),%ax
mov    %ax,-0xc(%rbp)
mov    0xe6b(%rip),%al
mov    %al,-0xa(%rbp)
lea    0xe62(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xa0(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    -0x8(%rbp),%rdi
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x98(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x90(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_t>:
push   %r14
push   %rbx
sub    $0x88,%rsp
movaps 0xe7f(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x746e696f70736c,%rax
mov    %rax,0xf(%rsp)
lea    0xe7c(%rip),%rdi
lea    0xe7e(%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    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
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    0xe1f(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.fread_t.c = [23 x i8] c"this is tutorialspoint\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 void @fread_t() {
%1 = alloca i32*
%2 = alloca [23 x i8]
%3 = alloca [100 x i8]
%4 = bitcast [23 x i8]* %2 to i8*
%5 = 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* %5, i32** %1
%6 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%8 = call i64 @strlen(i8* %7)
%9 = add nsw i64 %8, 1
%10 = load i32*, i32** %1
%11 = call i32 @fwrite(i8* %6, i64 %9, i32 1, i32* %10)
%12 = load i32*, i32** %1
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @fseek(i32* %12, i32 0, i32 %13)
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%16 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = load i32*, i32** %1
%20 = call i32 @fread(i8* %15, i64 %18, i32 1, i32* %19)
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32*, i32** %1
%24 = call i32 @fclose(i32* %23)
ret void
}

LLVM IR (-O2):
@__const.fread_t.c = [23 x i8] c"this is tutorialspoint\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 void @fread_t() {
%1 = alloca [23 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [23 x i8], [23 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 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 0, i32 %9)
%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 void
}