#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 EXIT_FAILURE;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
void process_term_status(int status) {
  if (WIFEXITED(status)) {
    int exit_status = WEXITSTATUS(status);
    exit(exit_status);
  } else if (WIFSIGNALED(status)) {
    int term_signal = WTERMSIG(status);
    exit(term_signal + 128);
  } else {
    fprintf(stderr, "watchdogrun: seen unexpected status 0x%x from wait\n",
            status);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<process_term_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1190 <process_term_status+0x30>
mov    -0x4(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1080 <exit@plt>
mov    -0x4(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     11bb <process_term_status+0x5b>
mov    -0x4(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x80,%edi
call   1080 <exit@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe32(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<process_term_status>:
push   %rbx
mov    %edi,%ebx
call   1070 <WIFEXITED@plt>
test   %rax,%rax
jne    119e <process_term_status+0x3e>
mov    %ebx,%edi
call   1030 <WIFSIGNALED@plt>
test   %rax,%rax
jne    11ac <process_term_status+0x4c>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %ebx,%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,%edi
call   1080 <exit@plt>
mov    %ebx,%edi
call   1050 <WTERMSIG@plt>
lea    0x80(%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [52 x i8] c"watchdogrun: seen unexpected status 0x%x from wait\0A\00"
@EXIT_FAILURE = global i32 0
define void @process_term_status(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i64 @WIFEXITED(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* %2
%10 = call i32 @WEXITSTATUS(i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
%14 = load i32, i32* %2
%15 = call i64 @WIFSIGNALED(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* %2
%19 = call i32 @WTERMSIG(i32 %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 128
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %13
%24 = load i32, i32* @stderr
%25 = load i32, i32* %2
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [52 x i8] c"watchdogrun: seen unexpected status 0x%x from wait\0A\00"
@EXIT_FAILURE = global i32 0
define void @process_term_status(i32 %0) {
%2 = tail call i64 @WIFEXITED(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 @WEXITSTATUS(i32 %0)
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %1
%8 = tail call i64 @WIFSIGNALED(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call i32 @WTERMSIG(i32 %0)
%12 = add nsw i32 %11, 128
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %7
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %0)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
}