#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 */
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int errno;
int fcntl_(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int _check_setfl_ignored(int fd, int ignored_flag, const char *flagname) {
  int flags;
  int newflags;
  int rc;
  printf("Check fcntl(%d, F_SETFL, +%s) is ignored... ", fd, flagname);
  flags = fcntl_(fd, F_GETFL, 0);
  if (flags == -1) {
    printf("[FAIL]: fcntl(F_GETFL) failed, rc=%d errno=%d (%s)\n", flags, errno,
           strerror(errno));
    return 1;
  }
  if (flags & ignored_flag) {
    printf("[FAIL]: fcntl(F_GETFL) included %s (%x) in %x\n", flagname,
           ignored_flag, flags);
    return 1;
  }
  rc = fcntl_(fd, F_SETFL, (flags | ignored_flag));
  if (rc == -1) {
    printf("[FAIL]: fcntl(F_SETFL) failed, rc=%d errno=%d (%s)\n", rc, errno,
           strerror(errno));
    return 1;
  }
  newflags = fcntl_(fd, F_GETFL, 0);
  if (newflags != flags) {
    printf("[FAIL]: fcntl(F_SETFL) changed value of %s (%x) flag\n", flagname,
           ignored_flag);
    return 1;
  }
  printf("[OK]\n");
  return 0;
}


x86 assembly (clang, -O0):
<_check_setfl_ignored>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl_@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ba <_check_setfl_ignored+0x8a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    %rax,%rcx
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ac <_check_setfl_ignored+0x17c>
mov    -0x1c(%rbp),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     11ed <_check_setfl_ignored+0xbd>
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ac <_check_setfl_ignored+0x17c>
mov    -0x8(%rbp),%edi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
or     -0xc(%rbp),%edx
call   1030 <fcntl_@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1254 <_check_setfl_ignored+0x124>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    %rax,%rcx
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ac <_check_setfl_ignored+0x17c>
mov    -0x8(%rbp),%edi
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl_@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1297 <_check_setfl_ignored+0x167>
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ac <_check_setfl_ignored+0x17c>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_check_setfl_ignored>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xea9(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e69(%rip),%r12
mov    (%r12),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <fcntl_@plt>
cmp    $0xffffffff,%eax
je     1198 <_check_setfl_ignored+0x58>
mov    %eax,%ebx
test   %r14d,%eax
je     11d2 <_check_setfl_ignored+0x92>
lea    0xeda(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c0 <_check_setfl_ignored+0x80>
mov    0x2e39(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1060 <strerror@plt>
lea    0xe7e(%rip),%rdi
mov    $0xffffffff,%esi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edx
or     %r14d,%edx
mov    %ebp,%edi
call   1040 <fcntl_@plt>
cmp    $0xffffffff,%eax
je     120e <_check_setfl_ignored+0xce>
mov    (%r12),%esi
xor    %r12d,%r12d
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <fcntl_@plt>
cmp    %ebx,%eax
jne    1227 <_check_setfl_ignored+0xe7>
lea    0xef3(%rip),%rdi
call   1030 <puts@plt>
jmp    11c6 <_check_setfl_ignored+0x86>
mov    0x2dc3(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1060 <strerror@plt>
lea    0xe6b(%rip),%rdi
jmp    11af <_check_setfl_ignored+0x6f>
lea    0xe96(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c0 <_check_setfl_ignored+0x80>

LLVM IR (-O0):
@.str = [45 x i8] c"Check fcntl(%d, F_SETFL, +%s) is ignored... \00"
@F_GETFL = global i32 0
@.str.1 = [52 x i8] c"[FAIL]: fcntl(F_GETFL) failed, rc=%d errno=%d (%s)\0A\00"
@errno = global i32 0
@.str.2 = [47 x i8] c"[FAIL]: fcntl(F_GETFL) included %s (%x) in %x\0A\00"
@F_SETFL = global i32 0
@.str.3 = [52 x i8] c"[FAIL]: fcntl(F_SETFL) failed, rc=%d errno=%d (%s)\0A\00"
@.str.4 = [54 x i8] c"[FAIL]: fcntl(F_SETFL) changed value of %s (%x) flag\0A\00"
@.str.5 = [6 x i8] c"[OK]\0A\00"
define i32 @_check_setfl_ignored(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%11 = load i32, i32* %5
%12 = load i8*, i8** %7
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %12)
%14 = load i32, i32* %5
%15 = load i32, i32* @F_GETFL
%16 = call i32 @fcntl_(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %25
19: ; preds = %3
%20 = load i32, i32* %8
%21 = load i32, i32* @errno
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %21, i8* %23)
store i32 1, i32* %4
br label %63
25: ; preds = %3
%26 = load i32, i32* %8
%27 = load i32, i32* %6
%28 = and i32 %26, %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i8*, i8** %7
%32 = load i32, i32* %6
%33 = load i32, i32* %8
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %31, i32 %32, i32 %33)
store i32 1, i32* %4
br label %63
35: ; preds = %25
%36 = load i32, i32* %5
%37 = load i32, i32* @F_SETFL
%38 = load i32, i32* %8
%39 = load i32, i32* %6
%40 = or i32 %38, %39
%41 = call i32 @fcntl_(i32 %36, i32 %37, i32 %40)
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %50
44: ; preds = %35
%45 = load i32, i32* %10
%46 = load i32, i32* @errno
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %45, i32 %46, i8* %48)
store i32 1, i32* %4
br label %63
50: ; preds = %35
%51 = load i32, i32* %5
%52 = load i32, i32* @F_GETFL
%53 = call i32 @fcntl_(i32 %51, i32 %52, i32 0)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = load i32, i32* %8
%56 = icmp ne i32 %54, %55
br i1 %56, label %57, label %61
57: ; preds = %50
%58 = load i8*, i8** %7
%59 = load i32, i32* %6
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i8* %58, i32 %59)
store i32 1, i32* %4
br label %63
61: ; preds = %50
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %4
br label %63
63: ; preds = %61, %57, %44, %30, %19
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
@.str = [45 x i8] c"Check fcntl(%d, F_SETFL, +%s) is ignored... \00"
@F_GETFL = global i32 0
@.str.1 = [52 x i8] c"[FAIL]: fcntl(F_GETFL) failed, rc=%d errno=%d (%s)\0A\00"
@errno = global i32 0
@.str.2 = [47 x i8] c"[FAIL]: fcntl(F_GETFL) included %s (%x) in %x\0A\00"
@F_SETFL = global i32 0
@.str.3 = [52 x i8] c"[FAIL]: fcntl(F_SETFL) failed, rc=%d errno=%d (%s)\0A\00"
@.str.4 = [54 x i8] c"[FAIL]: fcntl(F_SETFL) changed value of %s (%x) flag\0A\00"
@str = [5 x i8] c"[OK]\00"
define i32 @_check_setfl_ignored(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %2)
%5 = load i32, i32* @F_GETFL
%6 = tail call i32 @fcntl_(i32 %0, i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 -1, i32 %9, i8* %10)
br label %34
12: ; preds = %3
%13 = and i32 %6, %1
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 %1, i32 %6)
br label %34
17: ; preds = %12
%18 = load i32, i32* @F_SETFL
%19 = or i32 %6, %1
%20 = tail call i32 @fcntl_(i32 %0, i32 %18, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @errno
%24 = tail call i8* @strerror(i32 %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 -1, i32 %23, i8* %24)
br label %34
26: ; preds = %17
%27 = load i32, i32* @F_GETFL
%28 = tail call i32 @fcntl_(i32 %0, i32 %27, i32 0)
%29 = icmp eq i32 %28, %6
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32 %1)
br label %34
32: ; preds = %26
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %32, %30, %22, %15, %8
%35 = phi i32 [ 1, %8 ], [ 1, %15 ], [ 1, %22 ], [ 1, %30 ], [ 0, %32 ]
ret i32 %35
}