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

/* Variables and functions */
int read(int, unsigned char *, int);
int write(int, unsigned char *, int);
int do_pipe(int in, int out) {
  unsigned char buf[1024];
  int len;
  len = read(in, buf, sizeof(buf));
  if (len <= 0)
    return -1;
  if (write(out, buf, len) != len)
    return -1;
  return len;
}


x86 assembly (clang, -O0):
<do_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jg     1164 <do_pipe+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <do_pipe+0x7a>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
call   1030 <write@plt>
cmp    -0x414(%rbp),%eax
je     1191 <do_pipe+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <do_pipe+0x7a>
mov    -0x414(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_pipe>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ebx
mov    %rsp,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1156 <do_pipe+0x36>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
mov    $0xffffffff,%eax
cmove  %ebp,%eax
jmp    115b <do_pipe+0x3b>
mov    $0xffffffff,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @do_pipe(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 1024)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp sle i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %24
14: ; preds = %2
%15 = load i32, i32* %5
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%17 = load i32, i32* %7
%18 = call i32 @write(i32 %15, i8* %16, i32 %17)
%19 = load i32, i32* %7
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 -1, i32* %3
br label %24
22: ; preds = %14
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %24
24: ; preds = %22, %21, %13
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
define i32 @do_pipe(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @read(i32 %0, i8* %4, i32 1024)
%6 = icmp slt i32 %5, 1
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = call i32 @write(i32 %1, i8* %4, i32 %5)
%9 = icmp eq i32 %8, %5
%10 = select i1 %9, i32 %5, i32 -1
br label %11
11: ; preds = %7, %2
%12 = phi i32 [ -1, %2 ], [ %10, %7 ]
ret i32 %12
}