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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
int main() {
  int MAX_BUF = 3072;
  char buf[MAX_BUF];
  int fd_cpu;
  int fd_disk;
  int fd_mem;
  fd_cpu = open("../IO/CPU_pipe", O_RDONLY);
  fd_disk = open("../IO/disk_pipe", O_RDONLY);
  fd_mem = open("../IO/memory_pipe", O_RDONLY);
  for (;;) {
    while (read(fd_cpu, buf, MAX_BUF) > 0)
      printf("Received cpu: %s\n", buf);
    while (read(fd_disk, buf, MAX_BUF) > 0)
      printf("Received disk: %s\n", buf);
    while (read(fd_mem, buf, MAX_BUF) > 0)
      printf("Received memory: %s\n", buf);
  }
  close(fd_cpu);
  close(fd_disk);
  close(fd_mem);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc00,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0xe73(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x24(%rbp)
jmp    11b9 <main+0x89>
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jle    11e7 <main+0xb7>
mov    -0x30(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
jmp    11b9 <main+0x89>
jmp    11ec <main+0xbc>
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jle    121a <main+0xea>
mov    -0x30(%rbp),%rsi
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
jmp    11ec <main+0xbc>
jmp    121f <main+0xef>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jle    124d <main+0x11d>
mov    -0x30(%rbp),%rsi
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
jmp    121f <main+0xef>
jmp    11b4 <main+0x84>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc08,%rsp
mov    0x2ea0(%rip),%rbx
mov    (%rbx),%esi
lea    0xeaf(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%r14d
mov    (%rbx),%esi
lea    0xead(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%r15d
mov    (%rbx),%esi
lea    0xeac(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%r12d
mov    %rsp,%rbp
lea    0xebe(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rbx
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xc00,%edx
call   1040 <read@plt>
test   %rax,%rax
lea    0xe84(%rip),%r13
jle    11d0 <main+0xa0>
nop
mov    %r13,%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xc00,%edx
call   1040 <read@plt>
test   %rax,%rax
jg     11b0 <main+0x80>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xc00,%edx
call   1040 <read@plt>
test   %rax,%rax
mov    %rbx,%r13
jle    1210 <main+0xe0>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xc00,%edx
call   1040 <read@plt>
test   %rax,%rax
jg     11f0 <main+0xc0>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0xc00,%edx
call   1040 <read@plt>
test   %rax,%rax
lea    0xe2c(%rip),%rbx
jle    1190 <main+0x60>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0xc00,%edx
call   1040 <read@plt>
test   %rax,%rax
jg     1230 <main+0x100>
jmp    1190 <main+0x60>

LLVM IR (-O0):
@.str = [15 x i8] c"../IO/CPU_pipe\00"
@O_RDONLY = global i32 0
@.str.1 = [16 x i8] c"../IO/disk_pipe\00"
@.str.2 = [18 x i8] c"../IO/memory_pipe\00"
@.str.3 = [18 x i8] c"Received cpu: %s\0A\00"
@.str.4 = [19 x i8] c"Received disk: %s\0A\00"
@.str.5 = [21 x i8] c"Received memory: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 3072, i32* %2
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i8, i64 %9
store i64 %9, i64* %4
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %16)
store i32 %17, i32* %7
br label %18
18: ; preds = %42, %0
br label %19
19: ; preds = %24, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %2
%22 = call i64 @read(i32 %20, i8* %11, i32 %21)
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %11)
br label %19
26: ; preds = %19
br label %27
27: ; preds = %32, %26
%28 = load i32, i32* %6
%29 = load i32, i32* %2
%30 = call i64 @read(i32 %28, i8* %11, i32 %29)
%31 = icmp sgt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %11)
br label %27
34: ; preds = %27
br label %35
35: ; preds = %40, %34
%36 = load i32, i32* %7
%37 = load i32, i32* %2
%38 = call i64 @read(i32 %36, i8* %11, i32 %37)
%39 = icmp sgt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %11)
br label %35
42: ; preds = %35
br label %18
}

LLVM IR (-O2):
@.str = [15 x i8] c"../IO/CPU_pipe\00"
@O_RDONLY = global i32 0
@.str.1 = [16 x i8] c"../IO/disk_pipe\00"
@.str.2 = [18 x i8] c"../IO/memory_pipe\00"
@.str.3 = [18 x i8] c"Received cpu: %s\0A\00"
@.str.4 = [19 x i8] c"Received disk: %s\0A\00"
@.str.5 = [21 x i8] c"Received memory: %s\0A\00"
define i32 @main() {
%1 = alloca [3072 x i8]
%2 = getelementptr inbounds [3072 x i8], [3072 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %22, %0
%10 = call i64 @read(i32 %4, i8* %2, i32 3072)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %15, %9
%13 = call i64 @read(i32 %6, i8* %2, i32 3072)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %23, label %19
15: ; preds = %9, %15
%16 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%17 = call i64 @read(i32 %4, i8* %2, i32 3072)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %15, label %12
19: ; preds = %23, %12
%20 = call i64 @read(i32 %8, i8* %2, i32 3072)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %27, %19
br label %9
23: ; preds = %12, %23
%24 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%25 = call i64 @read(i32 %6, i8* %2, i32 3072)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %23, label %19
27: ; preds = %19, %27
%28 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%29 = call i64 @read(i32 %8, i8* %2, i32 3072)
%30 = icmp sgt i64 %29, 0
br i1 %30, label %27, label %22
}