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

/* Variables and functions */
int fork();
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[], char *envp[]) {
  int pid = 0;
  int *status = malloc(sizeof(int));
  char *input1 = (char *)malloc(20);
  char *input2 = (char *)malloc(20);
  pid = fork();
  if (pid) {
    printf("Parent: Enter something\n");
    waitpid(pid, status, 0);
    scanf("%s", input1);
    printf("Parent entered: %s\n", input1);
  } else {
    printf("Child: Enter something: \n");
    scanf("%s", input2);
    printf("Child entered: %s\n", input2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11f2 <main+0xa2>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x30(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1222 <main+0xd2>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xe0e(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x38(%rbp),%rsi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11ce <main+0x6e>
mov    %eax,%ebp
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
lea    0xe46(%rip),%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xe3a(%rip),%rdi
mov    %rbx,%rsi
jmp    11f3 <main+0x93>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1f(%rip),%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
lea    0xe27(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Parent: Enter something\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [20 x i8] c"Parent entered: %s\0A\00"
@.str.3 = [26 x i8] c"Child: Enter something: \0A\00"
@.str.4 = [19 x i8] c"Child entered: %s\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 0, i32* %8
%12 = call i32* @malloc(i32 4)
store i32* %12, i32** %9
%13 = call i32* @malloc(i32 20)
%14 = bitcast i32* %13 to i8*
store i8* %14, i8** %10
%15 = call i32* @malloc(i32 20)
%16 = bitcast i32* %15 to i8*
store i8* %16, i8** %11
%17 = call i32 (...) @fork()
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* %8
%23 = load i32*, i32** %9
%24 = call i32 @waitpid(i32 %22, i32* %23, i32 0)
%25 = load i8*, i8** %10
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %10
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %35
29: ; preds = %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%31 = load i8*, i8** %11
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %11
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %29, %20
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [20 x i8] c"Parent entered: %s\0A\00"
@.str.4 = [19 x i8] c"Child entered: %s\0A\00"
@str = [25 x i8] c"Child: Enter something: \00"
@str.5 = [24 x i8] c"Parent: Enter something\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = tail call i32* @malloc(i32 4)
%5 = tail call i32* @malloc(i32 20)
%6 = tail call i32* @malloc(i32 20)
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %3
%10 = bitcast i32* %5 to i8*
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
%12 = tail call i32 @waitpid(i32 %7, i32* %4, i32 0)
%13 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32* %5)
br label %20
15: ; preds = %3
%16 = bitcast i32* %6 to i8*
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32* %6)
br label %20
20: ; preds = %15, %9
ret i32 0
}