#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 */
struct tm {
  int /*<<< orphan*/ member_0;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  struct tm stTime = {0};
  int i;
  pid_t pid;
  pid = fork();
  if (0 > pid)
    printf("fork error!\r\n");
  else if (0 == pid)
    printf("child process, id=%d!\r\n", getpid());
  else
    printf("parent process, pid=%d id=%d!\r\n", pid, getpid());
  for (i = 0; i < 5; i++) {
    printf("pid=%d, hello word:%d \n", getpid(), i);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jle    1189 <main+0x49>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d9 <main+0x99>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11b1 <main+0x71>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d4 <main+0x94>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d9 <main+0x99>
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    1212 <main+0xd2>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0xc(%rbp),%edx
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e0 <main+0xa0>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
js     1171 <main+0x31>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
test   %rbx,%rbx
je     117f <main+0x3f>
lea    0xeb5(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    118f <main+0x4f>
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
jmp    118f <main+0x4f>
lea    0xe7a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe9b(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [14 x i8] c"fork error!\0D\0A\00"
@.str.1 = [24 x i8] c"child process, id=%d!\0D\0A\00"
@.str.2 = [32 x i8] c"parent process, pid=%d id=%d!\0D\0A\00"
@.str.3 = [24 x i8] c"pid=%d, hello word:%d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.tm
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
%5 = bitcast %struct.tm* %2 to i8*
%6 = call i64 (...) @fork()
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp sgt i64 0, %7
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %22
11: ; preds = %0
%12 = load i64, i64* %4
%13 = icmp eq i64 0, %12
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 (...) @getpid()
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %21
17: ; preds = %11
%18 = load i64, i64* %4
%19 = call i32 (...) @getpid()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i64 %18, i32 %19)
br label %21
21: ; preds = %17, %14
br label %22
22: ; preds = %21, %9
store i32 0, i32* %3
br label %23
23: ; preds = %30, %22
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 5
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = call i32 (...) @getpid()
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %28)
br label %30
30: ; preds = %26
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %23
33: ; preds = %23
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str.1 = [24 x i8] c"child process, id=%d!\0D\0A\00"
@.str.2 = [32 x i8] c"parent process, pid=%d id=%d!\0D\0A\00"
@.str.3 = [24 x i8] c"pid=%d, hello word:%d \0A\00"
@str = [13 x i8] c"fork error!\0D\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %12
5: ; preds = %0
%6 = icmp eq i64 %1, 0
%7 = tail call i32 (...) @getpid()
br i1 %6, label %8, label %10
8: ; preds = %5
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %12
10: ; preds = %5
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i64 %1, i32 %7)
br label %12
12: ; preds = %8, %10, %3
%13 = tail call i32 (...) @getpid()
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 0)
%15 = tail call i32 (...) @getpid()
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %15, i32 1)
%17 = tail call i32 (...) @getpid()
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 2)
%19 = tail call i32 (...) @getpid()
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 3)
%21 = tail call i32 (...) @getpid()
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 4)
ret i32 0
}