#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 */
scalar_t__ EINVAL;
int /*<<< orphan*/ abort();
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ ftruncate(int, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  int pip[2];
  if (pipe(pip) != 0) {
    perror("pipe");
    abort();
  }
  if (ftruncate(pip[0], 20) == 0 || errno != EINVAL) {
    perror("ftruncate 1");
    abort();
  }
  errno = 0;
  if (ftruncate(pip[1], 20) == 0 || errno != EINVAL) {
    perror("ftruncate 2");
    abort();
  }
  printf("pass\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
je     1195 <main+0x35>
lea    0xe77(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0xc(%rbp),%edi
mov    $0x14,%esi
call   1050 <ftruncate@plt>
cmp    $0x0,%rax
je     11c6 <main+0x66>
mov    0x2e2d(%rip),%rax
mov    (%rax),%rax
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%rax
je     11d9 <main+0x79>
lea    0xe38(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2e00(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    $0x14,%esi
call   1050 <ftruncate@plt>
cmp    $0x0,%rax
je     1218 <main+0xb8>
mov    0x2ddb(%rip),%rax
mov    (%rax),%rax
mov    0x2dc9(%rip),%rcx
cmp    (%rcx),%rax
je     122b <main+0xcb>
lea    0xdf2(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
lea    0xdeb(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rdi
call   1060 <pipe@plt>
test   %rax,%rax
jne    11ce <main+0x6e>
mov    (%rsp),%edi
mov    $0x14,%esi
call   1050 <ftruncate@plt>
test   %rax,%rax
je     11d7 <main+0x77>
mov    0x2e56(%rip),%rbx
mov    (%rbx),%rax
mov    0x2e44(%rip),%r14
cmp    (%r14),%rax
jne    11d7 <main+0x77>
movq   $0x0,(%rbx)
mov    0x4(%rsp),%edi
mov    $0x14,%esi
call   1050 <ftruncate@plt>
test   %rax,%rax
je     11ea <main+0x8a>
mov    (%rbx),%rax
cmp    (%r14),%rax
jne    11ea <main+0x8a>
lea    0xe5b(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe2b(%rip),%rdi
jmp    11de <main+0x7e>
lea    0xe27(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xe20(%rip),%rdi
jmp    11de <main+0x7e>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.1 = [12 x i8] c"ftruncate 1\00"
@.str.2 = [12 x i8] c"ftruncate 2\00"
@.str.3 = [6 x i8] c"pass\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
store i32 0, i32* %1
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%4 = call i64 @pipe(i32* %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @abort()
unreachable
9: ; preds = %0
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%11 = load i32, i32* %10
%12 = call i64 @ftruncate(i32 %11, i32 20)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %9
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINVAL
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14, %9
%19 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %14
store i64 0, i64* @errno
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i64 @ftruncate(i32 %23, i32 20)
%25 = icmp eq i64 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %21
%27 = load i64, i64* @errno
%28 = load i64, i64* @EINVAL
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26, %21
%31 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 (...) @abort()
unreachable
33: ; preds = %26
%34 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.1 = [12 x i8] c"ftruncate 1\00"
@.str.2 = [12 x i8] c"ftruncate 2\00"
@str = [5 x i8] c"pass\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i64 @pipe(i32* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @abort()
unreachable
9: ; preds = %0
%10 = load i32, i32* %3
%11 = call i64 @ftruncate(i32 %10, i32 20)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINVAL
%16 = icmp eq i64 %14, %15
br i1 %16, label %20, label %17
17: ; preds = %13, %9
%18 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 (...) @abort()
unreachable
20: ; preds = %13
store i64 0, i64* @errno
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i64 @ftruncate(i32 %22, i32 20)
%24 = icmp eq i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = load i64, i64* @errno
%27 = load i64, i64* @EINVAL
%28 = icmp eq i64 %26, %27
br i1 %28, label %32, label %29
29: ; preds = %25, %20
%30 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 (...) @abort()
unreachable
32: ; preds = %25
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%34 = call i32 @exit(i32 0)
unreachable
}