#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 FD_CLOEXEC;
int /*<<< orphan*/ F_GETFD;
int /*<<< orphan*/ F_SETFD;
int /*<<< orphan*/ abortmsgerrno(char *, int);
int fcntl(int, int /*<<< orphan*/, ...);
void fsetcloexec(int fd) {
  int flags = fcntl(fd, F_GETFD);
  if (flags < 0)
    abortmsgerrno("cannot get flags of fd %d", fd);
  if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0)
    abortmsgerrno("cannot set flags of fd %d", fd);
}


x86 assembly (clang, -O0):
<fsetcloexec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    115a <fsetcloexec+0x3a>
mov    -0x4(%rbp),%esi
lea    0xeab(%rip),%rdi
call   1040 <abortmsgerrno@plt>
mov    -0x4(%rbp),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e68(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%eax
jge    1191 <fsetcloexec+0x71>
mov    -0x4(%rbp),%esi
lea    0xe8e(%rip),%rdi
call   1040 <abortmsgerrno@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsetcloexec>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1149 <fsetcloexec+0x29>
lea    0xebe(%rip),%rdi
mov    %ebx,%esi
call   1040 <abortmsgerrno@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
or     %ebp,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     1171 <fsetcloexec+0x51>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xea2(%rip),%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <abortmsgerrno@plt>

LLVM IR (-O0):
@F_GETFD = global i32 0
@.str = [26 x i8] c"cannot get flags of fd %d\00"
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@.str.1 = [26 x i8] c"cannot set flags of fd %d\00"
define void @fsetcloexec(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @F_GETFD
%6 = call i32 (i32, i32, ...) @fcntl(i32 %4, i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* %2
%11 = call i32 @abortmsgerrno(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %9, %1
%13 = load i32, i32* %2
%14 = load i32, i32* @F_SETFD
%15 = load i32, i32* %3
%16 = load i32, i32* @FD_CLOEXEC
%17 = or i32 %15, %16
%18 = call i32 (i32, i32, ...) @fcntl(i32 %13, i32 %14, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = load i32, i32* %2
%22 = call i32 @abortmsgerrno(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20, %12
ret void
}

LLVM IR (-O2):
@F_GETFD = global i32 0
@.str = [26 x i8] c"cannot get flags of fd %d\00"
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@.str.1 = [26 x i8] c"cannot set flags of fd %d\00"
define void @fsetcloexec(i32 %0) {
%2 = load i32, i32* @F_GETFD
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @abortmsgerrno(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %7
7: ; preds = %5, %1
%8 = load i32, i32* @F_SETFD
%9 = load i32, i32* @FD_CLOEXEC
%10 = or i32 %9, %3
%11 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %8, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @abortmsgerrno(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %15
15: ; preds = %13, %7
ret void
}