#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__ ENODEV;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
void *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(scalar_t__);
int main(void) {
  int pipe_fd[2];
  void *pa;
  if (pipe(pipe_fd) == -1) {
    printf("Error at pipe(): %s\n", strerror(errno));
    return 2;
  }
  pa = mmap(NULL, 1024, PROT_READ, MAP_SHARED, pipe_fd[0], 0);
  if (pa == MAP_FAILED && errno == ENODEV) {
    printf("Test PASSED\n");
    close(pipe_fd[0]);
    close(pipe_fd[1]);
    return 0;
  }
  if (pa == MAP_FAILED) {
    printf("Test FAILED: Expect ENODEV, get: %s\n", strerror(errno));
  } else {
    printf("Text FAILED: mmap() succeded\n");
  }
  close(pipe_fd[0]);
  close(pipe_fd[1]);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    119d <main+0x4d>
mov    0x2e58(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    127e <main+0x12e>
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
mov    0x2e3b(%rip),%rax
mov    (%rax),%ecx
mov    -0xc(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x400,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2ded(%rip),%rcx
cmp    (%rcx),%rax
jne    1220 <main+0xd0>
mov    0x2ded(%rip),%rax
mov    (%rax),%rax
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%rax
jne    1220 <main+0xd0>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    127e <main+0x12e>
mov    -0x18(%rbp),%rax
mov    0x2d95(%rip),%rcx
cmp    (%rcx),%rax
jne    1259 <main+0x109>
mov    0x2d95(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1267 <main+0x117>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
je     11ad <main+0x4d>
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
mov    0x2e6a(%rip),%rax
mov    (%rax),%ecx
mov    (%rsp),%r8d
xor    %edi,%edi
mov    $0x400,%esi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
je     11d4 <main+0x74>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
jmp    1221 <main+0xc1>
mov    0x2e1c(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
lea    0xe3d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%eax
pop    %rcx
ret
mov    0x2df5(%rip),%rax
mov    (%rax),%rdi
mov    0x2de3(%rip),%rax
cmp    (%rax),%rdi
jne    120b <main+0xab>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%edi
call   1060 <close@plt>
mov    0x4(%rsp),%edi
call   1060 <close@plt>
xor    %eax,%eax
pop    %rcx
ret
call   1080 <strerror@plt>
lea    0xdfe(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%edi
call   1060 <close@plt>
mov    0x4(%rsp),%edi
call   1060 <close@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Error at pipe(): %s\0A\00"
@errno = global i64 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@ENODEV = global i64 0
@.str.1 = [13 x i8] c"Test PASSED\0A\00"
@.str.2 = [37 x i8] c"Test FAILED: Expect ENODEV, get: %s\0A\00"
@.str.3 = [30 x i8] c"Text FAILED: mmap() succeded\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i8*
store i32 0, i32* %1
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = call i8* @strerror(i64 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %9)
store i32 2, i32* %1
br label %49
11: ; preds = %0
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @MAP_SHARED
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%15 = load i32, i32* %14
%16 = call i8* @mmap(i32* null, i32 1024, i32 %12, i32 %13, i32 %15, i32 0)
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = load i8*, i8** @MAP_FAILED
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %32
20: ; preds = %11
%21 = load i64, i64* @errno
%22 = load i64, i64* @ENODEV
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
store i32 0, i32* %1
br label %49
32: ; preds = %20, %11
%33 = load i8*, i8** %3
%34 = load i8*, i8** @MAP_FAILED
%35 = icmp eq i8* %33, %34
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i64, i64* @errno
%38 = call i8* @strerror(i64 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %38)
br label %42
40: ; preds = %32
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %36
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%44 = load i32, i32* %43
%45 = call i32 @close(i32 %44)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @close(i32 %47)
store i32 1, i32* %1
br label %49
49: ; preds = %42, %24, %7
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@.str = [21 x i8] c"Error at pipe(): %s\0A\00"
@errno = global i64 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@ENODEV = global i64 0
@.str.2 = [37 x i8] c"Test FAILED: Expect ENODEV, get: %s\0A\00"
@str = [29 x i8] c"Text FAILED: mmap() succeded\00"
@str.4 = [12 x i8] c"Test PASSED\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 i32 @pipe(i32* %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i64, i64* @errno
%8 = call i8* @strerror(i64 %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %39
10: ; preds = %0
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @MAP_SHARED
%13 = load i32, i32* %3
%14 = call i8* @mmap(i32* null, i32 1024, i32 %11, i32 %12, i32 %13, i32 0)
%15 = load i8*, i8** @MAP_FAILED
%16 = icmp eq i8* %14, %15
br i1 %16, label %17, label %31
17: ; preds = %10
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENODEV
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0))
%23 = load i32, i32* %3
%24 = call i32 @close(i32 %23)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
br label %39
28: ; preds = %17
%29 = call i8* @strerror(i64 %18)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %33
31: ; preds = %10
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = load i32, i32* %3
%35 = call i32 @close(i32 %34)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
br label %39
39: ; preds = %33, %21, %6
%40 = phi i32 [ 2, %6 ], [ 0, %21 ], [ 1, %33 ]
ret i32 %40
}