#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*/ die(int);
int fcntl(int, int /*<<< orphan*/, ...);
void set_cloexec(int fd) {
  int flags = fcntl(fd, F_GETFD);
  if (flags < 0)
    die(13);
  if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0)
    die(14);
}


x86 assembly (clang, -O0):
<set_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,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1155 <set_cloexec+0x35>
mov    $0xd,%edi
call   1040 <die@plt>
mov    -0x4(%rbp),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e6d(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%eax
jge    1187 <set_cloexec+0x67>
mov    $0xe,%edi
call   1040 <die@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_cloexec>:
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    1145 <set_cloexec+0x25>
mov    $0xd,%edi
call   1040 <die@plt>
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
or     %ebp,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     116d <set_cloexec+0x4d>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0xe,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <die@plt>

LLVM IR (-O0):
@F_GETFD = global i32 0
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
define void @set_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)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @die(i32 13)
br label %11
11: ; preds = %9, %1
%12 = load i32, i32* %2
%13 = load i32, i32* @F_SETFD
%14 = load i32, i32* %3
%15 = load i32, i32* @FD_CLOEXEC
%16 = or i32 %14, %15
%17 = call i32 (i32, i32, ...) @fcntl(i32 %12, i32 %13, i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = call i32 @die(i32 14)
br label %21
21: ; preds = %19, %11
ret void
}

LLVM IR (-O2):
@F_GETFD = global i32 0
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
define void @set_cloexec(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 @die(i32 13)
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 @die(i32 14)
br label %15
15: ; preds = %13, %7
ret void
}