#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*/ close(int);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
void PipeRead(int fd[2], int len) {
  char buf[100] = "\0";
  int nRead = 0;
  printf("Read Process : Wanna read %d characters.\n", len);
  close(fd[1]);
  nRead = read(fd[0], buf, len);
  printf("Read Process : Read %d characters\n", nRead);
}


x86 assembly (clang, -O0):
<PipeRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
movl   $0x0,-0x74(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%esi
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PipeRead>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
mov    0x4(%rbx),%edi
call   1040 <close@plt>
mov    (%rbx),%edi
mov    %rsp,%rsi
mov    %ebp,%edx
call   1050 <read@plt>
lea    0xea0(%rip),%rdi
mov    %eax,%esi
add    $0x68,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"Read Process : Wanna read %d characters.\0A\00"
@.str.1 = [35 x i8] c"Read Process : Read %d characters\0A\00"
define void @PipeRead(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = bitcast [100 x i8]* %5 to i8*
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32*, i32** %3
%11 = getelementptr inbounds i32, i32* %10, i64 1
%12 = load i32, i32* %11
%13 = call i32 @close(i32 %12)
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%18 = load i32, i32* %4
%19 = call i32 @read(i32 %16, i8* %17, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %20)
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"Read Process : Wanna read %d characters.\0A\00"
@.str.1 = [35 x i8] c"Read Process : Read %d characters\0A\00"
define void @PipeRead(i32* nocapture %0, i32 %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = getelementptr inbounds i32, i32* %0, i64 1
%7 = load i32, i32* %6
%8 = tail call i32 @close(i32 %7)
%9 = load i32, i32* %0
%10 = call i32 @read(i32 %9, i8* %4, i32 %1)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %10)
ret void
}