#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__ fork();
int /*<<< orphan*/ node_listensocket_fromserver();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int waitpid(scalar_t__, int /*<<< orphan*/ *, int /*<<< orphan*/);
void pid_listen() {
  pid_t pid;
rebootchild:
  if ((pid = fork()) == 0) {
    node_listensocket_fromserver();
  } else if (pid < 0) {
    printf("pid error ....\n");
  }
  sleep(1);
  int pidstat;
  if ((pidstat = waitpid(pid, NULL, 0)) < 0)
    printf("error...\n");
  else if (pidstat > 0) {
    goto rebootchild;
  }
}


x86 assembly (clang, -O0):
<pid_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1179 <pid_listen+0x29>
mov    $0x0,%al
call   1050 <node_listensocket_fromserver@plt>
jmp    1195 <pid_listen+0x45>
cmpq   $0x0,-0x8(%rbp)
jge    1190 <pid_listen+0x40>
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
jmp    1195 <pid_listen+0x45>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11cb <pid_listen+0x7b>
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
jmp    11df <pid_listen+0x8f>
cmpl   $0x0,-0xc(%rbp)
jle    11da <pid_listen+0x8a>
jmp    1158 <pid_listen+0x8>
jmp    11df <pid_listen+0x8f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pid_listen>:
push   %r14
push   %rbx
push   %rax
lea    0xeae(%rip),%r14
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1180 <pid_listen+0x30>
jns    1187 <pid_listen+0x37>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1187 <pid_listen+0x37>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <node_listensocket_fromserver@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
test   %eax,%eax
js     11ab <pid_listen+0x5b>
jne    1160 <pid_listen+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4e(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"pid error ....\0A\00"
@.str.1 = [10 x i8] c"error...\0A\00"
define void @pid_listen() {
%1 = alloca i64
%2 = alloca i32
br label %3
3: ; preds = %24, %0
%4 = call i64 (...) @fork()
store i64 %4, i64* %1
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = call i32 (...) @node_listensocket_fromserver()
br label %14
8: ; preds = %3
%9 = load i64, i64* %1
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
br label %14
14: ; preds = %13, %6
%15 = call i32 @sleep(i32 1)
%16 = load i64, i64* %1
%17 = call i32 @waitpid(i64 %16, i32* null, i32 0)
store i32 %17, i32* %2
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %26
21: ; preds = %14
%22 = load i32, i32* %2
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
br label %3
25: ; preds = %21
br label %26
26: ; preds = %25, %19
ret void
}

LLVM IR (-O2):
@str = [9 x i8] c"error...\00"
@str.2 = [15 x i8] c"pid error ....\00"
define void @pid_listen() {
br label %1
1: ; preds = %16, %0
%2 = tail call i64 (...) @fork()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (...) @node_listensocket_fromserver()
br label %10
6: ; preds = %1
%7 = icmp slt i64 %2, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.2, i64 0, i64 0))
br label %10
10: ; preds = %6, %8, %4
%11 = tail call i32 @sleep(i32 1)
%12 = tail call i32 @waitpid(i64 %2, i32* null, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %18
16: ; preds = %10
%17 = icmp eq i32 %12, 0
br i1 %17, label %18, label %1
18: ; preds = %16, %14
ret void
}