#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 */
struct stat {
  scalar_t__ st_dev;
  scalar_t__ st_ino;
};

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ errx(int, char *, scalar_t__, ...);
int fstat(int, struct stat *);
int pipe(int *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  int pipefd[2];
  struct stat st1, st2;
  if (pipe(pipefd) == -1)
    err(1, "FAIL: pipe");
  if (fstat(pipefd[0], &st1) == -1)
    err(1, "FAIL: fstat st1");
  if (fstat(pipefd[1], &st2) == -1)
    err(1, "FAIL: fstat st2");
  if (st1.st_dev != st2.st_dev || st1.st_dev == 0 || st2.st_dev == 0)
    errx(1, "FAIL: wrong dev number %d %d", st1.st_dev, st2.st_dev);
  if (st1.st_ino == st2.st_ino)
    errx(1, "FAIL: inode numbers are equal: %d", st1.st_ino);
  close(pipefd[0]);
  close(pipefd[1]);
  printf("PASS\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1192 <main+0x32>
mov    $0x1,%edi
lea    0xe73(%rip),%rsi
call   1070 <err@plt>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    11b8 <main+0x58>
mov    $0x1,%edi
lea    0xe58(%rip),%rsi
call   1070 <err@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    11de <main+0x7e>
mov    $0x1,%edi
lea    0xe42(%rip),%rsi
call   1070 <err@plt>
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    1202 <main+0xa2>
cmpq   $0x0,-0x20(%rbp)
je     1202 <main+0xa2>
cmpq   $0x0,-0x30(%rbp)
jne    121d <main+0xbd>
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%edi
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1242 <main+0xe2>
mov    -0x18(%rbp),%rdx
mov    $0x1,%edi
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
lea    0xe11(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    %rsp,%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1182 <main+0x22>
lea    0xe88(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
mov    (%rsp),%edi
lea    0x18(%rsp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    11a5 <main+0x45>
lea    0xe70(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
mov    0x4(%rsp),%edi
lea    0x8(%rsp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    11c9 <main+0x69>
lea    0xe5c(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
mov    0x18(%rsp),%rdx
mov    0x8(%rsp),%rcx
test   %rcx,%rcx
je     11e2 <main+0x82>
test   %rdx,%rdx
je     11e2 <main+0x82>
cmp    %rcx,%rdx
je     11f5 <main+0x95>
lea    0xe42(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <errx@plt>
mov    0x20(%rsp),%rdx
cmp    0x10(%rsp),%rdx
jne    1214 <main+0xb4>
lea    0xe40(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <errx@plt>
mov    (%rsp),%edi
call   1050 <close@plt>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
lea    0xe3e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
@.str = [11 x i8] c"FAIL: pipe\00"
@.str.1 = [16 x i8] c"FAIL: fstat st1\00"
@.str.2 = [16 x i8] c"FAIL: fstat st2\00"
@.str.3 = [29 x i8] c"FAIL: wrong dev number %d %d\00"
@.str.4 = [34 x i8] c"FAIL: inode numbers are equal: %d\00"
@.str.5 = [6 x i8] c"PASS\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca %struct.stat
%4 = alloca %struct.stat
store i32 0, i32* %1
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%12 = load i32, i32* %11
%13 = call i32 @fstat(i32 %12, %struct.stat* %3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32 @fstat(i32 %19, %struct.stat* %4)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %17
%25 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%28 = load i64, i64* %27
%29 = icmp ne i64 %26, %28
br i1 %29, label %38, label %30
30: ; preds = %24
%31 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%32 = load i64, i64* %31
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%36 = load i64, i64* %35
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %34, %30, %24
%39 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%40 = load i64, i64* %39
%41 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%42 = load i64, i64* %41
%43 = call i32 (i32, i8*, i64, ...) @errx(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 %40, i64 %42)
br label %44
44: ; preds = %38, %34
%45 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%46 = load i64, i64* %45
%47 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%48 = load i64, i64* %47
%49 = icmp eq i64 %46, %48
br i1 %49, label %50, label %54
50: ; preds = %44
%51 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%52 = load i64, i64* %51
%53 = call i32 (i32, i8*, i64, ...) @errx(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i64 %52)
br label %54
54: ; preds = %50, %44
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%56 = load i32, i32* %55
%57 = call i32 @close(i32 %56)
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%59 = load i32, i32* %58
%60 = call i32 @close(i32 %59)
%61 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
@.str = [11 x i8] c"FAIL: pipe\00"
@.str.1 = [16 x i8] c"FAIL: fstat st1\00"
@.str.2 = [16 x i8] c"FAIL: fstat st2\00"
@.str.3 = [29 x i8] c"FAIL: wrong dev number %d %d\00"
@.str.4 = [34 x i8] c"FAIL: inode numbers are equal: %d\00"
@str = [5 x i8] c"PASS\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca %struct.stat
%3 = alloca %struct.stat
%4 = bitcast [2 x i32]* %1 to i8*
%5 = bitcast %struct.stat* %2 to i8*
%6 = bitcast %struct.stat* %3 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = load i32, i32* %7
%14 = call i32 @fstat(i32 %13, %struct.stat* %2)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @fstat(i32 %20, %struct.stat* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%27 = load i64, i64* %26
%28 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%29 = load i64, i64* %28
%30 = icmp ne i64 %27, %29
%31 = icmp eq i64 %27, 0
%32 = or i1 %31, %30
%33 = icmp eq i64 %29, 0
%34 = or i1 %33, %32
br i1 %34, label %35, label %37
35: ; preds = %25
%36 = call i32 (i32, i8*, i64, ...) @errx(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 %27, i64 %29)
br label %37
37: ; preds = %25, %35
%38 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%39 = load i64, i64* %38
%40 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%41 = load i64, i64* %40
%42 = icmp eq i64 %39, %41
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 (i32, i8*, i64, ...) @errx(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i64 %39)
br label %45
45: ; preds = %43, %37
%46 = load i32, i32* %7
%47 = call i32 @close(i32 %46)
%48 = load i32, i32* %19
%49 = call i32 @close(i32 %48)
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret i32 0
}