#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 fcntl(int, int /*<<< orphan*/, int);
int set_fl(int fd, int flag) {
  int oflag;
  oflag = fcntl(fd, F_GETFL, 0);
  if (oflag < 0) {
    return -1;
  }
  oflag |= flag;
  oflag = fcntl(fd, F_SETFL, oflag);
  if (oflag != 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_fl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    114a <set_fl+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1187 <set_fl+0x77>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1180 <set_fl+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    1187 <set_fl+0x77>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_fl>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eba(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     1145 <set_fl+0x35>
or     %ebp,%eax
mov    0x2eac(%rip),%rcx
mov    (%rcx),%esi
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
neg    %eax
sbb    %eax,%eax
jmp    114a <set_fl+0x3a>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
define i32 @set_fl(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = load i32, i32* @F_GETFL
%9 = call i32 @fcntl(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %25
13: ; preds = %2
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = or i32 %15, %14
store i32 %16, i32* %6
%17 = load i32, i32* %4
%18 = load i32, i32* @F_SETFL
%19 = load i32, i32* %6
%20 = call i32 @fcntl(i32 %17, i32 %18, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %13
store i32 -1, i32* %3
br label %25
24: ; preds = %13
store i32 0, i32* %3
br label %25
25: ; preds = %24, %23, %12
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
define i32 @set_fl(i32 %0, i32 %1) {
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 @fcntl(i32 %0, i32 %3, i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = or i32 %4, %1
%8 = load i32, i32* @F_SETFL
%9 = tail call i32 @fcntl(i32 %0, i32 %8, i32 %7)
%10 = icmp ne i32 %9, 0
%11 = sext i1 %10 to i32
br label %12
12: ; preds = %6, %2
%13 = phi i32 [ -1, %2 ], [ %11, %6 ]
ret i32 %13
}