#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 int /*<<< orphan*/ pid_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ ESRCH;
int /*<<< orphan*/ atoi(char *);
scalar_t__ errno;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdin;
int main() {
  char buf[32];
  pid_t pid;
  fgets(buf, sizeof(buf), stdin);
  pid = atoi(buf);
  for (;;) {
    sleep(5);
    if (kill(pid, 0) < 0 && errno == ESRCH)
      return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1030 <fgets@plt>
lea    -0x30(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    $0x5,%edi
call   1060 <sleep@plt>
mov    -0x34(%rbp),%edi
xor    %esi,%esi
call   1040 <kill@plt>
cmp    $0x0,%rax
jge    11b2 <main+0x72>
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%rax
jne    11b2 <main+0x72>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret
jmp    1172 <main+0x32>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e98(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <fgets@plt>
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
mov    0x2e65(%rip),%r14
mov    0x2e4e(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    $0x5,%edi
call   1060 <sleep@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <kill@plt>
test   %rax,%rax
jns    1180 <main+0x40>
mov    (%r14),%rax
cmp    (%r15),%rax
jne    1180 <main+0x40>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@errno = global i64 0
@ESRCH = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %4, i32 32, i32 %5)
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%8 = call i32 @atoi(i8* %7)
store i32 %8, i32* %3
br label %9
9: ; preds = %19, %0
%10 = call i32 @sleep(i32 5)
%11 = load i32, i32* %3
%12 = call i64 @kill(i32 %11, i32 0)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i64, i64* @errno
%16 = load i64, i64* @ESRCH
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
ret i32 0
19: ; preds = %14, %9
br label %9
}

LLVM IR (-O2):
@stdin = global i32 0
@errno = global i64 0
@ESRCH = global i64 0
define i32 @main() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @fgets(i8* %2, i32 32, i32 %3)
%5 = call i32 @atoi(i8* %2)
br label %6
6: ; preds = %14, %0
%7 = call i32 @sleep(i32 5)
%8 = call i64 @kill(i32 %5, i32 0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i64, i64* @errno
%12 = load i64, i64* @ESRCH
%13 = icmp eq i64 %11, %12
br i1 %13, label %15, label %14
14: ; preds = %10, %6
br label %6
15: ; preds = %10
ret i32 0
}