#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;

/* Variables and functions */
int kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int wait_for_termination(pid_t pid, unsigned seconds) {
  int rc;
  while (0 != (rc = kill(pid, 0))) {
    sleep(1);
    if (seconds != -1 && 0 == seconds--) {
      break;
    }
  }
  if (0 == rc) {
    rc = -1;
  } else {
    rc = 0;
  }
  return rc;
}


x86 assembly (clang, -O0):
<wait_for_termination>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1030 <kill@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
je     117a <wait_for_termination+0x5a>
mov    $0x1,%edi
call   1040 <sleep@plt>
cmpl   $0xffffffff,-0x8(%rbp)
je     1175 <wait_for_termination+0x55>
mov    -0x8(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jne    1175 <wait_for_termination+0x55>
jmp    117a <wait_for_termination+0x5a>
jmp    112e <wait_for_termination+0xe>
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jne    1191 <wait_for_termination+0x71>
movl   $0xffffffff,-0xc(%rbp)
jmp    1198 <wait_for_termination+0x78>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_termination>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%r14d
xor    %esi,%esi
call   1030 <kill@plt>
mov    $0xffffffff,%r15d
jmp    114c <wait_for_termination+0x2c>
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
xor    %esi,%esi
call   1030 <kill@plt>
mov    %ebx,%ebp
test   %eax,%eax
je     116e <wait_for_termination+0x4e>
mov    $0x1,%edi
call   1040 <sleep@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%ebp
je     1140 <wait_for_termination+0x20>
sub    $0x1,%ebp
mov    %ebp,%ebx
jae    1140 <wait_for_termination+0x20>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @wait_for_termination(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %6
6: ; preds = %19, %2
%7 = load i32, i32* %3
%8 = call i32 @kill(i32 %7, i32 0)
store i32 %8, i32* %5
%9 = icmp ne i32 0, %8
br i1 %9, label %10, label %20
10: ; preds = %6
%11 = call i32 @sleep(i32 1)
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i32, i32* %4
%16 = add i32 %15, -1
store i32 %16, i32* %4
%17 = icmp eq i32 0, %15
br i1 %17, label %18, label %19
18: ; preds = %14
br label %20
19: ; preds = %14, %10
br label %6
20: ; preds = %18, %6
%21 = load i32, i32* %5
%22 = icmp eq i32 0, %21
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 -1, i32* %5
br label %25
24: ; preds = %20
store i32 0, i32* %5
br label %25
25: ; preds = %24, %23
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
define i32 @wait_for_termination(i32 %0, i32 %1) {
%3 = tail call i32 @kill(i32 %0, i32 0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %2, %12
%6 = phi i32 [ %13, %12 ], [ %1, %2 ]
%7 = tail call i32 @sleep(i32 1)
%8 = icmp eq i32 %6, -1
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = add i32 %6, -1
%11 = icmp eq i32 %6, 0
br i1 %11, label %16, label %12
12: ; preds = %9, %5
%13 = phi i32 [ %10, %9 ], [ -1, %5 ]
%14 = tail call i32 @kill(i32 %0, i32 0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %5
16: ; preds = %12, %9, %2
%17 = phi i32 [ -1, %2 ], [ 0, %9 ], [ -1, %12 ]
ret i32 %17
}