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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
void WriteFile(void *memory) {
  FILE *newFile;
  char fileName[100];
  char readBuffer[5000];
  int byteNum;
  printf("\n---------WRITE FILE-----------\n");
  printf("enter a file name: ");
  scanf("%s", fileName);
  printf("enter of Bytes to write: ");
  scanf("%d", &byteNum);
  newFile = fopen(fileName, "w");
  fwrite(memory, 1, byteNum, newFile);
  fclose(newFile);
  newFile = fopen(fileName, "r");
  fread(readBuffer, sizeof(readBuffer), 1, newFile);
  fclose(newFile);
  printf("Contents: %s\n", readBuffer);
}


x86 assembly (clang, -O0):
<WriteFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1420,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea0(%rip),%rdi
lea    -0x1414(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x80(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1414(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x80(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x1410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1388,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x1410(%rbp),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x1420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x1410,%rsp
mov    %rdi,%r14
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe74(%rip),%rdi
lea    0x10(%rsp),%r15
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6d(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
lea    0xe5d(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe31(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0x80(%rsp),%r14
mov    %r14,%rdi
mov    $0x1388,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xdfc(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"\0A---------WRITE FILE-----------\0A\00"
@.str.1 = [20 x i8] c"enter a file name: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [26 x i8] c"enter of Bytes to write: \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [14 x i8] c"Contents: %s\0A\00"
define void @WriteFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [100 x i8]
%5 = alloca [5000 x i8]
%6 = alloca i32
store i8* %0, i8** %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %6)
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %14, i32** %3
%15 = load i8*, i8** %2
%16 = load i32, i32* %6
%17 = load i32*, i32** %3
%18 = call i32 @fwrite(i8* %15, i32 1, i32 %16, i32* %17)
%19 = load i32*, i32** %3
%20 = call i32 @fclose(i32* %19)
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %22, i32** %3
%23 = getelementptr inbounds [5000 x i8], [5000 x i8]* %5, i64 0, i64 0
%24 = load i32*, i32** %3
%25 = call i32 @fread(i8* %23, i32 5000, i32 1, i32* %24)
%26 = load i32*, i32** %3
%27 = call i32 @fclose(i32* %26)
%28 = getelementptr inbounds [5000 x i8], [5000 x i8]* %5, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %28)
ret void
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"enter a file name: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [26 x i8] c"enter of Bytes to write: \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [14 x i8] c"Contents: %s\0A\00"
@str = [32 x i8] c"\0A---------WRITE FILE-----------\00"
define void @WriteFile(i8* nocapture %0) {
%2 = alloca [100 x i8]
%3 = alloca [5000 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [5000 x i8], [5000 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%13 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%14 = load i32, i32* %4
%15 = call i32 @fwrite(i8* %0, i32 1, i32 %14, i32* %13)
%16 = call i32 @fclose(i32* %13)
%17 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%18 = call i32 @fread(i8* %6, i32 5000, i32 1, i32* %17)
%19 = call i32 @fclose(i32* %17)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %6)
ret void
}