void prexit(stat) {
  if (WIFEXITED(stat))
    printf("normal termination, exit status = %d\n", WEXITSTATUS(stat));
  else if (WIFSIGNALED(stat))
    printf("abnormal termination, signal = %d %s\n", WTERMSIG(stat), "");
  else if (WIFSTOPPED(stat))
    printf("child stopped, signal = %d\n", WSTOPSIG(stat));
  else if (WIFCONTINUED(stat))
    printf("child stopped, signal = %d\n", WSTOPSIG(stat));
}


x86 assembly (clang, -O0):
<prexit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1090 <WIFEXITED@plt>
cmp    $0x0,%eax
je     11bd <prexit+0x3d>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1080 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1264 <prexit+0xe4>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%eax
je     11f6 <prexit+0x76>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1070 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xe43(%rip),%rdi
lea    0xe7d(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125f <prexit+0xdf>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1060 <WIFSTOPPED@plt>
cmp    $0x0,%eax
je     1228 <prexit+0xa8>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   10a0 <WSTOPSIG@plt>
mov    %eax,%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125a <prexit+0xda>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1050 <WIFCONTINUED@plt>
cmp    $0x0,%eax
je     1255 <prexit+0xd5>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   10a0 <WSTOPSIG@plt>
mov    %eax,%esi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125a <prexit+0xda>
jmp    125f <prexit+0xdf>
jmp    1264 <prexit+0xe4>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prexit>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1090 <WIFEXITED@plt>
test   %eax,%eax
je     11a8 <prexit+0x28>
mov    %ebx,%edi
xor    %eax,%eax
call   1080 <WEXITSTATUS@plt>
lea    0xe62(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <WIFSIGNALED@plt>
test   %eax,%eax
je     11d6 <prexit+0x56>
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <WTERMSIG@plt>
lea    0xe61(%rip),%rdi
lea    0xe9b(%rip),%rdx
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <WIFSTOPPED@plt>
test   %eax,%eax
jne    11f0 <prexit+0x70>
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <WIFCONTINUED@plt>
test   %eax,%eax
je     1202 <prexit+0x82>
mov    %ebx,%edi
xor    %eax,%eax
call   10a0 <WSTOPSIG@plt>
lea    0xe4c(%rip),%rdi
jmp    119e <prexit+0x1e>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [38 x i8] c"normal termination, exit status = %d\0A\00"
@.str.1 = [38 x i8] c"abnormal termination, signal = %d %s\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [28 x i8] c"child stopped, signal = %d\0A\00"
define void @prexit(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i32 (i32, ...) bitcast (i32 (...)* @WIFEXITED to i32 (i32, ...)*)(i32 %3)
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* %2
%8 = call i32 (i32, ...) bitcast (i32 (...)* @WEXITSTATUS to i32 (i32, ...)*)(i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %37
10: ; preds = %1
%11 = load i32, i32* %2
%12 = call i32 (i32, ...) bitcast (i32 (...)* @WIFSIGNALED to i32 (i32, ...)*)(i32 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* %2
%16 = call i32 (i32, ...) bitcast (i32 (...)* @WTERMSIG to i32 (i32, ...)*)(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %36
18: ; preds = %10
%19 = load i32, i32* %2
%20 = call i32 (i32, ...) bitcast (i32 (...)* @WIFSTOPPED to i32 (i32, ...)*)(i32 %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* %2
%24 = call i32 (i32, ...) bitcast (i32 (...)* @WSTOPSIG to i32 (i32, ...)*)(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %35
26: ; preds = %18
%27 = load i32, i32* %2
%28 = call i32 (i32, ...) bitcast (i32 (...)* @WIFCONTINUED to i32 (i32, ...)*)(i32 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* %2
%32 = call i32 (i32, ...) bitcast (i32 (...)* @WSTOPSIG to i32 (i32, ...)*)(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %30, %26
br label %35
35: ; preds = %34, %22
br label %36
36: ; preds = %35, %14
br label %37
37: ; preds = %36, %6
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"normal termination, exit status = %d\0A\00"
@.str.1 = [38 x i8] c"abnormal termination, signal = %d %s\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [28 x i8] c"child stopped, signal = %d\0A\00"
define void @prexit(i32 %0) {
%2 = tail call i32 (i32, ...) bitcast (i32 (...)* @WIFEXITED to i32 (i32, ...)*)(i32 %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 (i32, ...) bitcast (i32 (...)* @WEXITSTATUS to i32 (i32, ...)*)(i32 %0)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %25
7: ; preds = %1
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @WIFSIGNALED to i32 (i32, ...)*)(i32 %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @WTERMSIG to i32 (i32, ...)*)(i32 %0)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %25
13: ; preds = %7
%14 = tail call i32 (i32, ...) bitcast (i32 (...)* @WIFSTOPPED to i32 (i32, ...)*)(i32 %0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = tail call i32 (i32, ...) bitcast (i32 (...)* @WSTOPSIG to i32 (i32, ...)*)(i32 %0)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %25
19: ; preds = %13
%20 = tail call i32 (i32, ...) bitcast (i32 (...)* @WIFCONTINUED to i32 (i32, ...)*)(i32 %0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = tail call i32 (i32, ...) bitcast (i32 (...)* @WSTOPSIG to i32 (i32, ...)*)(i32 %0)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %10, %19, %22, %16, %4
ret void
}