#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ TestShow(int *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
void main() {
  int x = 0;
  static int y = 0;
  pid_t pd = fork();
  if (pd > 0) {
    sleep(2);
    printf("parent:local value ");
    TestShow(&x);
    printf("static value ");
    TestShow(&y);
    printf("x:%d  y:%d\n", x, y);
  } else {
    printf("child:local value ");
    TestShow(&x);
    printf("static value ");
    TestShow(&y);
    printf("x:%d  y:%d\n", x, y);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    11cc <main+0x7c>
mov    $0x2,%edi
call   1060 <sleep@plt>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x4(%rbp),%rdi
call   1040 <TestShow@plt>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0x2ea1(%rip),%rdi
call   1040 <TestShow@plt>
mov    -0x4(%rbp),%esi
mov    0x2e93(%rip),%edx
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1214 <main+0xc4>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x4(%rbp),%rdi
call   1040 <TestShow@plt>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0x2e54(%rip),%rdi
call   1040 <TestShow@plt>
mov    -0x4(%rbp),%esi
mov    0x2e46(%rip),%edx
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jle    1178 <main+0x28>
mov    $0x2,%edi
call   1060 <sleep@plt>
lea    0xe8a(%rip),%rdi
jmp    117f <main+0x2f>
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x4(%rsp),%rdi
call   1040 <TestShow@plt>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x2ea7(%rip),%rdi
call   1040 <TestShow@plt>
mov    0x4(%rsp),%esi
mov    0x2e98(%rip),%edx
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@main.y = internal global i32 0
@.str = [20 x i8] c"parent:local value \00"
@.str.1 = [14 x i8] c"static value \00"
@.str.2 = [12 x i8] c"x:%d y:%d\0A\00"
@.str.3 = [19 x i8] c"child:local value \00"
define void @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %0
%7 = call i32 @sleep(i32 2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @TestShow(i32* %1)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @TestShow(i32* @main.y)
%12 = load i32, i32* %1
%13 = load i32, i32* @main.y
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %13)
br label %23
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @TestShow(i32* %1)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @TestShow(i32* @main.y)
%20 = load i32, i32* %1
%21 = load i32, i32* @main.y
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %21)
br label %23
23: ; preds = %15, %6
%24 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@main.y = internal global i32 0
@.str = [20 x i8] c"parent:local value \00"
@.str.1 = [14 x i8] c"static value \00"
@.str.2 = [12 x i8] c"x:%d y:%d\0A\00"
@.str.3 = [19 x i8] c"child:local value \00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i64 (...) @fork()
%4 = icmp sgt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @sleep(i32 2)
br label %7
7: ; preds = %0, %5
%8 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), %0 ]
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %8)
%10 = call i32 @TestShow(i32* %1)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @TestShow(i32* @main.y)
%13 = load i32, i32* %1
%14 = load i32, i32* @main.y
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
%16 = call i32 @exit(i32 0)
unreachable
}