#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*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  pid_t pid;
  int fd_arr[2], i;
  char ch;
  pipe(fd_arr);
  if ((pid = fork()) == 0) {
    close(fd_arr[1]);
    for (i = 0; i < 10; i++) {
      read(fd_arr[0], &ch, 1);
      putchar(ch);
    }
    close(fd_arr[0]);
    exit(0);
  } else {
    close(fd_arr[0]);
    for (i = 0; i < 10; i++) {
      ch = 'a' + i;
      write(fd_arr[1], &ch, 1);
    }
    close(fd_arr[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1c(%rbp),%rdi
call   1060 <pipe@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    11f2 <main+0x82>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jge    11e3 <main+0x73>
mov    -0x1c(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl -0x21(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b1 <main+0x41>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jge    1233 <main+0xc3>
mov    -0x20(%rbp),%eax
add    $0x61,%eax
mov    %al,-0x21(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1201 <main+0x91>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1289 <main+0x119>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
movb   $0x61,0x7(%rsp)
mov    0xc(%rsp),%edi
lea    0x7(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movb   $0x62,0x7(%rsp)
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movb   $0x63,0x7(%rsp)
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movb   $0x64,0x7(%rsp)
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movb   $0x65,0x7(%rsp)
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movb   $0x66,0x7(%rsp)
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movb   $0x67,0x7(%rsp)
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movb   $0x68,0x7(%rsp)
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movb   $0x69,0x7(%rsp)
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movb   $0x6a,0x7(%rsp)
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
lea    0x7(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = call i32 (...) @fork()
store i32 %12, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %2
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i32 @close(i32 %16)
store i32 0, i32* %8
br label %18
18: ; preds = %27, %14
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%23 = load i32, i32* %22
%24 = call i32 @read(i32 %23, i8* %9, i32 1)
%25 = load i8, i8* %9
%26 = call i32 @putchar(i8 signext %25)
br label %27
27: ; preds = %21
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %18
30: ; preds = %18
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%32 = load i32, i32* %31
%33 = call i32 @close(i32 %32)
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %2
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
store i32 0, i32* %8
br label %39
39: ; preds = %49, %35
%40 = load i32, i32* %8
%41 = icmp slt i32 %40, 10
br i1 %41, label %42, label %52
42: ; preds = %39
%43 = load i32, i32* %8
%44 = add nsw i32 97, %43
%45 = trunc i32 %44 to i8
store i8 %45, i8* %9
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @write(i32 %47, i8* %9, i32 1)
br label %49
49: ; preds = %42
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %39
52: ; preds = %39
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%54 = load i32, i32* %53
%55 = call i32 @close(i32 %54)
br label %56
56: ; preds = %52
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca i8
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = call i32 (...) @fork()
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %57
10: ; preds = %2
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* %6
%15 = call i32 @read(i32 %14, i8* %4, i32 1)
%16 = load i8, i8* %4
%17 = call i32 @putchar(i8 signext %16)
%18 = load i32, i32* %6
%19 = call i32 @read(i32 %18, i8* %4, i32 1)
%20 = load i8, i8* %4
%21 = call i32 @putchar(i8 signext %20)
%22 = load i32, i32* %6
%23 = call i32 @read(i32 %22, i8* %4, i32 1)
%24 = load i8, i8* %4
%25 = call i32 @putchar(i8 signext %24)
%26 = load i32, i32* %6
%27 = call i32 @read(i32 %26, i8* %4, i32 1)
%28 = load i8, i8* %4
%29 = call i32 @putchar(i8 signext %28)
%30 = load i32, i32* %6
%31 = call i32 @read(i32 %30, i8* %4, i32 1)
%32 = load i8, i8* %4
%33 = call i32 @putchar(i8 signext %32)
%34 = load i32, i32* %6
%35 = call i32 @read(i32 %34, i8* %4, i32 1)
%36 = load i8, i8* %4
%37 = call i32 @putchar(i8 signext %36)
%38 = load i32, i32* %6
%39 = call i32 @read(i32 %38, i8* %4, i32 1)
%40 = load i8, i8* %4
%41 = call i32 @putchar(i8 signext %40)
%42 = load i32, i32* %6
%43 = call i32 @read(i32 %42, i8* %4, i32 1)
%44 = load i8, i8* %4
%45 = call i32 @putchar(i8 signext %44)
%46 = load i32, i32* %6
%47 = call i32 @read(i32 %46, i8* %4, i32 1)
%48 = load i8, i8* %4
%49 = call i32 @putchar(i8 signext %48)
%50 = load i32, i32* %6
%51 = call i32 @read(i32 %50, i8* %4, i32 1)
%52 = load i8, i8* %4
%53 = call i32 @putchar(i8 signext %52)
%54 = load i32, i32* %6
%55 = call i32 @close(i32 %54)
%56 = call i32 @exit(i32 0)
unreachable
57: ; preds = %2
%58 = load i32, i32* %6
%59 = call i32 @close(i32 %58)
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i8 97, i8* %4
%61 = load i32, i32* %60
%62 = call i32 @write(i32 %61, i8* %4, i32 1)
store i8 98, i8* %4
%63 = load i32, i32* %60
%64 = call i32 @write(i32 %63, i8* %4, i32 1)
store i8 99, i8* %4
%65 = load i32, i32* %60
%66 = call i32 @write(i32 %65, i8* %4, i32 1)
store i8 100, i8* %4
%67 = load i32, i32* %60
%68 = call i32 @write(i32 %67, i8* %4, i32 1)
store i8 101, i8* %4
%69 = load i32, i32* %60
%70 = call i32 @write(i32 %69, i8* %4, i32 1)
store i8 102, i8* %4
%71 = load i32, i32* %60
%72 = call i32 @write(i32 %71, i8* %4, i32 1)
store i8 103, i8* %4
%73 = load i32, i32* %60
%74 = call i32 @write(i32 %73, i8* %4, i32 1)
store i8 104, i8* %4
%75 = load i32, i32* %60
%76 = call i32 @write(i32 %75, i8* %4, i32 1)
store i8 105, i8* %4
%77 = load i32, i32* %60
%78 = call i32 @write(i32 %77, i8* %4, i32 1)
store i8 106, i8* %4
%79 = load i32, i32* %60
%80 = call i32 @write(i32 %79, i8* %4, i32 1)
%81 = load i32, i32* %60
%82 = call i32 @close(i32 %81)
ret i32 0
}