#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 check(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, ...);
void make_cloexec(int fd) {
  int flags = check(fcntl(fd, F_GETFD), "fcntl(F_GETFD)");
  check(fcntl(fd, F_SETFD, flags | FD_CLOEXEC), "fcntl(F_SETFD)");
}


x86 assembly (clang, -O0):
<make_cloexec>:
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,%edi
lea    0xeb9(%rip),%rsi
call   1040 <check@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e73(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,%edi
lea    0xe98(%rip),%rsi
call   1040 <check@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_cloexec>:
push   %rbx
mov    %edi,%ebx
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
lea    0xec6(%rip),%rsi
mov    %eax,%edi
call   1040 <check@plt>
mov    0x2e98(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e87(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
lea    0xeaa(%rip),%rsi
mov    %eax,%edi
pop    %rbx
jmp    1040 <check@plt>

LLVM IR (-O0):
@F_GETFD = global i32 0
@.str = [15 x i8] c"fcntl(F_GETFD)\00"
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@.str.1 = [15 x i8] c"fcntl(F_SETFD)\00"
define void @make_cloexec(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)
%7 = call i32 @check(i32 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = load i32, i32* @F_SETFD
%10 = load i32, i32* %3
%11 = load i32, i32* @FD_CLOEXEC
%12 = or i32 %10, %11
%13 = call i32 (i32, i32, ...) @fcntl(i32 %8, i32 %9, i32 %12)
%14 = call i32 @check(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@F_GETFD = global i32 0
@.str = [15 x i8] c"fcntl(F_GETFD)\00"
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@.str.1 = [15 x i8] c"fcntl(F_SETFD)\00"
define void @make_cloexec(i32 %0) {
%2 = load i32, i32* @F_GETFD
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = tail call i32 @check(i32 %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%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 %0, i32 %5, i32 %7)
%9 = tail call i32 @check(i32 %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
ret void
}