#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 */

/* Variables and functions */
int /*<<< orphan*/ SIGCONT;
int /*<<< orphan*/ SIGSEGV;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ SIG_IGN;
int WNOHANG;
int __WALL;
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ os_kill_ptraced_process(int, int /*<<< orphan*/);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ uml_abort();
int waitpid(int, int /*<<< orphan*/ *, int);
void os_dump_core(void) {
  int pid;
  signal(SIGSEGV, SIG_DFL);
  signal(SIGTERM, SIG_IGN);
  kill(0, SIGTERM);
  kill(0, SIGCONT);
  while ((pid = waitpid(-1, NULL, WNOHANG | __WALL)) > 0)
    os_kill_ptraced_process(pid, 0);
  uml_abort();
}


x86 assembly (clang, -O0):
<os_dump_core>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1050 <kill@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1050 <kill@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
mov    0x2e02(%rip),%rax
or     (%rax),%edx
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <waitpid@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jle    11e1 <os_dump_core+0x91>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1030 <os_kill_ptraced_process@plt>
jmp    11a6 <os_dump_core+0x56>
mov    $0x0,%al
call   1060 <uml_abort@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_dump_core>:
push   %r14
push   %rbx
push   %rax
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2e66(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    (%rbx),%esi
xor    %edi,%edi
call   1050 <kill@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1050 <kill@plt>
mov    0x2e2e(%rip),%r14
mov    0x2e0f(%rip),%rbx
nopl   0x0(%rax)
mov    (%rbx),%edx
or     (%r14),%edx
mov    $0xffffffff,%edi
xor    %esi,%esi
call   1070 <waitpid@plt>
test   %eax,%eax
jle    11d0 <os_dump_core+0x80>
mov    %eax,%edi
xor    %esi,%esi
call   1030 <os_kill_ptraced_process@plt>
jmp    11b0 <os_dump_core+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <uml_abort@plt>

LLVM IR (-O0):
@SIGSEGV = global i32 0
@SIG_DFL = global i32 0
@SIGTERM = global i32 0
@SIG_IGN = global i32 0
@SIGCONT = global i32 0
@WNOHANG = global i32 0
@__WALL = global i32 0
define void @os_dump_core() {
%1 = alloca i32
%2 = load i32, i32* @SIGSEGV
%3 = load i32, i32* @SIG_DFL
%4 = call i32 @signal(i32 %2, i32 %3)
%5 = load i32, i32* @SIGTERM
%6 = load i32, i32* @SIG_IGN
%7 = call i32 @signal(i32 %5, i32 %6)
%8 = load i32, i32* @SIGTERM
%9 = call i32 @kill(i32 0, i32 %8)
%10 = load i32, i32* @SIGCONT
%11 = call i32 @kill(i32 0, i32 %10)
br label %12
12: ; preds = %18, %0
%13 = load i32, i32* @WNOHANG
%14 = load i32, i32* @__WALL
%15 = or i32 %13, %14
%16 = call i32 @waitpid(i32 -1, i32* null, i32 %15)
store i32 %16, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* %1
%20 = call i32 @os_kill_ptraced_process(i32 %19, i32 0)
br label %12
21: ; preds = %12
%22 = call i32 (...) @uml_abort()
ret void
}

LLVM IR (-O2):
@SIGSEGV = global i32 0
@SIG_DFL = global i32 0
@SIGTERM = global i32 0
@SIG_IGN = global i32 0
@SIGCONT = global i32 0
@WNOHANG = global i32 0
@__WALL = global i32 0
define void @os_dump_core() {
%1 = load i32, i32* @SIGSEGV
%2 = load i32, i32* @SIG_DFL
%3 = tail call i32 @signal(i32 %1, i32 %2)
%4 = load i32, i32* @SIGTERM
%5 = load i32, i32* @SIG_IGN
%6 = tail call i32 @signal(i32 %4, i32 %5)
%7 = load i32, i32* @SIGTERM
%8 = tail call i32 @kill(i32 0, i32 %7)
%9 = load i32, i32* @SIGCONT
%10 = tail call i32 @kill(i32 0, i32 %9)
%11 = load i32, i32* @WNOHANG
%12 = load i32, i32* @__WALL
%13 = or i32 %12, %11
%14 = tail call i32 @waitpid(i32 -1, i32* null, i32 %13)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %0, %16
%17 = phi i32 [ %22, %16 ], [ %14, %0 ]
%18 = tail call i32 @os_kill_ptraced_process(i32 %17, i32 0)
%19 = load i32, i32* @WNOHANG
%20 = load i32, i32* @__WALL
%21 = or i32 %20, %19
%22 = tail call i32 @waitpid(i32 -1, i32* null, i32 %21)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %16, label %24
24: ; preds = %16, %0
%25 = tail call i32 (...) @uml_abort()
ret void
}