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

/* Variables and functions */
int /*<<< orphan*/ close(int /*<<< orphan*/ *);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ remove(char *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  FILE *a_file;
  time_t a_time = time(NULL);
  char *time_text = ctime(&a_time);
  int time_len = strlen(time_text) * sizeof(char);
  int id = fork();
  if (id != 0) {
    char *time_text = (char *)malloc(time_len);
    wait(NULL);
    a_file = fopen("data", "r");
    int r_fread = fread(time_text, time_len, 1, a_file);
    printf("time_text: %s\n", time_text);
    close(a_file);
    remove("data");
    free(time_text);
    return 0;
  } else {
    a_file = fopen("data", "w");
    time_t a_time = time(NULL);
    char *time_text = ctime(&a_time);
    fwrite(time_text, time_len, 1, a_file);
    close(a_file);
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1060 <ctime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     129c <main+0xcc>
mov    -0x24(%rbp),%edi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <wait@plt>
lea    0xdc6(%rip),%rdi
lea    0xdc4(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1050 <fread@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xd9a(%rip),%rdi
call   1080 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1090 <close@plt>
lea    0xd7e(%rip),%rdi
call   1040 <remove@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f1 <main+0x121>
lea    0xd5d(%rip),%rdi
lea    0xd6c(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,-0x38(%rbp)
lea    -0x38(%rbp),%rdi
call   1060 <ctime@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1060 <ctime@plt>
mov    %rax,%rdi
call   1070 <strlen@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     1269 <main+0x99>
mov    %r15d,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   10e0 <wait@plt>
lea    0xde5(%rip),%r14
lea    0xde3(%rip),%rsi
mov    %r14,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
lea    0xdc0(%rip),%rdi
mov    %rbx,%rsi
call   1080 <printf@plt>
mov    %rbp,%rdi
call   1090 <close@plt>
mov    %r14,%rdi
call   1040 <remove@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    12ac <main+0xdc>
lea    0xd90(%rip),%rdi
lea    0xd9f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,(%rsp)
mov    %rsp,%rdi
call   1060 <ctime@plt>
mov    %rax,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10d0 <fwrite@plt>
mov    %rbx,%rdi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"data\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"time_text: %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %1
%11 = call i32 @time(i32* null)
store i32 %11, i32* %3
%12 = call i8* @ctime(i32* %3)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 1
%17 = trunc i64 %16 to i32
store i32 %17, i32* %5
%18 = call i32 (...) @fork()
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %0
%22 = load i32, i32* %5
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %7
%25 = call i32 @wait(i32* null)
%26 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %2
%27 = load i8*, i8** %7
%28 = load i32, i32* %5
%29 = load i32*, i32** %2
%30 = call i32 @fread(i8* %27, i32 %28, i32 1, i32* %29)
store i32 %30, i32* %8
%31 = load i8*, i8** %7
%32 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i32*, i32** %2
%34 = call i32 @close(i32* %33)
%35 = call i32 @remove(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%36 = load i8*, i8** %7
%37 = call i32 @free(i8* %36)
store i32 0, i32* %1
br label %48
38: ; preds = %0
%39 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %39, i32** %2
%40 = call i32 @time(i32* null)
store i32 %40, i32* %9
%41 = call i8* @ctime(i32* %9)
store i8* %41, i8** %10
%42 = load i8*, i8** %10
%43 = load i32, i32* %5
%44 = load i32*, i32** %2
%45 = call i32 @fwrite(i8* %42, i32 %43, i32 1, i32* %44)
%46 = load i32*, i32** %2
%47 = call i32 @close(i32* %46)
store i32 0, i32* %1
br label %48
48: ; preds = %38, %21
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@.str = [5 x i8] c"data\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"time_text: %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 @time(i32* null)
store i32 %4, i32* %1
%5 = call i8* @ctime(i32* %1)
%6 = call i32 @strlen(i8* %5)
%7 = call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %0
%10 = call i64 @malloc(i32 %6)
%11 = inttoptr i64 %10 to i8*
%12 = call i32 @wait(i32* null)
%13 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @fread(i8* %11, i32 %6, i32 1, i32* %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%16 = call i32 @close(i32* %13)
%17 = call i32 @remove(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @free(i8* %11)
br label %26
19: ; preds = %0
%20 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = bitcast i32* %2 to i8*
%22 = call i32 @time(i32* null)
store i32 %22, i32* %2
%23 = call i8* @ctime(i32* %2)
%24 = call i32 @fwrite(i8* %23, i32 %6, i32 1, i32* %20)
%25 = call i32 @close(i32* %20)
br label %26
26: ; preds = %19, %9
ret i32 0
}