#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 */
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ WCONTINUED;
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int dup2(int, int);
int /*<<< orphan*/ my_putstr(char *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int wait_exec_red(pid_t pid, int statue, int fd) {
  waitpid(pid, &statue, WCONTINUED);
  if (WIFSIGNALED(statue)) {
    if (WTERMSIG(statue) == 11)
      my_putstr("Segmentation Fault (Core dumped)\n");
  }
  if ((dup2(1, fd)) == -1)
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<wait_exec_red>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rsi
call   1070 <waitpid@plt>
mov    -0xc(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     11aa <wait_exec_red+0x5a>
mov    -0xc(%rbp),%edi
call   1060 <WTERMSIG@plt>
cmp    $0xb,%eax
jne    11a5 <wait_exec_red+0x55>
lea    0xe60(%rip),%rdi
call   1050 <my_putstr@plt>
jmp    11aa <wait_exec_red+0x5a>
mov    -0x10(%rbp),%esi
mov    $0x1,%edi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    11cc <wait_exec_red+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d3 <wait_exec_red+0x83>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_exec_red>:
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %esi,0xc(%rsp)
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rsi
call   1070 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1040 <WIFSIGNALED@plt>
test   %rax,%rax
je     1196 <wait_exec_red+0x46>
mov    0xc(%rsp),%edi
call   1060 <WTERMSIG@plt>
cmp    $0xb,%eax
jne    1196 <wait_exec_red+0x46>
lea    0xe6f(%rip),%rdi
call   1050 <my_putstr@plt>
mov    $0x1,%edi
mov    %ebx,%esi
call   1030 <dup2@plt>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
sete   %cl
neg    %ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@WCONTINUED = global i32 0
@.str = [34 x i8] c"Segmentation Fault (Core dumped)\0A\00"
define i32 @wait_exec_red(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
%9 = load i32, i32* @WCONTINUED
%10 = call i32 @waitpid(i32 %8, i32* %6, i32 %9)
%11 = load i32, i32* %6
%12 = call i64 @WIFSIGNALED(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %3
%15 = load i32, i32* %6
%16 = call i32 @WTERMSIG(i32 %15)
%17 = icmp eq i32 %16, 11
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @my_putstr(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
br label %21
21: ; preds = %20, %3
%22 = load i32, i32* %7
%23 = call i32 @dup2(i32 1, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 -1, i32* %4
br label %27
26: ; preds = %21
store i32 0, i32* %4
br label %27
27: ; preds = %26, %25
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@WCONTINUED = global i32 0
@.str = [34 x i8] c"Segmentation Fault (Core dumped)\0A\00"
define i32 @wait_exec_red(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
store i32 %1, i32* %4
%5 = load i32, i32* @WCONTINUED
%6 = call i32 @waitpid(i32 %0, i32* %4, i32 %5)
%7 = load i32, i32* %4
%8 = call i64 @WIFSIGNALED(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %3
%11 = load i32, i32* %4
%12 = call i32 @WTERMSIG(i32 %11)
%13 = icmp eq i32 %12, 11
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @my_putstr(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %10, %14, %3
%17 = call i32 @dup2(i32 1, i32 %2)
%18 = icmp eq i32 %17, -1
%19 = sext i1 %18 to i32
ret i32 %19
}