#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 /*<<< orphan*/ exit(int);
scalar_t__ pipe(int *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ read(int, char *, int);
void *tf(void *arg) {
  int fds[2];
  if (pipe(fds) != 0) {
    puts("pipe failed");
    exit(1);
  }
  char buf[10];
  read(fds[0], buf, sizeof(buf));
  puts("read returned");
  exit(1);
}


x86 assembly (clang, -O0):
<tf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <pipe@plt>
cmp    $0x0,%rax
je     1175 <tf+0x35>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<tf>:
sub    $0x18,%rsp
lea    0x4(%rsp),%rdi
call   1040 <pipe@plt>
test   %rax,%rax
jne    116f <tf+0x2f>
mov    0x4(%rsp),%edi
lea    0xe(%rsp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
lea    0xe9f(%rip),%rdi
jmp    1176 <tf+0x36>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"pipe failed\00"
@.str.1 = [14 x i8] c"read returned\00"
define i8* @tf(i8* %0) {
%2 = alloca i8*
%3 = alloca [2 x i32]
%4 = alloca [10 x i8]
store i8* %0, i8** %2
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%15 = call i32 @read(i32 %13, i8* %14, i32 10)
%16 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"pipe failed\00"
@.str.1 = [14 x i8] c"read returned\00"
define noalias i8* @tf(i8* nocapture readnone %0) {
%2 = alloca [2 x i32]
%3 = alloca [10 x i8]
%4 = bitcast [2 x i32]* %2 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* %5
%14 = call i32 @read(i32 %13, i8* %12, i32 10)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
}