#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*/ line3;
typedef int /*<<< orphan*/ line2;
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ input;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int fork();
scalar_t__ malloc(int);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
char *processLine(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fds1[2];
  int fds2[2];
  int f;
  char line[256];
  char *line3 = (char *)malloc(256);
  char line2[256];
  pipe(fds1);
  pipe(fds2);
  f = fork();
  if (f == 0) {
    read(fds1[0], line, sizeof(line));
    printf("child got: %s", line);
    line3 = processLine(line);
    printf("%s", line);
    write(fds2[1], line3, sizeof(line3));
    exit(0);
  } else {
    char input[256];
    printf("type something: ");
    fgets(input, sizeof(input), stdin);
    write(fds1[1], input, sizeof(input));
    read(fds2[0], line2, sizeof(line2));
    printf("child sent: %s", line2);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,-0x128(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <pipe@plt>
lea    -0x10(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    123e <main+0xae>
mov    -0x8(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
lea    -0x120(%rbp),%rsi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
call   1090 <processLine@plt>
mov    %rax,-0x128(%rbp)
lea    -0x120(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x128(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x330(%rbp),%rdi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1070 <fgets@plt>
mov    -0x4(%rbp),%edi
lea    -0x330(%rbp),%rsi
mov    $0x100,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
lea    -0x230(%rbp),%rsi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x218,%rsp
mov    $0x100,%edi
call   1080 <malloc@plt>
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     1231 <main+0xa1>
lea    0xe46(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
lea    0x110(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1070 <fgets@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1030 <write@plt>
mov    (%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
lea    0xe05(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r14
ret
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
lea    0xdb2(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1090 <processLine@plt>
mov    %rax,%rbx
lea    0xdc1(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"child got: %s\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [17 x i8] c"type something: \00"
@stdin = global i32 0
@.str.3 = [15 x i8] c"child sent: %s\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = call i64 @malloc(i32 256)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %5
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%13 = call i32 @pipe(i32* %12)
%14 = call i32 (...) @fork()
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %33
17: ; preds = %0
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 256)
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%25 = call i8* @processLine(i8* %24)
store i8* %25, i8** %5
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%29 = load i32, i32* %28
%30 = load i8*, i8** %5
%31 = call i32 @write(i32 %29, i8* %30, i32 8)
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%36 = load i32, i32* @stdin
%37 = call i32 @fgets(i8* %35, i32 256, i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%41 = call i32 @write(i32 %39, i8* %40, i32 256)
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%43 = load i32, i32* %42
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%45 = call i32 @read(i32 %43, i8* %44, i32 256)
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %33
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"child got: %s\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [17 x i8] c"type something: \00"
@stdin = global i32 0
@.str.3 = [15 x i8] c"child sent: %s\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [2 x i32]
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = bitcast [2 x i32]* %1 to i8*
%7 = bitcast [2 x i32]* %2 to i8*
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = tail call i64 @malloc(i32 256)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = call i32 (...) @fork()
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %0
%18 = load i32, i32* %11
%19 = call i32 @read(i32 %18, i8* %8, i32 256)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %8)
%21 = call i8* @processLine(i8* %8)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @write(i32 %24, i8* %21, i32 8)
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %0
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %28, i32 256, i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i32 @write(i32 %33, i8* %28, i32 256)
%35 = load i32, i32* %13
%36 = call i32 @read(i32 %35, i8* %10, i32 256)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %10)
ret i32 0
}