#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 EACCES;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
scalar_t__ errno;
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ logError(char *, int, scalar_t__, char *);
char *strerror(scalar_t__);
int fd_add_flags(int fd, int adding_flags) {
  int flags;
  flags = fcntl(fd, F_GETFL, 0);
  if (flags < 0) {
    logError("file: "
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/"
             "fastdfs-5.01/common/shared_func.c"
             ", line: %d, "
             "fcntl fail, errno: %d, error info: %s.",
             1422, errno,
             (strerror(errno) != NULL ? strerror(errno) : "Unkown error"));
    return errno != 0 ? errno : EACCES;
  }
  if (fcntl(fd, F_SETFL, flags | adding_flags) == -1) {
    logError("file: "
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/"
             "fastdfs-5.01/common/shared_func.c"
             ", line: %d, "
             "fcntl fail, errno: %d, error info: %s.",
             1430, errno,
             (strerror(errno) != NULL ? strerror(errno) : "Unkown error"));
    return errno != 0 ? errno : EACCES;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fd_add_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1204 <fd_add_flags+0xd4>
mov    0x2e6b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
cmp    $0x0,%rax
je     119d <fd_add_flags+0x6d>
mov    0x2e44(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %rax,-0x20(%rbp)
jmp    11ad <fd_add_flags+0x7d>
lea    0xf33(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11ad <fd_add_flags+0x7d>
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe44(%rip),%rdi
mov    $0x58e,%esi
call   1040 <logError@plt>
mov    0x2e03(%rip),%rax
cmpq   $0x0,(%rax)
je     11ea <fd_add_flags+0xba>
mov    0x2df2(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    11f8 <fd_add_flags+0xc8>
mov    0x2df7(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    12d1 <fd_add_flags+0x1a1>
mov    -0x8(%rbp),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
or     -0xc(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    12ca <fd_add_flags+0x19a>
mov    0x2da5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
cmp    $0x0,%rax
je     1263 <fd_add_flags+0x133>
mov    0x2d7e(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %rax,-0x38(%rbp)
jmp    1273 <fd_add_flags+0x143>
lea    0xe6d(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    1273 <fd_add_flags+0x143>
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xd7e(%rip),%rdi
mov    $0x596,%esi
call   1040 <logError@plt>
mov    0x2d3d(%rip),%rax
cmpq   $0x0,(%rax)
je     12b0 <fd_add_flags+0x180>
mov    0x2d2c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    12be <fd_add_flags+0x18e>
mov    0x2d31(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    12d1 <fd_add_flags+0x1a1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fd_add_flags>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     1193 <fd_add_flags+0x63>
mov    0x2e82(%rip),%rcx
mov    (%rcx),%esi
or     %r14d,%eax
mov    %ebp,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11fb <fd_add_flags+0xcb>
mov    0x2e5c(%rip),%rbp
mov    0x0(%rbp),%rbx
mov    %rbx,%rdi
call   1050 <strerror@plt>
test   %rax,%rax
je     11ce <fd_add_flags+0x9e>
mov    0x0(%rbp),%rdi
call   1050 <strerror@plt>
mov    %rax,%rcx
jmp    11d5 <fd_add_flags+0xa5>
mov    0x2e36(%rip),%rbp
mov    0x0(%rbp),%rbx
mov    %rbx,%rdi
call   1050 <strerror@plt>
test   %rax,%rax
je     11b9 <fd_add_flags+0x89>
mov    0x0(%rbp),%rdi
call   1050 <strerror@plt>
mov    %rax,%rcx
jmp    11c0 <fd_add_flags+0x90>
lea    0xf17(%rip),%rcx
lea    0xe39(%rip),%rdi
mov    $0x58e,%esi
jmp    11e1 <fd_add_flags+0xb1>
lea    0xf02(%rip),%rcx
lea    0xe24(%rip),%rdi
mov    $0x596,%esi
mov    %rbx,%rdx
call   1040 <logError@plt>
mov    0x0(%rbp),%rbx
test   %rbx,%rbx
jne    11fb <fd_add_flags+0xcb>
mov    0x2def(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [215 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, fcntl fail, errno: %d, error info: %s.\00"
@errno = global i64 0
@.str.1 = [13 x i8] c"Unkown error\00"
@EACCES = global i32 0
@F_SETFL = global i32 0
define i32 @fd_add_flags(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 %34
12: ; preds = %2
%13 = load i64, i64* @errno
%14 = load i64, i64* @errno
%15 = call i8* @strerror(i64 %14)
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i64, i64* @errno
%19 = call i8* @strerror(i64 %18)
br label %21
20: ; preds = %12
br label %21
21: ; preds = %20, %17
%22 = phi i8* [ %19, %17 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %20 ]
%23 = call i32 @logError(i8* getelementptr inbounds ([215 x i8], [215 x i8]* @.str, i64 0, i64 0), i32 1422, i64 %13, i8* %22)
%24 = load i64, i64* @errno
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = load i64, i64* @errno
br label %31
28: ; preds = %21
%29 = load i32, i32* @EACCES
%30 = sext i32 %29 to i64
br label %31
31: ; preds = %28, %26
%32 = phi i64 [ %27, %26 ], [ %30, %28 ]
%33 = trunc i64 %32 to i32
store i32 %33, i32* %3
br label %65
34: ; preds = %2
%35 = load i32, i32* %4
%36 = load i32, i32* @F_SETFL
%37 = load i32, i32* %6
%38 = load i32, i32* %5
%39 = or i32 %37, %38
%40 = call i32 @fcntl(i32 %35, i32 %36, i32 %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %64
42: ; preds = %34
%43 = load i64, i64* @errno
%44 = load i64, i64* @errno
%45 = call i8* @strerror(i64 %44)
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = load i64, i64* @errno
%49 = call i8* @strerror(i64 %48)
br label %51
50: ; preds = %42
br label %51
51: ; preds = %50, %47
%52 = phi i8* [ %49, %47 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %50 ]
%53 = call i32 @logError(i8* getelementptr inbounds ([215 x i8], [215 x i8]* @.str, i64 0, i64 0), i32 1430, i64 %43, i8* %52)
%54 = load i64, i64* @errno
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %51
%57 = load i64, i64* @errno
br label %61
58: ; preds = %51
%59 = load i32, i32* @EACCES
%60 = sext i32 %59 to i64
br label %61
61: ; preds = %58, %56
%62 = phi i64 [ %57, %56 ], [ %60, %58 ]
%63 = trunc i64 %62 to i32
store i32 %63, i32* %3
br label %65
64: ; preds = %34
store i32 0, i32* %3
br label %65
65: ; preds = %64, %61, %31
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [215 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, fcntl fail, errno: %d, error info: %s.\00"
@errno = global i64 0
@.str.1 = [13 x i8] c"Unkown error\00"
@EACCES = global i32 0
@F_SETFL = global i32 0
define i32 @fd_add_flags(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 %6, label %22
6: ; preds = %2
%7 = load i64, i64* @errno
%8 = tail call i8* @strerror(i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = load i64, i64* @errno
%12 = tail call i8* @strerror(i64 %11)
br label %13
13: ; preds = %6, %10
%14 = phi i8* [ %12, %10 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %6 ]
%15 = tail call i32 @logError(i8* getelementptr inbounds ([215 x i8], [215 x i8]* @.str, i64 0, i64 0), i32 1422, i64 %7, i8* %14)
%16 = load i64, i64* @errno
%17 = icmp eq i64 %16, 0
%18 = load i32, i32* @EACCES
%19 = zext i32 %18 to i64
%20 = select i1 %17, i64 %19, i64 %16
%21 = trunc i64 %20 to i32
br label %43
22: ; preds = %2
%23 = load i32, i32* @F_SETFL
%24 = or i32 %4, %1
%25 = tail call i32 @fcntl(i32 %0, i32 %23, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %43
27: ; preds = %22
%28 = load i64, i64* @errno
%29 = tail call i8* @strerror(i64 %28)
%30 = icmp eq i8* %29, null
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = load i64, i64* @errno
%33 = tail call i8* @strerror(i64 %32)
br label %34
34: ; preds = %27, %31
%35 = phi i8* [ %33, %31 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %27 ]
%36 = tail call i32 @logError(i8* getelementptr inbounds ([215 x i8], [215 x i8]* @.str, i64 0, i64 0), i32 1430, i64 %28, i8* %35)
%37 = load i64, i64* @errno
%38 = icmp eq i64 %37, 0
%39 = load i32, i32* @EACCES
%40 = zext i32 %39 to i64
%41 = select i1 %38, i64 %40, i64 %37
%42 = trunc i64 %41 to i32
br label %43
43: ; preds = %22, %34, %13
%44 = phi i32 [ %21, %13 ], [ %42, %34 ], [ 0, %22 ]
ret i32 %44
}