#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int FD_CLOEXEC;
int /*<<< orphan*/ F_GETFD;
int /*<<< orphan*/ F_SETFD;
int fcntl(int, int /*<<< orphan*/, ...);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void cloexec(FILE *f) {
  int fd = fileno(f);
  int fl, rc;
  fl = fcntl(fd, F_GETFD);
  rc = fcntl(fd, F_SETFD, fl | FD_CLOEXEC);
  (void)rc;
  fl = fcntl(fd, F_GETFD);
  if (!(fl & FD_CLOEXEC))
    fprintf(stderr, "cloexec failed!\n");
}


x86 assembly (clang, -O0):
<cloexec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fileno@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
mov    0x2e5c(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e30(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11c0 <cloexec+0x90>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cloexec>:
push   %r15
push   %r14
push   %rbx
call   1050 <fileno@plt>
mov    %eax,%ebx
mov    0x2e85(%rip),%r14
mov    (%r14),%esi
mov    %eax,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    0x2e82(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e71(%rip),%r15
or     (%r15),%eax
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    (%r14),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,(%r15)
je     1184 <cloexec+0x54>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@F_GETFD = global i32 0
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"cloexec failed!\0A\00"
define void @cloexec(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = call i32 @fileno(i32* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = load i32, i32* @F_GETFD
%10 = call i32 (i32, i32, ...) @fcntl(i32 %8, i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %3
%12 = load i32, i32* @F_SETFD
%13 = load i32, i32* %4
%14 = load i32, i32* @FD_CLOEXEC
%15 = or i32 %13, %14
%16 = call i32 (i32, i32, ...) @fcntl(i32 %11, i32 %12, i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = load i32, i32* %3
%19 = load i32, i32* @F_GETFD
%20 = call i32 (i32, i32, ...) @fcntl(i32 %18, i32 %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = load i32, i32* @FD_CLOEXEC
%23 = and i32 %21, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %1
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %25, %1
ret void
}

LLVM IR (-O2):
@F_GETFD = global i32 0
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"cloexec failed!\0A\00"
define void @cloexec(i32* nocapture %0) {
%2 = tail call i32 @fileno(i32* %0)
%3 = load i32, i32* @F_GETFD
%4 = tail call i32 (i32, i32, ...) @fcntl(i32 %2, i32 %3)
%5 = load i32, i32* @F_SETFD
%6 = load i32, i32* @FD_CLOEXEC
%7 = or i32 %6, %4
%8 = tail call i32 (i32, i32, ...) @fcntl(i32 %2, i32 %5, i32 %7)
%9 = load i32, i32* @F_GETFD
%10 = tail call i32 (i32, i32, ...) @fcntl(i32 %2, i32 %9)
%11 = load i32, i32* @FD_CLOEXEC
%12 = and i32 %11, %10
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %14, %1
ret void
}