#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*/ s;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  char s[10005];
  int c2p[2], p2c[2];
  pipe(c2p);
  pipe(p2c);
  if (fork() == 0) {
    read(p2c[0], s, sizeof(s));
    int i, n = strlen(s);
    for (i = 0; i < n / 2; ++i) {
      char aux = s[i];
      s[i] = s[n - i - 1];
      s[n - i - 1] = aux;
    }
    write(c2p[1], s, sizeof(s));
    exit(1);
  }
  fgets(s, sizeof(s), stdin);
  close(p2c[0]);
  close(c2p[1]);
  write(p2c[1], s, sizeof(s));
  close(p2c[1]);
  read(c2p[0], s, sizeof(s));
  printf("%s\n", s);
  close(c2p[0]);
  wait(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2740,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x2728(%rbp),%rdi
call   1070 <pipe@plt>
lea    -0x2730(%rbp),%rdi
call   1070 <pipe@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
cmp    $0x0,%rax
jne    12c5 <main+0x125>
mov    -0x2730(%rbp),%edi
lea    -0x2720(%rbp),%rsi
mov    $0x2715,%edx
call   1080 <read@plt>
lea    -0x2720(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2738(%rbp)
movl   $0x0,-0x2734(%rbp)
mov    -0x2734(%rbp),%eax
mov    %eax,-0x2740(%rbp)
mov    -0x2738(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2740(%rbp),%eax
cmp    %ecx,%eax
jge    12a4 <main+0x104>
movslq -0x2734(%rbp),%rax
mov    -0x2720(%rbp,%rax,1),%al
mov    %al,-0x2739(%rbp)
mov    -0x2738(%rbp),%eax
sub    -0x2734(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x2720(%rbp,%rax,1),%cl
movslq -0x2734(%rbp),%rax
mov    %cl,-0x2720(%rbp,%rax,1)
mov    -0x2739(%rbp),%cl
mov    -0x2738(%rbp),%eax
sub    -0x2734(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0x2720(%rbp,%rax,1)
mov    -0x2734(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2734(%rbp)
jmp    120e <main+0x6e>
mov    -0x2724(%rbp),%edi
lea    -0x2720(%rbp),%rsi
mov    $0x2715,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x2720(%rbp),%rdi
mov    0x2d15(%rip),%rax
mov    (%rax),%edx
mov    $0x2715,%esi
call   1090 <fgets@plt>
mov    -0x2730(%rbp),%edi
call   1060 <close@plt>
mov    -0x2724(%rbp),%edi
call   1060 <close@plt>
mov    -0x272c(%rbp),%edi
lea    -0x2720(%rbp),%rsi
mov    $0x2715,%edx
call   1030 <write@plt>
mov    -0x272c(%rbp),%edi
call   1060 <close@plt>
mov    -0x2728(%rbp),%edi
lea    -0x2720(%rbp),%rsi
mov    $0x2715,%edx
call   1080 <read@plt>
lea    -0x2720(%rbp),%rsi
lea    0xcc4(%rip),%rdi
call   1050 <printf@plt>
mov    -0x2728(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10b0 <wait@plt>
xor    %eax,%eax
add    $0x2740,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x2730,%rsp
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
mov    %rsp,%rdi
call   1070 <pipe@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
je     124b <main+0xab>
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2715,%esi
call   1090 <fgets@plt>
mov    (%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
mov    $0x2715,%edx
call   1030 <write@plt>
mov    0x4(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x2715,%edx
call   1080 <read@plt>
lea    0xdd8(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10b0 <wait@plt>
xor    %eax,%eax
add    $0x2730,%rsp
pop    %rbx
ret
mov    (%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x2715,%edx
call   1080 <read@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     12e9 <main+0x149>
mov    %eax,%r8d
shr    %r8d
cmp    $0x1,%r8d
jne    1281 <main+0xe1>
xor    %edx,%edx
jmp    12cb <main+0x12b>
mov    %r8d,%esi
and    $0xfffffffe,%esi
lea    -0x2(%rax),%edi
xor    %edx,%edx
nopl   0x0(%rax)
movzbl 0x10(%rsp,%rdx,1),%r9d
lea    0x1(%rdi),%ecx
movslq %ecx,%rcx
movzbl 0x10(%rsp,%rcx,1),%ebx
mov    %bl,0x10(%rsp,%rdx,1)
mov    %r9b,0x10(%rsp,%rcx,1)
movzbl 0x11(%rsp,%rdx,1),%ecx
movslq %edi,%rdi
movzbl 0x10(%rsp,%rdi,1),%ebx
mov    %bl,0x11(%rsp,%rdx,1)
mov    %cl,0x10(%rsp,%rdi,1)
add    $0x2,%rdx
add    $0xfffffffe,%edi
cmp    %rdx,%rsi
jne    1290 <main+0xf0>
test   $0x1,%r8b
je     12e9 <main+0x149>
mov    0x10(%rsp,%rdx,1),%cl
mov    %edx,%esi
not    %esi
add    %esi,%eax
cltq
mov    0x10(%rsp,%rax,1),%bl
mov    %bl,0x10(%rsp,%rdx,1)
mov    %cl,0x10(%rsp,%rax,1)
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x2715,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10005 x i8]
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %1
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = call i64 (...) @fork()
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %57
14: ; preds = %0
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds [10005 x i8], [10005 x i8]* %2, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 10005)
%19 = getelementptr inbounds [10005 x i8], [10005 x i8]* %2, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %6
store i32 0, i32* %5
br label %21
21: ; preds = %48, %14
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = sdiv i32 %23, 2
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %51
26: ; preds = %21
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [10005 x i8], [10005 x i8]* %2, i64 0, i64 %28
%30 = load i8, i8* %29
store i8 %30, i8* %7
%31 = load i32, i32* %6
%32 = load i32, i32* %5
%33 = sub nsw i32 %31, %32
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [10005 x i8], [10005 x i8]* %2, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [10005 x i8], [10005 x i8]* %2, i64 0, i64 %39
store i8 %37, i8* %40
%41 = load i8, i8* %7
%42 = load i32, i32* %6
%43 = load i32, i32* %5
%44 = sub nsw i32 %42, %43
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [10005 x i8], [10005 x i8]* %2, i64 0, i64 %46
store i8 %41, i8* %47
br label %48
48: ; preds = %26
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %21
51: ; preds = %21
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%53 = load i32, i32* %52
%54 = getelementptr inbounds [10005 x i8], [10005 x i8]* %2, i64 0, i64 0
%55 = call i32 @write(i32 %53, i8* %54, i32 10005)
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %0
%58 = getelementptr inbounds [10005 x i8], [10005 x i8]* %2, i64 0, i64 0
%59 = load i32, i32* @stdin
%60 = call i32 @fgets(i8* %58, i32 10005, i32 %59)
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%62 = load i32, i32* %61
%63 = call i32 @close(i32 %62)
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%65 = load i32, i32* %64
%66 = call i32 @close(i32 %65)
%67 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%68 = load i32, i32* %67
%69 = getelementptr inbounds [10005 x i8], [10005 x i8]* %2, i64 0, i64 0
%70 = call i32 @write(i32 %68, i8* %69, i32 10005)
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%72 = load i32, i32* %71
%73 = call i32 @close(i32 %72)
%74 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%75 = load i32, i32* %74
%76 = getelementptr inbounds [10005 x i8], [10005 x i8]* %2, i64 0, i64 0
%77 = call i32 @read(i32 %75, i8* %76, i32 10005)
%78 = getelementptr inbounds [10005 x i8], [10005 x i8]* %2, i64 0, i64 0
%79 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %78)
%80 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%81 = load i32, i32* %80
%82 = call i32 @close(i32 %81)
%83 = call i32 @wait(i32 0)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [10005 x i8]
%2 = alloca [2 x i32]
%3 = alloca [2 x i32]
%4 = getelementptr inbounds [10005 x i8], [10005 x i8]* %1, i64 0, i64 0
%5 = bitcast [2 x i32]* %2 to i8*
%6 = bitcast [2 x i32]* %3 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %65
13: ; preds = %0
%14 = load i32, i32* %9
%15 = call i32 @read(i32 %14, i8* %4, i32 10005)
%16 = call i32 @strlen(i8* %4)
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %60
18: ; preds = %13
%19 = lshr i32 %16, 1
%20 = zext i32 %19 to i64
%21 = and i64 %20, 1
%22 = icmp eq i32 %19, 1
br i1 %22, label %48, label %23
23: ; preds = %18
%24 = and i64 %20, 2147483646
br label %25
25: ; preds = %25, %23
%26 = phi i64 [ 0, %23 ], [ %45, %25 ]
%27 = phi i64 [ 0, %23 ], [ %46, %25 ]
%28 = getelementptr inbounds [10005 x i8], [10005 x i8]* %1, i64 0, i64 %26
%29 = load i8, i8* %28
%30 = trunc i64 %26 to i32
%31 = xor i32 %30, -1
%32 = add i32 %16, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10005 x i8], [10005 x i8]* %1, i64 0, i64 %33
%35 = load i8, i8* %34
store i8 %35, i8* %28
store i8 %29, i8* %34
%36 = or i64 %26, 1
%37 = getelementptr inbounds [10005 x i8], [10005 x i8]* %1, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = trunc i64 %36 to i32
%40 = xor i32 %39, -1
%41 = add i32 %16, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [10005 x i8], [10005 x i8]* %1, i64 0, i64 %42
%44 = load i8, i8* %43
store i8 %44, i8* %37
store i8 %38, i8* %43
%45 = add nuw nsw i64 %26, 2
%46 = add i64 %27, 2
%47 = icmp eq i64 %46, %24
br i1 %47, label %48, label %25
48: ; preds = %25, %18
%49 = phi i64 [ 0, %18 ], [ %45, %25 ]
%50 = icmp eq i64 %21, 0
br i1 %50, label %60, label %51
51: ; preds = %48
%52 = getelementptr inbounds [10005 x i8], [10005 x i8]* %1, i64 0, i64 %49
%53 = load i8, i8* %52
%54 = trunc i64 %49 to i32
%55 = xor i32 %54, -1
%56 = add i32 %16, %55
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [10005 x i8], [10005 x i8]* %1, i64 0, i64 %57
%59 = load i8, i8* %58
store i8 %59, i8* %52
store i8 %53, i8* %58
br label %60
60: ; preds = %51, %48, %13
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%62 = load i32, i32* %61
%63 = call i32 @write(i32 %62, i8* %4, i32 10005)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %0
%66 = load i32, i32* @stdin
%67 = call i32 @fgets(i8* %4, i32 10005, i32 %66)
%68 = load i32, i32* %9
%69 = call i32 @close(i32 %68)
%70 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%71 = load i32, i32* %70
%72 = call i32 @close(i32 %71)
%73 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%74 = load i32, i32* %73
%75 = call i32 @write(i32 %74, i8* %4, i32 10005)
%76 = load i32, i32* %73
%77 = call i32 @close(i32 %76)
%78 = load i32, i32* %7
%79 = call i32 @read(i32 %78, i8* %4, i32 10005)
%80 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%81 = load i32, i32* %7
%82 = call i32 @close(i32 %81)
%83 = call i32 @wait(i32 0)
ret i32 0
}