#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 WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int /*<<< orphan*/ WTERMSIG(int);
int /*<<< orphan*/ pm_asprintf(char const **, char *, ...);
int /*<<< orphan*/ signalName(int /*<<< orphan*/);
const char *pm_termStatusDesc(int const termStatusArg) {
  const char *retval;
  int termStatus = termStatusArg;
  if (WIFEXITED(termStatus)) {
    int const exitStatus = WEXITSTATUS(termStatus);
    if (exitStatus == 0)
      pm_asprintf(&retval, "Process exited normally");
    else
      pm_asprintf(&retval, "Process exited with abnormal exit status %u.  ",
                  exitStatus);
  } else if (WIFSIGNALED(termStatus)) {
    pm_asprintf(&retval, "Process was killed by a Class %u (%s) signal.",
                WTERMSIG(termStatus), signalName(WTERMSIG(termStatus)));
  } else {
    pm_asprintf(&retval,
                "Process died, but its termination status "
                "0x%x  doesn't make sense",
                termStatus);
  }
  return retval;
}


x86 assembly (clang, -O0):
<pm_termStatusDesc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11c9 <pm_termStatusDesc+0x69>
mov    -0x14(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11af <pm_termStatusDesc+0x4f>
lea    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1030 <pm_asprintf@plt>
jmp    11c4 <pm_termStatusDesc+0x64>
mov    -0x18(%rbp),%edx
lea    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1030 <pm_asprintf@plt>
jmp    122b <pm_termStatusDesc+0xcb>
mov    -0x14(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1211 <pm_termStatusDesc+0xb1>
mov    -0x14(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%edi
call   1070 <signalName@plt>
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
lea    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1030 <pm_asprintf@plt>
jmp    1226 <pm_termStatusDesc+0xc6>
mov    -0x14(%rbp),%edx
lea    -0x10(%rbp),%rdi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1030 <pm_asprintf@plt>
jmp    122b <pm_termStatusDesc+0xcb>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pm_termStatusDesc>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
call   1080 <WIFEXITED@plt>
test   %rax,%rax
je     1188 <pm_termStatusDesc+0x28>
mov    %ebx,%edi
call   1060 <WEXITSTATUS@plt>
test   %eax,%eax
je     11c2 <pm_termStatusDesc+0x62>
lea    0xe97(%rip),%rsi
mov    %rsp,%rdi
mov    %eax,%edx
jmp    11e1 <pm_termStatusDesc+0x81>
mov    %ebx,%edi
call   1040 <WIFSIGNALED@plt>
test   %rax,%rax
je     11d5 <pm_termStatusDesc+0x75>
mov    %ebx,%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%edi
call   1070 <signalName@plt>
lea    0xe95(%rip),%rsi
mov    %rsp,%rdi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <pm_asprintf@plt>
jmp    11e8 <pm_termStatusDesc+0x88>
lea    0xe37(%rip),%rsi
mov    %rsp,%rdi
xor    %eax,%eax
call   1030 <pm_asprintf@plt>
jmp    11e8 <pm_termStatusDesc+0x88>
lea    0xe99(%rip),%rsi
mov    %rsp,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <pm_asprintf@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Process exited normally\00"
@.str.1 = [47 x i8] c"Process exited with abnormal exit status %u. \00"
@.str.2 = [46 x i8] c"Process was killed by a Class %u (%s) signal.\00"
@.str.3 = [66 x i8] c"Process died, but its termination status 0x%x doesn't make sense\00"
define i8* @pm_termStatusDesc(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = call i64 @WIFEXITED(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %1
%11 = load i32, i32* %4
%12 = call i32 @WEXITSTATUS(i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 (i8**, i8*, ...) @pm_asprintf(i8** %3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %20
17: ; preds = %10
%18 = load i32, i32* %5
%19 = call i32 (i8**, i8*, ...) @pm_asprintf(i8** %3, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %15
br label %36
21: ; preds = %1
%22 = load i32, i32* %4
%23 = call i64 @WIFSIGNALED(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i32, i32* %4
%27 = call i32 @WTERMSIG(i32 %26)
%28 = load i32, i32* %4
%29 = call i32 @WTERMSIG(i32 %28)
%30 = call i32 @signalName(i32 %29)
%31 = call i32 (i8**, i8*, ...) @pm_asprintf(i8** %3, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %30)
br label %35
32: ; preds = %21
%33 = load i32, i32* %4
%34 = call i32 (i8**, i8*, ...) @pm_asprintf(i8** %3, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32, %25
br label %36
36: ; preds = %35, %20
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
@.str = [24 x i8] c"Process exited normally\00"
@.str.1 = [47 x i8] c"Process exited with abnormal exit status %u. \00"
@.str.2 = [46 x i8] c"Process was killed by a Class %u (%s) signal.\00"
@.str.3 = [66 x i8] c"Process died, but its termination status 0x%x doesn't make sense\00"
define i8* @pm_termStatusDesc(i32 %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i64 @WIFEXITED(i32 %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = tail call i32 @WEXITSTATUS(i32 %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 (i8**, i8*, ...) @pm_asprintf(i8** %2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %23
11: ; preds = %6
%12 = call i32 (i8**, i8*, ...) @pm_asprintf(i8** %2, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %23
13: ; preds = %1
%14 = tail call i64 @WIFSIGNALED(i32 %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = tail call i32 @WTERMSIG(i32 %0)
%18 = tail call i32 @WTERMSIG(i32 %0)
%19 = tail call i32 @signalName(i32 %18)
%20 = call i32 (i8**, i8*, ...) @pm_asprintf(i8** %2, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %19)
br label %23
21: ; preds = %13
%22 = call i32 (i8**, i8*, ...) @pm_asprintf(i8** %2, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %23
23: ; preds = %9, %11, %16, %21
%24 = load i8*, i8** %2
ret i8* %24
}