#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*/ do_task(scalar_t__);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int spid = getpid();
  pid_t p = fork();
  if (p < 0) {
    do {
      printf("[%d]--", getpid());
      printf("fork() faild");
      printf("\n");
    } while (0);
    return -1;
  }
  if (0 == p) {
    do_task(spid);
  } else {
    do_task(p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11ba <main+0x7a>
jmp    117b <main+0x3b>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <main+0xa4>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11d4 <main+0x94>
movslq -0x14(%rbp),%rdi
call   1050 <do_task@plt>
jmp    11dd <main+0x9d>
mov    -0x20(%rbp),%rdi
call   1050 <do_task@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     116d <main+0x1d>
je     11a3 <main+0x53>
mov    %rax,%rdi
jmp    11a6 <main+0x56>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe85(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
movslq %ebx,%rdi
call   1060 <do_task@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"[%d]--\00"
@.str.1 = [13 x i8] c"fork() faild\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @getpid()
store i32 %8, i32* %6
%9 = call i64 (...) @fork()
store i64 %9, i64* %7
%10 = load i64, i64* %7
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %2
br label %13
13: ; preds = %12
%14 = call i32 (...) @getpid()
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %13
store i32 -1, i32* %3
br label %30
19: ; preds = %2
%20 = load i64, i64* %7
%21 = icmp eq i64 0, %20
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = call i32 @do_task(i64 %24)
br label %29
26: ; preds = %19
%27 = load i64, i64* %7
%28 = call i32 @do_task(i64 %27)
br label %29
29: ; preds = %26, %22
store i32 0, i32* %3
br label %30
30: ; preds = %29, %18
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [7 x i8] c"[%d]--\00"
@.str.1 = [13 x i8] c"fork() faild\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getpid()
%4 = tail call i64 (...) @fork()
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @putchar(i32 10)
br label %18
11: ; preds = %2
%12 = icmp eq i64 %4, 0
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = sext i32 %3 to i64
%15 = tail call i32 @do_task(i64 %14)
br label %18
16: ; preds = %11
%17 = tail call i32 @do_task(i64 %4)
br label %18
18: ; preds = %13, %16, %6
%19 = phi i32 [ -1, %6 ], [ 0, %16 ], [ 0, %13 ]
ret i32 %19
}