#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*/ readbuffer;

/* Variables and functions */
char *asctime(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int fork();
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main(void) {
  time_t t_time = time(NULL);
  char readbuffer[64];
  int fd[2];
  pipe(fd);
  int id;
  id = fork();
  if (id == 0) {
    printf("+Start child work\n");
    close(fd[1]);
    read(fd[0], readbuffer, sizeof(readbuffer));
    printf("Received time: %s", readbuffer);
    printf("+Finish child work\n");
    return 0;
  } else {
    printf("+Start parent work\n");
    char *time_text = asctime(localtime(&t_time));
    close(fd[0]);
    write(fd[1], time_text, (strlen(time_text) + 1));
    printf("+Finish parent work\n");
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,-0x8(%rbp)
lea    -0x58(%rbp),%rdi
call   1090 <pipe@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    122e <main+0x8e>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
mov    -0x58(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
call   10a0 <read@plt>
lea    -0x50(%rbp),%rsi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1297 <main+0xf7>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
mov    %rax,-0x68(%rbp)
mov    -0x58(%rbp),%edi
call   1080 <close@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x68(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0x4(%rsp),%rdi
call   10a0 <pipe@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
je     1222 <main+0x72>
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1070 <asctime@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%edi
call   1090 <close@plt>
mov    0x8(%rsp),%ebp
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <write@plt>
lea    0xe05(%rip),%rdi
jmp    1265 <main+0xb5>
lea    0xe10(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%edi
call   1090 <close@plt>
mov    0x4(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x40,%edx
call   10b0 <read@plt>
lea    0xdac(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xde6(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"+Start child work\0A\00"
@.str.1 = [18 x i8] c"Received time: %s\00"
@.str.2 = [20 x i8] c"+Finish child work\0A\00"
@.str.3 = [20 x i8] c"+Start parent work\0A\00"
@.str.4 = [21 x i8] c"+Finish parent work\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [64 x i8]
%4 = alloca [2 x i32]
%5 = alloca i32
%6 = alloca i8*
store i32 0, i32* %1
%7 = call i32 @time(i32* null)
store i32 %7, i32* %2
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = call i32 (...) @fork()
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i32 @close(i32 %16)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 64)
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %40
25: ; preds = %0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @localtime(i32* %2)
%28 = call i8* @asctime(i32 %27)
store i8* %28, i8** %6
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%33 = load i32, i32* %32
%34 = load i8*, i8** %6
%35 = load i8*, i8** %6
%36 = call i64 @strlen(i8* %35)
%37 = add nsw i64 %36, 1
%38 = call i32 @write(i32 %33, i8* %34, i64 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %40
40: ; preds = %25, %13
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"Received time: %s\00"
@str = [19 x i8] c"+Start parent work\00"
@str.5 = [20 x i8] c"+Finish parent work\00"
@str.6 = [18 x i8] c"+Start child work\00"
@str.7 = [19 x i8] c"+Finish child work\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca [2 x i32]
%4 = bitcast i32* %1 to i8*
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %1
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%7 = bitcast [2 x i32]* %3 to i8*
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = call i32 (...) @fork()
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 @close(i32 %15)
%17 = load i32, i32* %8
%18 = call i32 @read(i32 %17, i8* %6, i32 64)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %31
20: ; preds = %0
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%22 = call i32 @localtime(i32* %1)
%23 = call i8* @asctime(i32 %22)
%24 = load i32, i32* %8
%25 = call i32 @close(i32 %24)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%27 = load i32, i32* %26
%28 = call i64 @strlen(i8* dereferenceable(1) %23)
%29 = add nsw i64 %28, 1
%30 = call i32 @write(i32 %27, i8* %23, i64 %29)
br label %31
31: ; preds = %20, %12
%32 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0), %20 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0), %12 ]
%33 = call i32 @puts(i8* dereferenceable(1) %32)
ret i32 0
}