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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  int pipefd[2] = {0};
  if (pipe(pipefd) < 0) {
    perror("pipe");
    exit(1);
  }
  FILE *write_ptr = fdopen(pipefd[1], "w");
  fprintf(write_ptr, "Hello_world\n");
  fflush(write_ptr);
  char read_str[255] = {0};
  FILE *read_ptr = fdopen(pipefd[0], "r");
  fscanf(read_ptr, "%s", read_str);
  printf("Pipe read: %s\n", read_str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    11db <main+0x4b>
lea    0xe34(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xe20(%rip),%rsi
call   1090 <fdopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <fflush@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%edi
lea    0xdf0(%rip),%rsi
call   1090 <fdopen@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xdd1(%rip),%rsi
call   1050 <fscanf@plt>
lea    -0x120(%rbp),%rsi
lea    0xdc1(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x110,%rsp
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
test   %rax,%rax
js     1287 <main+0x107>
mov    0xc(%rsp),%edi
lea    0xe56(%rip),%rsi
call   1070 <fdopen@plt>
mov    %rax,%rbx
lea    0xe49(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fflush@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0xff(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
mov    0x8(%rsp),%edi
lea    0xdc3(%rip),%rsi
call   1070 <fdopen@plt>
lea    0xdb9(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rax,%rdi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
lea    0xda5(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
ret
lea    0xd72(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"Hello_world\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [15 x i8] c"Pipe read: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32*
%4 = alloca [255 x i8]
%5 = alloca i32*
store i32 0, i32* %1
%6 = bitcast [2 x i32]* %2 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32* @fdopen(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %3
%17 = load i32*, i32** %3
%18 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32*, i32** %3
%20 = call i32 @fflush(i32* %19)
%21 = bitcast [255 x i8]* %4 to i8*
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%23 = load i32, i32* %22
%24 = call i32* @fdopen(i32 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %24, i32** %5
%25 = load i32*, i32** %5
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%27 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"Hello_world\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [15 x i8] c"Pipe read: %s\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [255 x i8]
%3 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%4 = bitcast i64* %1 to i32*
%5 = call i64 @pipe(i32* %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = bitcast i64* %1 to [2 x i32]*
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32* @fdopen(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 12, i64 1, i32* %14)
%16 = call i32 @fflush(i32* %14)
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%18 = load i32, i32* %4
%19 = call i32* @fdopen(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %17)
%21 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %17)
ret i32 0
}