#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 /*<<< orphan*/ fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sleep(int);
int main() {
  puts("Hello");
  printf("world ");
  int oldpid = getpid();
  sleep(5);
  fork();
  puts("csd1208");
  int pid = getpid();
  printf("oldpid=%d, pid=%d\n", oldpid, pid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x5,%edi
call   1060 <sleep@plt>
mov    $0x0,%al
call   1070 <fork@plt>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
mov    $0x5,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
call   1070 <fork@plt>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe76(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Hello\00"
@.str.1 = [7 x i8] c"world \00"
@.str.2 = [8 x i8] c"csd1208\00"
@.str.3 = [19 x i8] c"oldpid=%d, pid=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (...) @getpid()
store i32 %6, i32* %2
%7 = call i32 @sleep(i32 5)
%8 = call i32 (...) @fork()
%9 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (...) @getpid()
store i32 %10, i32* %3
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %11, i32 %12)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"Hello\00"
@.str.1 = [7 x i8] c"world \00"
@.str.2 = [8 x i8] c"csd1208\00"
@.str.3 = [19 x i8] c"oldpid=%d, pid=%d\0A\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 @sleep(i32 5)
%5 = tail call i32 (...) @fork()
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %3, i32 %7)
ret i32 0
}