#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*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int fsync(int);
int pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(scalar_t__);
int main(void) {
  int fd[2];
  if (pipe(fd) == -1) {
    printf("fsync/7-1.c"
           " Test UNRESOLVED: Error at pipe: %s\n",
           strerror(errno));
    exit(2);
  }
  if (fsync(fd[1]) == -1 && errno == EINVAL) {
    printf("Got EINVAL when fsync on pipe\n");
    printf("Test PASSED\n");
    close(fd[0]);
    close(fd[1]);
    exit(0);
  } else {
    printf("fsync/7-1.c"
           " Test Fail: Expect EINVAL, get: %s\n",
           strerror(errno));
    close(fd[0]);
    close(fd[1]);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11ab <main+0x4b>
mov    0x2e58(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%edi
call   1060 <fsync@plt>
cmp    $0xffffffff,%eax
jne    1209 <main+0xa9>
mov    0x2e1d(%rip),%rax
mov    (%rax),%rax
mov    0x2e0b(%rip),%rcx
cmp    (%rcx),%rax
jne    1209 <main+0xa9>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11a8 <main+0x38>
mov    0x2e5b(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xe6c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x4(%rsp),%edi
call   1070 <fsync@plt>
mov    0x2e28(%rip),%rcx
mov    (%rcx),%rdi
cmp    $0xffffffff,%eax
jne    11fc <main+0x8c>
mov    0x2e11(%rip),%rax
cmp    (%rax),%rdi
jne    11fc <main+0x8c>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%edi
call   1050 <close@plt>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>
call   1090 <strerror@plt>
lea    0xe28(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%edi
call   1050 <close@plt>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"fsync/7-1.c Test UNRESOLVED: Error at pipe: %s\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.1 = [31 x i8] c"Got EINVAL when fsync on pipe\0A\00"
@.str.2 = [13 x i8] c"Test PASSED\0A\00"
@.str.3 = [47 x i8] c"fsync/7-1.c Test Fail: Expect EINVAL, get: %s\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 i32 @pipe(i32* %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i64, i64* @errno
%8 = call i8* @strerror(i64 %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = call i32 @exit(i32 2)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @fsync(i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %30
16: ; preds = %11
%17 = load i64, i64* @errno
%18 = load i64, i64* @EINVAL
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %16, %11
%31 = load i64, i64* @errno
%32 = call i8* @strerror(i64 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%35 = load i32, i32* %34
%36 = call i32 @close(i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
%40 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [48 x i8] c"fsync/7-1.c Test UNRESOLVED: Error at pipe: %s\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.3 = [47 x i8] c"fsync/7-1.c Test Fail: Expect EINVAL, get: %s\0A\00"
@str = [30 x i8] c"Got EINVAL when fsync on pipe\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 %11
6: ; preds = %0
%7 = load i64, i64* @errno
%8 = call i8* @strerror(i64 %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = call i32 @exit(i32 2)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @fsync(i32 %13)
%15 = icmp eq i32 %14, -1
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINVAL
%18 = icmp eq i64 %16, %17
%19 = select i1 %15, i1 %18, i1 false
br i1 %19, label %20, label %28
20: ; preds = %11
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%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 = load i32, i32* %12
%26 = call i32 @close(i32 %25)
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %11
%29 = call i8* @strerror(i64 %16)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = load i32, i32* %3
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* %12
%34 = call i32 @close(i32 %33)
%35 = call i32 @exit(i32 1)
unreachable
}