#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 /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ err_sys(char *, int /*<<< orphan*/);
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/, int);
void add_fl(char *filename[], int flags) {
  int val;
  if ((val = fcntl(atoi(*filename), F_GETFL, 0)) < 0) {
    err_sys("fcntl error for fd %d", atoi(*filename));
  }
  val |= flags;
  if (fcntl(atoi(*filename), F_SETFL, val)) {
    err_sys("fcntl error for fd %d", atoi(*filename));
  }
}


x86 assembly (clang, -O0):
<add_fl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    1183 <add_fl+0x53>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%esi
lea    0xe82(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
call   1040 <fcntl@plt>
cmp    $0x0,%eax
je     11ce <add_fl+0x9e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%esi
lea    0xe37(%rip),%rdi
call   1030 <err_sys@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_fl>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    (%rdi),%rdi
call   1050 <atoi@plt>
mov    0x2e8f(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1170 <add_fl+0x40>
mov    (%rbx),%rdi
call   1050 <atoi@plt>
lea    0xe97(%rip),%rdi
mov    %eax,%esi
call   1030 <err_sys@plt>
or     %r14d,%ebp
mov    (%rbx),%rdi
call   1050 <atoi@plt>
mov    0x2e5e(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
mov    %ebp,%edx
call   1040 <fcntl@plt>
test   %eax,%eax
je     11ab <add_fl+0x7b>
mov    (%rbx),%rdi
call   1050 <atoi@plt>
lea    0xe60(%rip),%rdi
mov    %eax,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <err_sys@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [22 x i8] c"fcntl error for fd %d\00"
@F_SETFL = global i32 0
define void @add_fl(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%6 = load i8**, i8*** %3
%7 = load i8*, i8** %6
%8 = call i32 @atoi(i8* %7)
%9 = load i32, i32* @F_GETFL
%10 = call i32 @fcntl(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %3
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
%16 = call i32 @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %12, %2
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = or i32 %19, %18
store i32 %20, i32* %5
%21 = load i8**, i8*** %3
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
%24 = load i32, i32* @F_SETFL
%25 = load i32, i32* %5
%26 = call i32 @fcntl(i32 %23, i32 %24, i32 %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %17
%29 = load i8**, i8*** %3
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = call i32 @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %28, %17
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [22 x i8] c"fcntl error for fd %d\00"
@F_SETFL = global i32 0
define void @add_fl(i8** nocapture %0, i32 %1) {
%3 = load i8*, i8** %0
%4 = tail call i32 @atoi(i8* %3)
%5 = load i32, i32* @F_GETFL
%6 = tail call i32 @fcntl(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i8*, i8** %0
%10 = tail call i32 @atoi(i8* %9)
%11 = tail call i32 @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8, %2
%13 = or i32 %6, %1
%14 = load i8*, i8** %0
%15 = tail call i32 @atoi(i8* %14)
%16 = load i32, i32* @F_SETFL
%17 = tail call i32 @fcntl(i32 %15, i32 %16, i32 %13)
%18 = icmp eq i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %12
%20 = load i8*, i8** %0
%21 = tail call i32 @atoi(i8* %20)
%22 = tail call i32 @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %12
ret void
}