#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 SIGTRAP;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int /*<<< orphan*/ WIFSTOPPED(int);
int WSTOPSIG(int);
int WTERMSIG(int);
int /*<<< orphan*/ snprintf(char *, size_t, char *, ...);
char *strsignal(int);
const char *subproc_StatusToStr(int status, char *str, size_t len) {
  if (WIFEXITED(status)) {
    snprintf(str, len, "EXITED, exit code: %d", WEXITSTATUS(status));
    return str;
  }
  if (WIFSIGNALED(status)) {
    snprintf(str, len, "SIGNALED, signal: %d (%s)", WTERMSIG(status),
             strsignal(WTERMSIG(status)));
    return str;
  }
  if (WEXITSTATUS(0)) {
    snprintf(str, len, "CONTINUED");
    return str;
  }
  if (!WIFSTOPPED(status)) {
    snprintf(str, len, "UNKNOWN STATUS: %d", status);
    return str;
  }
  if (WSTOPSIG(status) == (SIGTRAP | 0x80)) {
    snprintf(str, len, "STOPPED (linux syscall): %d (%s)", WSTOPSIG(status),
             strsignal(WSTOPSIG(status)));
    return str;
  }
  snprintf(str, len, "STOPPED with signal: %d (%s)", WSTOPSIG(status),
           strsignal(WSTOPSIG(status)));
  return str;
}


