#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 CHAR_MAX;
int EXIT_FAILURE;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int get_exit_code(int status) {
  if (WIFEXITED(status))
    return (WEXITSTATUS(status));
  else if (WIFSIGNALED(status))
    return (CHAR_MAX + 1 + WTERMSIG(status));
  return (EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<get_exit_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%rax
je     116d <get_exit_code+0x2d>
mov    -0x8(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    11b6 <get_exit_code+0x76>
mov    -0x8(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     11a5 <get_exit_code+0x65>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <WTERMSIG@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11b6 <get_exit_code+0x76>
jmp    11aa <get_exit_code+0x6a>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_exit_code>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
call   1060 <WIFEXITED@plt>
test   %rax,%rax
je     115e <get_exit_code+0x1e>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <WEXITSTATUS@plt>
mov    %ebx,%edi
call   1030 <WIFSIGNALED@plt>
test   %rax,%rax
je     1183 <get_exit_code+0x43>
mov    0x2e77(%rip),%rax
mov    (%rax),%r14d
mov    %ebx,%edi
call   1040 <WTERMSIG@plt>
add    %r14d,%eax
add    $0x1,%eax
jmp    118c <get_exit_code+0x4c>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@CHAR_MAX = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @get_exit_code(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i64 @WIFEXITED(i32 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* %3
%9 = call i32 @WEXITSTATUS(i32 %8)
store i32 %9, i32* %2
br label %23
10: ; preds = %1
%11 = load i32, i32* %3
%12 = call i64 @WIFSIGNALED(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i32, i32* @CHAR_MAX
%16 = add nsw i32 %15, 1
%17 = load i32, i32* %3
%18 = call i32 @WTERMSIG(i32 %17)
%19 = add nsw i32 %16, %18
store i32 %19, i32* %2
br label %23
20: ; preds = %10
br label %21
21: ; preds = %20
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %2
br label %23
23: ; preds = %21, %14, %7
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@CHAR_MAX = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @get_exit_code(i32 %0) {
%2 = tail call i64 @WIFEXITED(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @WEXITSTATUS(i32 %0)
br label %16
6: ; preds = %1
%7 = tail call i64 @WIFSIGNALED(i32 %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %6
%10 = load i32, i32* @CHAR_MAX
%11 = add nsw i32 %10, 1
%12 = tail call i32 @WTERMSIG(i32 %0)
%13 = add nsw i32 %11, %12
br label %16
14: ; preds = %6
%15 = load i32, i32* @EXIT_FAILURE
br label %16
16: ; preds = %14, %9, %4
%17 = phi i32 [ %5, %4 ], [ %13, %9 ], [ %15, %14 ]
ret i32 %17
}