#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 asprintf(char **, char *, int, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ get_exit_details(int, int *, int *, int *, int *);
int strerror(int /*<<< orphan*/);
int copy_exit_detail_str(int status, char **buffer) {
  int ret;
  bool core;
  bool signaled;
  bool parent;
  get_exit_details(status, &ret, &core, &signaled, &parent);
  if (ret == -1) {
    if (parent)
      ret = asprintf(buffer,
                     "An error has occurred in the "
                     "parent process: %s",
                     strerror(errno));
    else
      ret = asprintf(buffer,
                     "An error has occurred in the "
                     "child process: %s",
                     strerror(errno));
  } else {
    if (signaled)
      ret = asprintf(buffer,
                     "Process exited due to signal "
                     "%d (core %s dumped)",
                     ret, core ? "was" : "not");
    else
      ret = asprintf(buffer, "Process exited with status %d", ret);
  }
  return (ret == -1);
}


x86 assembly (clang, -O0):
<copy_exit_detail_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1050 <get_exit_details@plt>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11cf <copy_exit_detail_str+0x9f>
cmpl   $0x0,-0x20(%rbp)
je     119d <copy_exit_detail_str+0x6d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1030 <asprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    11ca <copy_exit_detail_str+0x9a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1030 <asprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    122b <copy_exit_detail_str+0xfb>
cmpl   $0x0,-0x1c(%rbp)
je     120e <copy_exit_detail_str+0xde>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%esi
lea    0xeaa(%rip),%rcx
lea    0xe9f(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1030 <asprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    1226 <copy_exit_detail_str+0xf6>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1030 <asprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    122b <copy_exit_detail_str+0xfb>
cmpl   $0xffffffff,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_exit_detail_str>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1050 <get_exit_details@plt>
mov    0x14(%rsp),%edx
cmp    $0xffffffff,%edx
je     118c <copy_exit_detail_str+0x5c>
cmpl   $0x0,0xc(%rsp)
je     11ab <copy_exit_detail_str+0x7b>
cmpl   $0x0,0x10(%rsp)
lea    0xf26(%rip),%rax
lea    0xf1b(%rip),%rcx
cmove  %rax,%rcx
lea    0xedf(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <asprintf@plt>
jmp    11ca <copy_exit_detail_str+0x9a>
mov    0x8(%rsp),%ebp
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
test   %ebp,%ebp
je     11b7 <copy_exit_detail_str+0x87>
lea    0xe57(%rip),%rsi
jmp    11be <copy_exit_detail_str+0x8e>
lea    0xee6(%rip),%rsi
mov    %rbx,%rdi
jmp    11c3 <copy_exit_detail_str+0x93>
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <asprintf@plt>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
sete   %cl
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"An error has occurred in the parent process: %s\00"
@errno = global i32 0
@.str.1 = [47 x i8] c"An error has occurred in the child process: %s\00"
@.str.2 = [49 x i8] c"Process exited due to signal %d (core %s dumped)\00"
@.str.3 = [4 x i8] c"was\00"
@.str.4 = [4 x i8] c"not\00"
@.str.5 = [30 x i8] c"Process exited with status %d\00"
define i32 @copy_exit_detail_str(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* %3
%10 = call i32 @get_exit_details(i32 %9, i32* %5, i32* %6, i32* %7, i32* %8)
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %27
13: ; preds = %2
%14 = load i32, i32* %8
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i8**, i8*** %4
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call i32 (i8**, i8*, i32, ...) @asprintf(i8** %17, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 %20, i32* %5
br label %26
21: ; preds = %13
%22 = load i8**, i8*** %4
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 (i8**, i8*, i32, ...) @asprintf(i8** %22, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %24)
store i32 %25, i32* %5
br label %26
26: ; preds = %21, %16
br label %43
27: ; preds = %2
%28 = load i32, i32* %7
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i8**, i8*** %4
%32 = load i32, i32* %5
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
%37 = call i32 (i8**, i8*, i32, ...) @asprintf(i8** %31, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %32, i8* %36)
store i32 %37, i32* %5
br label %42
38: ; preds = %27
%39 = load i8**, i8*** %4
%40 = load i32, i32* %5
%41 = call i32 (i8**, i8*, i32, ...) @asprintf(i8** %39, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %40)
store i32 %41, i32* %5
br label %42
42: ; preds = %38, %30
br label %43
43: ; preds = %42, %26
%44 = load i32, i32* %5
%45 = icmp eq i32 %44, -1
%46 = zext i1 %45 to i32
ret i32 %46
}

LLVM IR (-O2):
@.str = [48 x i8] c"An error has occurred in the parent process: %s\00"
@errno = global i32 0
@.str.1 = [47 x i8] c"An error has occurred in the child process: %s\00"
@.str.2 = [49 x i8] c"Process exited due to signal %d (core %s dumped)\00"
@.str.3 = [4 x i8] c"was\00"
@.str.4 = [4 x i8] c"not\00"
@.str.5 = [30 x i8] c"Process exited with status %d\00"
define i32 @copy_exit_detail_str(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = call i32 @get_exit_details(i32 %0, i32* %3, i32* %4, i32* %5, i32* %6)
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
br i1 %16, label %21, label %19
19: ; preds = %14
%20 = call i32 (i8**, i8*, i32, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %33
21: ; preds = %14
%22 = call i32 (i8**, i8*, i32, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %33
23: ; preds = %2
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %23
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 0
%29 = select i1 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0)
%30 = call i32 (i8**, i8*, i32, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %12, i8* %29)
br label %33
31: ; preds = %23
%32 = call i32 (i8**, i8*, i32, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %12)
br label %33
33: ; preds = %26, %31, %19, %21
%34 = phi i32 [ %30, %26 ], [ %32, %31 ], [ %20, %19 ], [ %22, %21 ]
%35 = icmp eq i32 %34, -1
%36 = zext i1 %35 to i32
ret i32 %36
}