#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 /*<<< orphan*/ perror(char *);
int socket_add_attribute(int sock, int newflag) {
  int flags;
  flags = fcntl(sock, F_GETFL);
  if (flags == -1) {
    perror("fcntl failed reading");
    return -1;
  }
  flags |= newflag;
  if (fcntl(sock, F_SETFL, flags) == -1) {
    perror("fcntl failed reading");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<socket_add_attribute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1166 <socket_add_attribute+0x46>
lea    0xeab(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <socket_add_attribute+0x8d>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11a6 <socket_add_attribute+0x86>
lea    0xe6b(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <socket_add_attribute+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_add_attribute>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1163 <socket_add_attribute+0x43>
or     %ebx,%eax
mov    0x2e97(%rip),%rcx
mov    (%rcx),%esi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1163 <socket_add_attribute+0x43>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe96(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%r14d
jmp    115b <socket_add_attribute+0x3b>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [21 x i8] c"fcntl failed reading\00"
@F_SETFL = global i32 0
define i32 @socket_add_attribute(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 (i32, i32, ...) @fcntl(i32 %7, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
14: ; preds = %2
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = or i32 %16, %15
store i32 %17, i32* %6
%18 = load i32, i32* %4
%19 = load i32, i32* @F_SETFL
%20 = load i32, i32* %6
%21 = call i32 (i32, i32, ...) @fcntl(i32 %18, i32 %19, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
25: ; preds = %14
store i32 0, i32* %3
br label %26
26: ; preds = %25, %23, %12
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [21 x i8] c"fcntl failed reading\00"
@F_SETFL = global i32 0
define i32 @socket_add_attribute(i32 %0, i32 %1) {
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = or i32 %4, %1
%8 = load i32, i32* @F_SETFL
%9 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %8, i32 %7)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %6, %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %6
%14 = phi i32 [ 0, %6 ], [ -1, %11 ]
ret i32 %14
}