#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 */
scalar_t__ WEXITSTATUS(int);
int WIFEXITED(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ wait(int *);
int main(int argc, char *argv[]) {
  pid_t pid = fork();
  if (pid == 0) {
    printf("i am CHILD ....\n");
    return -1;
  } else {
    int returnValue;
    if (wait(&returnValue) < 0)
      perror("wait() failed\n");
    printf("child proccess id is : %d\n", pid);
    printf("child proccess is die(%d) ", WIFEXITED(returnValue));
    printf("with return value %d ", (signed char)WEXITSTATUS(returnValue));
    printf("we are sorry ....\n");
  }
}


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   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a6 <main+0x46>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <main+0xb6>
lea    -0x1c(%rbp),%rdi
call   1070 <wait@plt>
cmp    $0x0,%rax
jge    11c5 <main+0x65>
lea    0xe51(%rip),%rdi
call   1050 <perror@plt>
mov    -0x18(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1060 <WIFEXITED@plt>
mov    %eax,%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
movsbl %al,%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11e5 <main+0x75>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
call   1080 <wait@plt>
test   %rax,%rax
js     11ff <main+0x8f>
lea    0xe77(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
lea    0xe76(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
movsbl %al,%esi
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
jmp    11f6 <main+0x86>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdfa(%rip),%rdi
call   1060 <perror@plt>
jmp    1191 <main+0x21>

LLVM IR (-O0):
@.str = [17 x i8] c"i am CHILD ....\0A\00"
@.str.1 = [15 x i8] c"wait() failed\0A\00"
@.str.2 = [27 x i8] c"child proccess id is : %d\0A\00"
@.str.3 = [27 x i8] c"child proccess is die(%d) \00"
@.str.4 = [22 x i8] c"with return value %d \00"
@.str.5 = [19 x i8] c"we are sorry ....\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 (...) @fork()
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
13: ; preds = %2
%14 = call i64 @wait(i32* %7)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = load i64, i64* %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %19)
%21 = load i32, i32* %7
%22 = call i32 @WIFEXITED(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %7
%25 = call i64 @WEXITSTATUS(i32 %24)
%26 = trunc i64 %25 to i8
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %11, %18
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"wait() failed\0A\00"
@.str.2 = [27 x i8] c"child proccess id is : %d\0A\00"
@.str.3 = [27 x i8] c"child proccess is die(%d) \00"
@.str.4 = [22 x i8] c"with return value %d \00"
@str = [18 x i8] c"we are sorry ....\00"
@str.6 = [16 x i8] c"i am CHILD ....\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.6, i64 0, i64 0))
br label %26
8: ; preds = %2
%9 = bitcast i32* %3 to i8*
%10 = call i64 @wait(i32* %3)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %4)
%16 = load i32, i32* %3
%17 = call i32 @WIFEXITED(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %3
%20 = call i64 @WEXITSTATUS(i32 %19)
%21 = trunc i64 %20 to i32
%22 = shl i32 %21, 24
%23 = ashr exact i32 %22, 24
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %14, %6
%27 = phi i32 [ -1, %6 ], [ 0, %14 ]
ret i32 %27
}