x86 assembly (clang, -O0):
<subproc_StatusToStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1090 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11e5 <subproc_StatusToStr+0x65>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%ecx
lea    0xe2f(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1374 <subproc_StatusToStr+0x1f4>
mov    -0xc(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     124a <subproc_StatusToStr+0xca>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    %eax,%edi
call   1070 <strsignal@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%ecx
mov    %rax,%r8
lea    0xde0(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1374 <subproc_StatusToStr+0x1f4>
xor    %edi,%edi
call   1080 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     127d <subproc_StatusToStr+0xfd>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xdc7(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1374 <subproc_StatusToStr+0x1f4>
mov    -0xc(%rbp),%edi
call   1050 <WIFSTOPPED@plt>
cmp    $0x0,%eax
jne    12b4 <subproc_StatusToStr+0x134>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%ecx
lea    0xd9a(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1374 <subproc_StatusToStr+0x1f4>
mov    -0xc(%rbp),%edi
call   10a0 <WSTOPSIG@plt>
mov    0x2d1d(%rip),%rcx
mov    (%rcx),%ecx
or     $0x80,%ecx
cmp    %ecx,%eax
jne    1326 <subproc_StatusToStr+0x1a6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0xc(%rbp),%edi
call   10a0 <WSTOPSIG@plt>
mov    %eax,-0x4c(%rbp)
mov    -0xc(%rbp),%edi
call   10a0 <WSTOPSIG@plt>
mov    %eax,%edi
call   1070 <strsignal@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x4c(%rbp),%ecx
mov    %rax,%r8
lea    0xd3b(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1374 <subproc_StatusToStr+0x1f4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0xc(%rbp),%edi
call   10a0 <WSTOPSIG@plt>
mov    %eax,-0x64(%rbp)
mov    -0xc(%rbp),%edi
call   10a0 <WSTOPSIG@plt>
mov    %eax,%edi
call   1070 <strsignal@plt>
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    -0x64(%rbp),%ecx
mov    %rax,%r8
lea    0xd09(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subproc_StatusToStr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
call   1090 <WIFEXITED@plt>
test   %rax,%rax
je     11bc <subproc_StatusToStr+0x3c>
mov    %ebp,%edi
call   1080 <WEXITSTATUS@plt>
lea    0xe55(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    121b <subproc_StatusToStr+0x9b>
mov    %ebp,%edi
call   1040 <WIFSIGNALED@plt>
test   %rax,%rax
je     11fc <subproc_StatusToStr+0x7c>
mov    %ebp,%edi
call   1060 <WTERMSIG@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1060 <WTERMSIG@plt>
mov    %eax,%edi
call   1070 <strsignal@plt>
lea    0xe2f(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    121b <subproc_StatusToStr+0x9b>
xor    %edi,%edi
call   1080 <WEXITSTATUS@plt>
test   %eax,%eax
je     122d <subproc_StatusToStr+0xad>
lea    0xe22(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
call   1050 <WIFSTOPPED@plt>
test   %eax,%eax
je     127b <subproc_StatusToStr+0xfb>
mov    %ebp,%edi
call   10a0 <WSTOPSIG@plt>
mov    %eax,%r12d
mov    0x2d97(%rip),%rax
mov    $0x80,%r13d
or     (%rax),%r13d
mov    %ebp,%edi
call   10a0 <WSTOPSIG@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   10a0 <WSTOPSIG@plt>
mov    %eax,%edi
call   1070 <strsignal@plt>
mov    %rax,%r8
cmp    %r13d,%r12d
jne    128f <subproc_StatusToStr+0x10f>
lea    0xdd4(%rip),%rdx
jmp    1296 <subproc_StatusToStr+0x116>
lea    0xdb8(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%ecx
jmp    11b3 <subproc_StatusToStr+0x33>
lea    0xdd8(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%ecx
jmp    11f3 <subproc_StatusToStr+0x73>

LLVM IR (-O0):
@.str = [22 x i8] c"EXITED, exit code: %d\00"
@.str.1 = [26 x i8] c"SIGNALED, signal: %d (%s)\00"
@.str.2 = [10 x i8] c"CONTINUED\00"
@.str.3 = [19 x i8] c"UNKNOWN STATUS: %d\00"
@SIGTRAP = global i32 0
@.str.4 = [33 x i8] c"STOPPED (linux syscall): %d (%s)\00"
@.str.5 = [29 x i8] c"STOPPED with signal: %d (%s)\00"
define i8* @subproc_StatusToStr(i32 %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%8 = load i32, i32* %5
%9 = call i64 @WIFEXITED(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = load i64, i64* %7
%14 = load i32, i32* %5
%15 = call i32 @WEXITSTATUS(i32 %14)
%16 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %12, i64 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i8*, i8** %6
store i8* %17, i8** %4
br label %76
18: ; preds = %3
%19 = load i32, i32* %5
%20 = call i64 @WIFSIGNALED(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i8*, i8** %6
%24 = load i64, i64* %7
%25 = load i32, i32* %5
%26 = call i32 @WTERMSIG(i32 %25)
%27 = load i32, i32* %5
%28 = call i32 @WTERMSIG(i32 %27)
%29 = call i8* @strsignal(i32 %28)
%30 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %23, i64 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %26, i8* %29)
%31 = load i8*, i8** %6
store i8* %31, i8** %4
br label %76
32: ; preds = %18
%33 = call i32 @WEXITSTATUS(i32 0)
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i8*, i8** %6
%37 = load i64, i64* %7
%38 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %36, i64 %37, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%39 = load i8*, i8** %6
store i8* %39, i8** %4
br label %76
40: ; preds = %32
%41 = load i32, i32* %5
%42 = call i32 @WIFSTOPPED(i32 %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %50, label %44
44: ; preds = %40
%45 = load i8*, i8** %6
%46 = load i64, i64* %7
%47 = load i32, i32* %5
%48 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %45, i64 %46, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %47)
%49 = load i8*, i8** %6
store i8* %49, i8** %4
br label %76
50: ; preds = %40
%51 = load i32, i32* %5
%52 = call i32 @WSTOPSIG(i32 %51)
%53 = load i32, i32* @SIGTRAP
%54 = or i32 %53, 128
%55 = icmp eq i32 %52, %54
br i1 %55, label %56, label %66
56: ; preds = %50
%57 = load i8*, i8** %6
%58 = load i64, i64* %7
%59 = load i32, i32* %5
%60 = call i32 @WSTOPSIG(i32 %59)
%61 = load i32, i32* %5
%62 = call i32 @WSTOPSIG(i32 %61)
%63 = call i8* @strsignal(i32 %62)
%64 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %57, i64 %58, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %60, i8* %63)
%65 = load i8*, i8** %6
store i8* %65, i8** %4
br label %76
66: ; preds = %50
%67 = load i8*, i8** %6
%68 = load i64, i64* %7
%69 = load i32, i32* %5
%70 = call i32 @WSTOPSIG(i32 %69)
%71 = load i32, i32* %5
%72 = call i32 @WSTOPSIG(i32 %71)
%73 = call i8* @strsignal(i32 %72)
%74 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %67, i64 %68, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %70, i8* %73)
%75 = load i8*, i8** %6
store i8* %75, i8** %4
br label %76
76: ; preds = %66, %56, %44, %35, %22, %11
%77 = load i8*, i8** %4
ret i8* %77
}

LLVM IR (-O2):
@.str = [22 x i8] c"EXITED, exit code: %d\00"
@.str.1 = [26 x i8] c"SIGNALED, signal: %d (%s)\00"
@.str.2 = [10 x i8] c"CONTINUED\00"
@.str.3 = [19 x i8] c"UNKNOWN STATUS: %d\00"
@SIGTRAP = global i32 0
@.str.4 = [33 x i8] c"STOPPED (linux syscall): %d (%s)\00"
@.str.5 = [29 x i8] c"STOPPED with signal: %d (%s)\00"
define i8* @subproc_StatusToStr(i32 %0, i8* returned writeonly %1, i64 %2) {
%4 = tail call i64 @WIFEXITED(i32 %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @WEXITSTATUS(i32 %0)
%8 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %39
9: ; preds = %3
%10 = tail call i64 @WIFSIGNALED(i32 %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = tail call i32 @WTERMSIG(i32 %0)
%14 = tail call i32 @WTERMSIG(i32 %0)
%15 = tail call i8* @strsignal(i32 %14)
%16 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %15)
br label %39
17: ; preds = %9
%18 = tail call i32 @WEXITSTATUS(i32 0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %39
22: ; preds = %17
%23 = tail call i32 @WIFSTOPPED(i32 %0)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %39
27: ; preds = %22
%28 = tail call i32 @WSTOPSIG(i32 %0)
%29 = load i32, i32* @SIGTRAP
%30 = or i32 %29, 128
%31 = icmp eq i32 %28, %30
%32 = tail call i32 @WSTOPSIG(i32 %0)
%33 = tail call i32 @WSTOPSIG(i32 %0)
%34 = tail call i8* @strsignal(i32 %33)
br i1 %31, label %35, label %37
35: ; preds = %27
%36 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %32, i8* %34)
br label %39
37: ; preds = %27
%38 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %32, i8* %34)
br label %39
39: ; preds = %37, %35, %25, %20, %12, %6
ret i8* %1
}