#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ strlen(char *);
int write(int, char *, scalar_t__);
void parent_code(int pipe_to_child[]) {
  close(pipe_to_child[0]);
  char line[] = "I'm proud of you, child.";
  ssize_t size = write(pipe_to_child[1], line, strlen(line) + 1);
  if (size == -1)
    error("Parent can't write to child");
  printf("Parent wrote %ld bytes\n", size);
}


x86 assembly (clang, -O0):
<parent_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1060 <close@plt>
mov    0xe92(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe8f(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe8c(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe8a(%rip),%al
mov    %al,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x44(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    11d8 <parent_code+0x88>
lea    0xe46(%rip),%rdi
call   1070 <error@plt>
mov    -0x34(%rbp),%esi
lea    0xe53(%rip),%rdi
call   1050 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parent_code>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
mov    (%rdi),%edi
call   1060 <close@plt>
movups 0xea1(%rip),%xmm0
movups %xmm0,0x9(%rsp)
movaps 0xe8c(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    0x4(%rbx),%ebx
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <write@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11a7 <parent_code+0x57>
lea    0xe77(%rip),%rdi
call   1070 <error@plt>
lea    0xe87(%rip),%rdi
mov    %ebx,%esi
add    $0x28,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>

LLVM IR (-O0):
@__const.parent_code.line = [25 x i8] c"I'm proud of you, child.\00"
@.str = [28 x i8] c"Parent can't write to child\00"
@.str.1 = [24 x i8] c"Parent wrote %ld bytes\0A\00"
define void @parent_code(i32* %0) {
%2 = alloca i32*
%3 = alloca [25 x i8]
%4 = alloca i32
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = getelementptr inbounds i32, i32* %5, i64 0
%7 = load i32, i32* %6
%8 = call i32 @close(i32 %7)
%9 = bitcast [25 x i8]* %3 to i8*
%10 = load i32*, i32** %2
%11 = getelementptr inbounds i32, i32* %10, i64 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 0
%14 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 0
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 1
%17 = call i32 @write(i32 %12, i8* %13, i64 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %1
%21 = call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %1
%23 = load i32, i32* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %23)
ret void
}

LLVM IR (-O2):
@__const.parent_code.line = [25 x i8] c"I'm proud of you, child.\00"
@.str = [28 x i8] c"Parent can't write to child\00"
@.str.1 = [24 x i8] c"Parent wrote %ld bytes\0A\00"
define void @parent_code(i32* nocapture %0) {
%2 = alloca [25 x i8]
%3 = load i32, i32* %0
%4 = tail call i32 @close(i32 %3)
%5 = getelementptr inbounds [25 x i8], [25 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds i32, i32* %0, i64 1
%7 = load i32, i32* %6
%8 = call i64 @strlen(i8* %5)
%9 = add nsw i64 %8, 1
%10 = call i32 @write(i32 %7, i8* %5, i64 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = tail call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %10)
ret void
}