#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
char getchar();
scalar_t__ isalpha(char);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ putchar(int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ toupper(char);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fd[2], nbytes;
  pid_t pid;
  char readbuffer[14];
  char readc[1];
  char string[] = "Hello World! \n";
  if (pipe(fd) < 0) {
    perror("pipe error");
    exit(1);
  }
  if ((pid = fork()) < 0) {
    perror("fork error");
    exit(1);
  }
  if (pid) {
    close(fd[0]);
    char c[1];
    c[0] = -1;
    while (c[0] != 'q') {
      c[0] = getchar();
      write(fd[1], c, 1);
    }
    wait(NULL);
    close(fd[1]);
  } else {
    close(fd[1]);
    readc[0] = -1;
    while (readc[0] != 'q') {
      read(fd[0], readc, 1);
      if (isalpha(readc[0]))
        putchar(toupper(readc[0]));
    }
    close(fd[0]);
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe2a(%rip),%rax
mov    %rax,-0x36(%rbp)
mov    0xe28(%rip),%eax
mov    %eax,-0x2e(%rbp)
mov    0xe22(%rip),%ax
mov    %ax,-0x2a(%rbp)
mov    0xe1a(%rip),%al
mov    %al,-0x28(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0x0,%rax
jge    1220 <main+0x60>
lea    0xdfe(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    124b <main+0x8b>
lea    0xdde(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
je     12a5 <main+0xe5>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
movb   $0xff,-0x37(%rbp)
movsbl -0x37(%rbp),%eax
cmp    $0x71,%eax
je     128f <main+0xcf>
mov    $0x0,%al
call   1090 <getchar@plt>
mov    %al,-0x37(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x37(%rbp),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
jmp    1262 <main+0xa2>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <wait@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
jmp    1306 <main+0x146>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
movb   $0xff,-0x27(%rbp)
movsbl -0x27(%rbp),%eax
cmp    $0x71,%eax
je     12f7 <main+0x137>
mov    -0xc(%rbp),%edi
lea    -0x27(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
movsbl -0x27(%rbp),%edi
call   10a0 <isalpha@plt>
cmp    $0x0,%rax
je     12f2 <main+0x132>
movsbl -0x27(%rbp),%edi
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    12b1 <main+0xf1>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
js     123e <main+0x7e>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
js     1247 <main+0x87>
je     125d <main+0x9d>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
lea    0x7(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1090 <getchar@plt>
mov    %eax,%ebx
mov    %al,0x7(%rsp)
mov    0xc(%rsp),%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0x71,%bl
jne    1200 <main+0x40>
xor    %edi,%edi
call   10d0 <wait@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdbb(%rip),%rdi
jmp    124e <main+0x8e>
lea    0xdbd(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
movb   $0xff,0x6(%rsp)
lea    0x6(%rsp),%r14
jmp    1285 <main+0xc5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x71,%bl
je     12ba <main+0xfa>
mov    0x8(%rsp),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
movzbl 0x6(%rsp),%ebx
movsbl %bl,%ebp
mov    %ebp,%edi
call   10a0 <isalpha@plt>
test   %rax,%rax
je     1280 <main+0xc0>
mov    %ebp,%edi
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1280 <main+0xc0>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@__const.main.string = [15 x i8] c"Hello World! \0A\00"
@.str = [11 x i8] c"pipe error\00"
@.str.1 = [11 x i8] c"fork error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i64
%5 = alloca [14 x i8]
%6 = alloca [1 x i8]
%7 = alloca [15 x i8]
%8 = alloca [1 x i8]
store i32 0, i32* %1
%9 = bitcast [15 x i8]* %7 to i8*
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%11 = call i64 @pipe(i32* %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = call i64 (...) @fork()
store i64 %17, i64* %4
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %16
%23 = load i64, i64* %4
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %47
25: ; preds = %22
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
store i8 -1, i8* %29
br label %30
30: ; preds = %35, %25
%31 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 113
br i1 %34, label %35, label %42
35: ; preds = %30
%36 = call signext i8 (...) @getchar()
%37 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
store i8 %36, i8* %37
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%41 = call i32 @write(i32 %39, i8* %40, i32 1)
br label %30
42: ; preds = %30
%43 = call i32 @wait(i32* null)
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%45 = load i32, i32* %44
%46 = call i32 @close(i32 %45)
br label %77
47: ; preds = %22
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%49 = load i32, i32* %48
%50 = call i32 @close(i32 %49)
%51 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
store i8 -1, i8* %51
br label %52
52: ; preds = %71, %47
%53 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 113
br i1 %56, label %57, label %72
57: ; preds = %52
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%59 = load i32, i32* %58
%60 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%61 = call i32 @read(i32 %59, i8* %60, i32 1)
%62 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%63 = load i8, i8* %62
%64 = call i64 @isalpha(i8 signext %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %71
66: ; preds = %57
%67 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%68 = load i8, i8* %67
%69 = call i32 @toupper(i8 signext %68)
%70 = call i32 @putchar(i32 %69)
br label %71
71: ; preds = %66, %57
br label %52
72: ; preds = %52
%73 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%74 = load i32, i32* %73
%75 = call i32 @close(i32 %74)
%76 = call i32 @exit(i32 0)
unreachable
77: ; preds = %42
ret i32 0
}

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