#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(int argc, char **argv) {
  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    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1199 <main+0x39>
mov    $0x1,%edi
lea    0xe6c(%rip),%rsi
call   1070 <err@plt>
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    11bf <main+0x5f>
mov    $0x1,%edi
lea    0xe51(%rip),%rsi
call   1070 <err@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    11e5 <main+0x85>
mov    $0x1,%edi
lea    0xe3b(%rip),%rsi
call   1070 <err@plt>
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    1209 <main+0xa9>
cmpq   $0x0,-0x28(%rbp)
je     1209 <main+0xa9>
cmpq   $0x0,-0x38(%rbp)
jne    1224 <main+0xc4>
mov    -0x28(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x1,%edi
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    1249 <main+0xe9>
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
lea    0xe0a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca %struct.stat
%8 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%16 = load i32, i32* %15
%17 = call i32 @fstat(i32 %16, %struct.stat* %7)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @fstat(i32 %23, %struct.stat* %8)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
%29 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%30 = load i64, i64* %29
%31 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%32 = load i64, i64* %31
%33 = icmp ne i64 %30, %32
br i1 %33, label %42, label %34
34: ; preds = %28
%35 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%36 = load i64, i64* %35
%37 = icmp eq i64 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%40 = load i64, i64* %39
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %38, %34, %28
%43 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%44 = load i64, i64* %43
%45 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%46 = load i64, i64* %45
%47 = call i32 (i32, i8*, i64, ...) @errx(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 %44, i64 %46)
br label %48
48: ; preds = %42, %38
%49 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%50 = load i64, i64* %49
%51 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%52 = load i64, i64* %51
%53 = icmp eq i64 %50, %52
br i1 %53, label %54, label %58
54: ; preds = %48
%55 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%56 = load i64, i64* %55
%57 = call i32 (i32, i8*, i64, ...) @errx(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i64 %56)
br label %58
58: ; preds = %54, %48
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%60 = load i32, i32* %59
%61 = call i32 @close(i32 %60)
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%63 = load i32, i32* %62
%64 = call i32 @close(i32 %63)
%65 = 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(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca %struct.stat
%5 = alloca %struct.stat
%6 = bitcast [2 x i32]* %3 to i8*
%7 = bitcast %struct.stat* %4 to i8*
%8 = bitcast %struct.stat* %5 to i8*
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* %9
%16 = call i32 @fstat(i32 %15, %struct.stat* %4)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i32 @fstat(i32 %22, %struct.stat* %5)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %20
%28 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%29 = load i64, i64* %28
%30 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%31 = load i64, i64* %30
%32 = icmp ne i64 %29, %31
%33 = icmp eq i64 %29, 0
%34 = or i1 %33, %32
%35 = icmp eq i64 %31, 0
%36 = or i1 %35, %34
br i1 %36, label %37, label %39
37: ; preds = %27
%38 = call i32 (i32, i8*, i64, ...) @errx(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 %29, i64 %31)
br label %39
39: ; preds = %27, %37
%40 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%41 = load i64, i64* %40
%42 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 1
%43 = load i64, i64* %42
%44 = icmp eq i64 %41, %43
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = call i32 (i32, i8*, i64, ...) @errx(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i64 %41)
br label %47
47: ; preds = %45, %39
%48 = load i32, i32* %9
%49 = call i32 @close(i32 %48)
%50 = load i32, i32* %21
%51 = call i32 @close(i32 %50)
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret i32 0
}