#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*/ getjob_fromserver(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int waitpid(scalar_t__, int /*<<< orphan*/ *, int /*<<< orphan*/);
void pid_listen(char *ip) {
  pid_t pid;
rebootchild:
  if ((pid = fork()) == 0) {
    getjob_fromserver(ip);
  } 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    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    117f <pid_listen+0x2f>
mov    -0x8(%rbp),%rdi
call   1030 <getjob_fromserver@plt>
jmp    119b <pid_listen+0x4b>
cmpq   $0x0,-0x10(%rbp)
jge    1196 <pid_listen+0x46>
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
jmp    119b <pid_listen+0x4b>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11d1 <pid_listen+0x81>
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
jmp    11e5 <pid_listen+0x95>
cmpl   $0x0,-0x14(%rbp)
jle    11e0 <pid_listen+0x90>
jmp    115c <pid_listen+0xc>
jmp    11e5 <pid_listen+0x95>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pid_listen>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
lea    0xeaa(%rip),%r14
nop
xor    %eax,%eax
call   1070 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1180 <pid_listen+0x30>
jns    1188 <pid_listen+0x38>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1188 <pid_listen+0x38>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <getjob_fromserver@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <waitpid@plt>
test   %eax,%eax
js     11aa <pid_listen+0x5a>
jne    1160 <pid_listen+0x10>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe4f(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
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(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i8* %0, i8** %2
br label %5
5: ; preds = %27, %1
%6 = call i64 (...) @fork()
store i64 %6, i64* %3
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i8*, i8** %2
%10 = call i32 @getjob_fromserver(i8* %9)
br label %17
11: ; preds = %5
%12 = load i64, i64* %3
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
br label %17
17: ; preds = %16, %8
%18 = call i32 @sleep(i32 1)
%19 = load i64, i64* %3
%20 = call i32 @waitpid(i64 %19, i32* null, i32 0)
store i32 %20, i32* %4
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %29
24: ; preds = %17
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %24
br label %5
28: ; preds = %24
br label %29
29: ; preds = %28, %22
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(i8* %0) {
br label %2
2: ; preds = %17, %1
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @getjob_fromserver(i8* %0)
br label %11
7: ; preds = %2
%8 = icmp slt i64 %3, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.2, i64 0, i64 0))
br label %11
11: ; preds = %7, %9, %5
%12 = tail call i32 @sleep(i32 1)
%13 = tail call i32 @waitpid(i64 %3, i32* null, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %19
17: ; preds = %11
%18 = icmp eq i32 %13, 0
br i1 %18, label %19, label %2
19: ; preds = %17, %15
ret void
}