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

/* Variables and functions */
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int getppid();
scalar_t__ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ test_msg(char *, char *, int, int /*<<< orphan*/);
void test_daemon() {
  pid_t ppid;
  ppid = getppid();
  if (ppid <= 1) {
    test_msg("ERR: %s:%d: "
             "Test orphaned\n"
             " (errno = %d)\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/OSLL/pmover/refs/heads/master/test/"
             "zdtm/lib/test.c",
             318, errno);
    goto out;
  }
  if (kill(ppid, SIGTERM))
    goto out;
  return;
out:
  kill(0, SIGKILL);
  exit(1);
}


x86 assembly (clang, -O0):
<test_daemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jg     1182 <test_daemon+0x42>
mov    0x2e75(%rip),%rax
mov    (%rax),%ecx
lea    0xe94(%rip),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x13e,%edx
call   1030 <test_msg@plt>
jmp    11a8 <test_daemon+0x68>
mov    -0x4(%rbp),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
cmp    $0x0,%rax
je     11a2 <test_daemon+0x62>
jmp    11a8 <test_daemon+0x68>
add    $0x10,%rsp
pop    %rbp
ret
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1040 <kill@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<test_daemon>:
push   %rax
xor    %eax,%eax
call   1050 <getppid@plt>
cmp    $0x1,%eax
jle    1164 <test_daemon+0x24>
mov    0x2e94(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1040 <kill@plt>
test   %rax,%rax
jne    1185 <test_daemon+0x45>
pop    %rax
ret
mov    0x2e6d(%rip),%rax
mov    (%rax),%ecx
lea    0xe8c(%rip),%rdi
lea    0xeae(%rip),%rsi
mov    $0x13e,%edx
call   1030 <test_msg@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1040 <kill@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"ERR: %s:%d: Test orphaned\0A (errno = %d)\0A\00"
@.str.1 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OSLL/pmover/refs/heads/master/test/zdtm/lib/test.c\00"
@errno = global i32 0
@SIGTERM = global i32 0
@SIGKILL = global i32 0
define void @test_daemon() {
%1 = alloca i32
%2 = call i32 (...) @getppid()
store i32 %2, i32* %1
%3 = load i32, i32* %1
%4 = icmp sle i32 %3, 1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @errno
%7 = call i32 @test_msg(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 318, i32 %6)
br label %15
8: ; preds = %0
%9 = load i32, i32* %1
%10 = load i32, i32* @SIGTERM
%11 = call i64 @kill(i32 %9, i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %8
br label %15
14: ; preds = %8
ret void
15: ; preds = %13, %5
%16 = load i32, i32* @SIGKILL
%17 = call i64 @kill(i32 0, i32 %16)
%18 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [41 x i8] c"ERR: %s:%d: Test orphaned\0A (errno = %d)\0A\00"
@.str.1 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OSLL/pmover/refs/heads/master/test/zdtm/lib/test.c\00"
@errno = global i32 0
@SIGTERM = global i32 0
@SIGKILL = global i32 0
define void @test_daemon() {
%1 = tail call i32 (...) @getppid()
%2 = icmp slt i32 %1, 2
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @errno
%5 = tail call i32 @test_msg(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 318, i32 %4)
br label %11
6: ; preds = %0
%7 = load i32, i32* @SIGTERM
%8 = tail call i64 @kill(i32 %1, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %6
ret void
11: ; preds = %6, %3
%12 = load i32, i32* @SIGKILL
%13 = tail call i64 @kill(i32 0, i32 %12)
%14 = tail call i32 @exit(i32 1)
unreachable
}