#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 */
struct sigaction {
  scalar_t__ sa_handler;
};
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ SIGABRT;
scalar_t__ SIG_DFL;
scalar_t__ SIG_IGN;
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sigaction(int /*<<< orphan*/, struct sigaction *,
                             struct sigaction *);
int /*<<< orphan*/ sigdelset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
void abort_normal(void) {
  sigset_t mask;
  struct sigaction action;
  sigaction(SIGABRT, NULL, &action);
  if (action.sa_handler == SIG_IGN) {
    action.sa_handler = SIG_DFL;
    sigaction(SIGABRT, &action, NULL);
  }
  if (action.sa_handler == SIG_DFL) {
    fflush(NULL);
  }
  sigfillset(&mask);
  sigdelset(&mask, SIGABRT);
  sigprocmask(SIG_SETMASK, &mask, NULL);
  kill(getpid(), SIGABRT);
  fflush(NULL);
  action.sa_handler = SIG_DFL;
  sigaction(SIGABRT, &action, NULL);
  sigprocmask(SIG_SETMASK, &mask, NULL);
  kill(getpid(), SIGABRT);
  exit(1);
}


x86 assembly (clang, -O0):
<abort_normal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x10(%rbp),%rdx
call   1040 <sigaction@plt>
mov    -0x10(%rbp),%rax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%rax
jne    11d6 <abort_normal+0x56>
mov    0x2e17(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigaction@plt>
mov    -0x10(%rbp),%rax
mov    0x2def(%rip),%rcx
cmp    (%rcx),%rax
jne    11f3 <abort_normal+0x73>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
lea    -0x4(%rbp),%rdi
call   1060 <sigfillset@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1090 <sigdelset@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    -0x4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%edi
mov    0x2d94(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigaction@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    -0x4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%edi
mov    0x2d3a(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<abort_normal>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e36(%rip),%r14
mov    (%r14),%edi
lea    0x8(%rsp),%rdx
xor    %esi,%esi
call   1040 <sigaction@plt>
mov    0x8(%rsp),%rax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
jne    11d5 <abort_normal+0x55>
mov    0x2e17(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <sigaction@plt>
mov    0x8(%rsp),%rax
mov    0x2df4(%rip),%r15
cmp    (%r15),%rax
jne    11e8 <abort_normal+0x68>
xor    %edi,%edi
call   1080 <fflush@plt>
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sigfillset@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1090 <sigdelset@plt>
mov    0x2de1(%rip),%r12
mov    (%r12),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    (%r14),%esi
mov    %eax,%edi
call   1070 <kill@plt>
xor    %edi,%edi
call   1080 <fflush@plt>
mov    (%r15),%rax
mov    %rax,0x8(%rsp)
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <sigaction@plt>
mov    (%r12),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    (%r14),%esi
mov    %eax,%edi
call   1070 <kill@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sigaction = type { i64 }
@SIGABRT = global i32 0
@SIG_IGN = global i64 0
@SIG_DFL = global i64 0
@SIG_SETMASK = global i32 0
define void @abort_normal() {
%1 = alloca i32
%2 = alloca %struct.sigaction
%3 = load i32, i32* @SIGABRT
%4 = call i32 @sigaction(i32 %3, %struct.sigaction* null, %struct.sigaction* %2)
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 0
%6 = load i64, i64* %5
%7 = load i64, i64* @SIG_IGN
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i64, i64* @SIG_DFL
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 0
store i64 %10, i64* %11
%12 = load i32, i32* @SIGABRT
%13 = call i32 @sigaction(i32 %12, %struct.sigaction* %2, %struct.sigaction* null)
br label %14
14: ; preds = %9, %0
%15 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @SIG_DFL
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @fflush(i32* null)
br label %21
21: ; preds = %19, %14
%22 = call i32 @sigfillset(i32* %1)
%23 = load i32, i32* @SIGABRT
%24 = call i32 @sigdelset(i32* %1, i32 %23)
%25 = load i32, i32* @SIG_SETMASK
%26 = call i32 @sigprocmask(i32 %25, i32* %1, i32* null)
%27 = call i32 (...) @getpid()
%28 = load i32, i32* @SIGABRT
%29 = call i32 @kill(i32 %27, i32 %28)
%30 = call i32 @fflush(i32* null)
%31 = load i64, i64* @SIG_DFL
%32 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 0
store i64 %31, i64* %32
%33 = load i32, i32* @SIGABRT
%34 = call i32 @sigaction(i32 %33, %struct.sigaction* %2, %struct.sigaction* null)
%35 = load i32, i32* @SIG_SETMASK
%36 = call i32 @sigprocmask(i32 %35, i32* %1, i32* null)
%37 = call i32 (...) @getpid()
%38 = load i32, i32* @SIGABRT
%39 = call i32 @kill(i32 %37, i32 %38)
%40 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
%struct.sigaction = type { i64 }
@SIGABRT = global i32 0
@SIG_IGN = global i64 0
@SIG_DFL = global i64 0
@SIG_SETMASK = global i32 0
define void @abort_normal() {
%1 = alloca i32
%2 = alloca %struct.sigaction
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.sigaction* %2 to i8*
%5 = load i32, i32* @SIGABRT
%6 = call i32 @sigaction(i32 %5, %struct.sigaction* null, %struct.sigaction* %2)
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 0
%8 = load i64, i64* %7
%9 = load i64, i64* @SIG_IGN
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = load i64, i64* @SIG_DFL
store i64 %12, i64* %7
%13 = load i32, i32* @SIGABRT
%14 = call i32 @sigaction(i32 %13, %struct.sigaction* %2, %struct.sigaction* null)
%15 = load i64, i64* %7
br label %16
16: ; preds = %11, %0
%17 = phi i64 [ %15, %11 ], [ %8, %0 ]
%18 = load i64, i64* @SIG_DFL
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @fflush(i32* null)
br label %22
22: ; preds = %20, %16
%23 = call i32 @sigfillset(i32* %1)
%24 = load i32, i32* @SIGABRT
%25 = call i32 @sigdelset(i32* %1, i32 %24)
%26 = load i32, i32* @SIG_SETMASK
%27 = call i32 @sigprocmask(i32 %26, i32* %1, i32* null)
%28 = call i32 (...) @getpid()
%29 = load i32, i32* @SIGABRT
%30 = call i32 @kill(i32 %28, i32 %29)
%31 = call i32 @fflush(i32* null)
%32 = load i64, i64* @SIG_DFL
store i64 %32, i64* %7
%33 = load i32, i32* @SIGABRT
%34 = call i32 @sigaction(i32 %33, %struct.sigaction* %2, %struct.sigaction* null)
%35 = load i32, i32* @SIG_SETMASK
%36 = call i32 @sigprocmask(i32 %35, i32* %1, i32* null)
%37 = call i32 (...) @getpid()
%38 = load i32, i32* @SIGABRT
%39 = call i32 @kill(i32 %37, i32 %38)
%40 = call i32 @exit(i32 1)
unreachable
}