#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 */
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, int);
int *sbrk(int);
int /*<<< orphan*/ sleep(int);
int main() {
  int *a = sbrk(4);
  *a = 40;
  if (fork()) {
    printf("parent:%d\n", *a);
    *a = 90;
  } else {
    printf("child:%d\n", *a);
    sleep(2);
    printf("---child:%d\n", *a);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1040 <sbrk@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x28,(%rax)
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
je     1199 <main+0x59>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movl   $0x5a,(%rax)
jmp    11c7 <main+0x87>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1050 <sleep@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x4,%edi
call   1040 <sbrk@plt>
mov    %rax,%rbx
movl   $0x28,(%rax)
xor    %eax,%eax
call   1060 <fork@plt>
mov    (%rbx),%esi
test   %rax,%rax
je     1176 <main+0x36>
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
movl   $0x5a,(%rbx)
jmp    119a <main+0x5a>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1050 <sleep@plt>
mov    (%rbx),%esi
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"parent:%d\0A\00"
@.str.1 = [10 x i8] c"child:%d\0A\00"
@.str.2 = [13 x i8] c"---child:%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32* @sbrk(i32 4)
store i32* %3, i32** %2
%4 = load i32*, i32** %2
store i32 40, i32* %4
%5 = call i64 (...) @fork()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = load i32, i32* %8
%10 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32*, i32** %2
store i32 90, i32* %11
br label %20
12: ; preds = %0
%13 = load i32*, i32** %2
%14 = load i32, i32* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 @sleep(i32 2)
%17 = load i32*, i32** %2
%18 = load i32, i32* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %12, %7
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"parent:%d\0A\00"
@.str.1 = [10 x i8] c"child:%d\0A\00"
@.str.2 = [13 x i8] c"---child:%d\0A\00"
define i32 @main() {
%1 = tail call i32* @sbrk(i32 4)
store i32 40, i32* %1
%2 = tail call i64 (...) @fork()
%3 = icmp eq i64 %2, 0
%4 = load i32, i32* %1
br i1 %3, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 90, i32* %1
br label %12
7: ; preds = %0
%8 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%9 = tail call i32 @sleep(i32 2)
%10 = load i32, i32* %1
%11 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %7, %5
ret i32 0
}