#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 */
int /*<<< orphan*/ SIGINT;
scalar_t__ fdevent_waitpid(scalar_t__, int /*<<< orphan*/ *, int);
char *getenv(char *);
int /*<<< orphan*/ kill(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ strtol(char const *const, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ unsetenv(char *);
__attribute__((__cold__)) void server_graceful_signal_prev_generation(void) {
  const char *const prev_gen = getenv("LIGHTTPD_PREV_GEN");
  if (NULL == prev_gen)
    return;
  pid_t pid = (pid_t)strtol(prev_gen, NULL, 10);
  unsetenv("LIGHTTPD_PREV_GEN");
  if (pid <= 0)
    return;
  if (pid == fdevent_waitpid(pid, NULL, 1))
    return;
  kill(pid, SIGINT);
}


x86 assembly (clang, -O0):
<server_graceful_signal_prev_generation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    1179 <server_graceful_signal_prev_generation+0x29>
jmp    11ee <server_graceful_signal_prev_generation+0x9e>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
cltq
mov    %rax,-0x10(%rbp)
lea    0xe68(%rip),%rdi
call   1070 <unsetenv@plt>
cmpq   $0x0,-0x10(%rbp)
jg     11ad <server_graceful_signal_prev_generation+0x5d>
jmp    11ee <server_graceful_signal_prev_generation+0x9e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x1,%edx
call   1040 <fdevent_waitpid@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
jne    11dc <server_graceful_signal_prev_generation+0x8c>
jmp    11ee <server_graceful_signal_prev_generation+0x9e>
mov    -0x10(%rbp),%rdi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_graceful_signal_prev_generation>:
push   %rbx
lea    0xf68(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     10da <server_graceful_signal_prev_generation+0x4a>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%ebx
lea    0xf46(%rip),%rdi
call   1070 <unsetenv@plt>
test   %ebx,%ebx
jle    10da <server_graceful_signal_prev_generation+0x4a>
movslq %ebx,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1040 <fdevent_waitpid@plt>
cmp    %rbx,%rax
jne    10dc <server_graceful_signal_prev_generation+0x4c>
pop    %rbx
ret
mov    0x2f05(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
pop    %rbx
jmp    1060 <kill@plt>
xchg   %ax,%ax

LLVM IR (-O0):
@.str = [18 x i8] c"LIGHTTPD_PREV_GEN\00"
@SIGINT = global i32 0
define void @server_graceful_signal_prev_generation() {
%1 = alloca i8*
%2 = alloca i64
%3 = call i8* @getenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = icmp eq i8* null, %4
br i1 %5, label %6, label %7
6: ; preds = %0
br label %25
7: ; preds = %0
%8 = load i8*, i8** %1
%9 = call i32 @strtol(i8* %8, i32* null, i32 10)
%10 = sext i32 %9 to i64
store i64 %10, i64* %2
%11 = call i32 @unsetenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = load i64, i64* %2
%13 = icmp sle i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %7
br label %25
15: ; preds = %7
%16 = load i64, i64* %2
%17 = load i64, i64* %2
%18 = call i64 @fdevent_waitpid(i64 %17, i32* null, i32 1)
%19 = icmp eq i64 %16, %18
br i1 %19, label %20, label %21
20: ; preds = %15
br label %25
21: ; preds = %15
%22 = load i64, i64* %2
%23 = load i32, i32* @SIGINT
%24 = call i32 @kill(i64 %22, i32 %23)
br label %25
25: ; preds = %21, %20, %14, %6
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"LIGHTTPD_PREV_GEN\00"
@SIGINT = global i32 0
define void @server_graceful_signal_prev_generation() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %14, label %3
3: ; preds = %0
%4 = tail call i32 @strtol(i8* nocapture %1, i32* null, i32 10)
%5 = sext i32 %4 to i64
%6 = tail call i32 @unsetenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = icmp slt i32 %4, 1
br i1 %7, label %14, label %8
8: ; preds = %3
%9 = tail call i64 @fdevent_waitpid(i64 %5, i32* null, i32 1)
%10 = icmp eq i64 %9, %5
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @SIGINT
%13 = tail call i32 @kill(i64 %5, i32 %12)
br label %14
14: ; preds = %11, %3, %8, %0
ret void
}