#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*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ getchar();
int getpid();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ wait(int *);
int main() {
  pid_t cPid;
  int childstatus;
  int k = 10;
  cPid = fork();
  if (cPid == 0) {
    printf(" child: My pid = %d \n", getpid());
    printf(" end of child k = %d\n", k);
    k = 44;
    printf(" end of child k = %d\n", k);
    exit(100);
  } else {
    wait(&childstatus);
    printf("parent: end of parent k = %d\n", k);
    getchar();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x18(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d0 <main+0x70>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2c,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
mov    $0x64,%edi
call   1060 <exit@plt>
lea    -0x14(%rbp),%rdi
call   1070 <wait@plt>
mov    -0x18(%rbp),%esi
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     119b <main+0x3b>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
lea    0xeaa(%rip),%rdi
mov    $0xa,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe57(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xe5f(%rip),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <printf@plt>
mov    $0x64,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c" child: My pid = %d \0A\00"
@.str.1 = [22 x i8] c" end of child k = %d\0A\00"
@.str.2 = [30 x i8] c"parent: end of parent k = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 10, i32* %4
%5 = call i64 (...) @fork()
store i64 %5, i64* %2
%6 = load i64, i64* %2
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %0
%9 = call i32 (...) @getpid()
%10 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %4
%12 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %11)
store i32 44, i32* %4
%13 = load i32, i32* %4
%14 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 100)
unreachable
16: ; preds = %0
%17 = call i32 @wait(i32* %3)
%18 = load i32, i32* %4
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = call i32 (...) @getchar()
br label %21
21: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c" child: My pid = %d \0A\00"
@.str.1 = [22 x i8] c" end of child k = %d\0A\00"
@.str.2 = [30 x i8] c"parent: end of parent k = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 10)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 44)
%10 = tail call i32 @exit(i32 100)
unreachable
11: ; preds = %0
%12 = call i32 @wait(i32* %1)
%13 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 10)
%14 = call i32 (...) @getchar()
ret i32 0
}