#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 SIGBUS;
int SIGSEGV;
scalar_t__ WCOREDUMP(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int wait_status_correct(int status) {
  if (WIFSIGNALED(status)) {
    if (WCOREDUMP(status)) {
      fprintf(stderr, "process finished abnormally. core dumped\n");
      return 0;
    }
    int signum = WTERMSIG(status);
    if (signum == SIGSEGV) {
      fprintf(stderr, "process finished abnormally. segmentation fault\n");
      return 0;
    }
    if (signum == SIGBUS) {
      fprintf(stderr, "process finished abnormally. bus error\n");
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<wait_status_correct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1206 <wait_status_correct+0xc6>
mov    -0x8(%rbp),%edi
call   1030 <WCOREDUMP@plt>
cmp    $0x0,%rax
je     1190 <wait_status_correct+0x50>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    120d <wait_status_correct+0xcd>
mov    -0x8(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e3b(%rip),%rcx
cmp    (%rcx),%eax
jne    11ce <wait_status_correct+0x8e>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    120d <wait_status_correct+0xcd>
mov    -0xc(%rbp),%eax
mov    0x2e18(%rip),%rcx
cmp    (%rcx),%eax
jne    1201 <wait_status_correct+0xc1>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    120d <wait_status_correct+0xcd>
jmp    1206 <wait_status_correct+0xc6>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_status_correct>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1040 <WIFSIGNALED@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11a6 <wait_status_correct+0x66>
mov    %ebp,%edi
call   1030 <WCOREDUMP@plt>
test   %rax,%rax
je     1169 <wait_status_correct+0x29>
lea    0xe99(%rip),%rsi
jmp    1196 <wait_status_correct+0x56>
mov    %ebp,%edi
call   1060 <WTERMSIG@plt>
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%eax
jne    1184 <wait_status_correct+0x44>
lea    0xea8(%rip),%rsi
jmp    1196 <wait_status_correct+0x56>
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%eax
jne    11a6 <wait_status_correct+0x66>
lea    0xec5(%rip),%rsi
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1050 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"process finished abnormally. core dumped\0A\00"
@SIGSEGV = global i32 0
@.str.1 = [49 x i8] c"process finished abnormally. segmentation fault\0A\00"
@SIGBUS = global i32 0
@.str.2 = [40 x i8] c"process finished abnormally. bus error\0A\00"
define i32 @wait_status_correct(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i64 @WIFSIGNALED(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %32
8: ; preds = %1
%9 = load i32, i32* %3
%10 = call i64 @WCOREDUMP(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %33
15: ; preds = %8
%16 = load i32, i32* %3
%17 = call i32 @WTERMSIG(i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = load i32, i32* @SIGSEGV
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %33
24: ; preds = %15
%25 = load i32, i32* %4
%26 = load i32, i32* @SIGBUS
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %33
31: ; preds = %24
br label %32
32: ; preds = %31, %1
store i32 1, i32* %2
br label %33
33: ; preds = %32, %28, %21, %12
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"process finished abnormally. core dumped\0A\00"
@SIGSEGV = global i32 0
@.str.1 = [49 x i8] c"process finished abnormally. segmentation fault\0A\00"
@SIGBUS = global i32 0
@.str.2 = [40 x i8] c"process finished abnormally. bus error\0A\00"
define i32 @wait_status_correct(i32 %0) {
%2 = tail call i64 @WIFSIGNALED(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = tail call i64 @WCOREDUMP(i32 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = tail call i32 @WTERMSIG(i32 %0)
%9 = load i32, i32* @SIGSEGV
%10 = icmp eq i32 %8, %9
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = load i32, i32* @SIGBUS
%13 = icmp eq i32 %8, %12
br i1 %13, label %14, label %18
14: ; preds = %11, %7, %4
%15 = phi i8* [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), %11 ]
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* %15)
br label %18
18: ; preds = %14, %1, %11
%19 = phi i32 [ 1, %11 ], [ 1, %1 ], [ 0, %14 ]
ret i32 %19
}