#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__ ssize_t;

/* Variables and functions */
int fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, scalar_t__, ...);
scalar_t__ read(int, char *, int);
scalar_t__ write(int, char *, int);
int main() {
  int pp[2];
  int son;
  pipe(pp);
  son = fork();
  if (son == 0) {
    char buf[13] = {0};
    ssize_t size;
    size = read(pp[0], buf, 12);
    if (size > 0) {
      printf("received: [%s]\n", buf);
    }
  } else if (son > 0) {
    char buf[13] = "我hello";
    ssize_t size;
    size = write(pp[1], buf, 7);
    if (size > 0) {
      printf("Send: %d bytes, buf:%s\n", size, buf);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11d3 <main+0x73>
lea    -0x1d(%rbp),%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1050 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0xc,%edx
call   1070 <read@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    11ce <main+0x6e>
lea    -0x1d(%rbp),%rsi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    123a <main+0xda>
cmpl   $0x0,-0x10(%rbp)
jle    1235 <main+0xd5>
mov    0xe44(%rip),%rax
mov    %rax,-0x35(%rbp)
mov    0xe42(%rip),%eax
mov    %eax,-0x2d(%rbp)
mov    0xe3d(%rip),%al
mov    %al,-0x29(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x35(%rbp),%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jle    1230 <main+0xd0>
mov    -0x40(%rbp),%rsi
lea    -0x35(%rbp),%rdx
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1235 <main+0xd5>
jmp    123a <main+0xda>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11ae <main+0x5e>
jle    11e6 <main+0x96>
movabs $0x6f6c6c65689188e6,%rax
6c 6c 6f
mov    %rax,(%rsp)
movq   $0x6f6c6c,0x5(%rsp)
mov    0x14(%rsp),%edi
mov    %rsp,%rsi
mov    $0x7,%edx
call   1030 <write@plt>
test   %rax,%rax
jle    11e6 <main+0x96>
lea    0xe71(%rip),%rdi
mov    %rsp,%rdx
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e6 <main+0x96>
movq   $0x0,0x5(%rsp)
movq   $0x0,(%rsp)
mov    0x10(%rsp),%edi
mov    %rsp,%rsi
mov    $0xc,%edx
call   1060 <read@plt>
test   %rax,%rax
jle    11e6 <main+0x96>
lea    0xe24(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"received: [%s]\0A\00"
@__const.main.buf = [13 x i8] c"\E6\88\91hello\00\00\00\00\00"
@.str.1 = [24 x i8] c"Send: %d bytes, buf:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca [13 x i8]
%5 = alloca i64
%6 = alloca [13 x i8]
%7 = alloca i64
store i32 0, i32* %1
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = call i32 (...) @fork()
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %0
%14 = bitcast [13 x i8]* %4 to i8*
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 0
%18 = call i64 @read(i32 %16, i8* %17, i32 12)
store i64 %18, i64* %5
%19 = load i64, i64* %5
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 0
%23 = ptrtoint i8* %22 to i64
%24 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 %23)
br label %25
25: ; preds = %21, %13
br label %43
26: ; preds = %0
%27 = load i32, i32* %3
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %42
29: ; preds = %26
%30 = bitcast [13 x i8]* %6 to i8*
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%32 = load i32, i32* %31
%33 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%34 = call i64 @write(i32 %32, i8* %33, i32 7)
store i64 %34, i64* %7
%35 = load i64, i64* %7
%36 = icmp sgt i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %29
%38 = load i64, i64* %7
%39 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%40 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %38, i8* %39)
br label %41
41: ; preds = %37, %29
br label %42
42: ; preds = %41, %26
br label %43
43: ; preds = %42, %25
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"received: [%s]\0A\00"
@__const.main.buf = [13 x i8] c"\E6\88\91hello\00\00\00\00\00"
@.str.1 = [24 x i8] c"Send: %d bytes, buf:%s\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [13 x i8]
%3 = alloca [13 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %0
%10 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%11 = load i32, i32* %5
%12 = call i64 @read(i32 %11, i8* %10, i32 12)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = ptrtoint [13 x i8]* %2 to i64
%16 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 %15)
br label %17
17: ; preds = %14, %9
br label %29
18: ; preds = %0
%19 = icmp sgt i32 %7, 0
br i1 %19, label %20, label %29
20: ; preds = %18
%21 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i64 @write(i32 %23, i8* %21, i32 7)
%25 = icmp sgt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %24, i8* %21)
br label %28
28: ; preds = %26, %20
br label %29
29: ; preds = %18, %28, %17
ret i32 0
}