#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 O_NONBLOCK;
scalar_t__ fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ fluff_traceback_drop();
int /*<<< orphan*/ fluff_traceback_grab(char *);
int /*<<< orphan*/ fluff_traceback_set(char *);
int set_blocking(int sock, int blocking) {
  int flags;
  if (!fluff_traceback_grab("set_blocking")) {
    flags = fcntl(sock, F_GETFL, 0);
    if (flags < 0) {
      fluff_traceback_set("failed to get flags");
      return flags;
    } else if (blocking) {
      flags &= ~O_NONBLOCK;
    } else {
      flags |= O_NONBLOCK;
    }
    if (fcntl(sock, F_SETFL, flags) < 0) {
      fluff_traceback_set("failed to set flags");
      return -1;
    } else {
      fluff_traceback_drop();
      return 0;
    }
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<set_blocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeab(%rip),%rdi
call   1060 <fluff_traceback_grab@plt>
cmp    $0x0,%eax
jne    1218 <set_blocking+0xd8>
mov    -0x8(%rbp),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    119a <set_blocking+0x5a>
lea    0xe83(%rip),%rdi
call   1050 <fluff_traceback_set@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121f <set_blocking+0xdf>
cmpl   $0x0,-0xc(%rbp)
je     11bb <set_blocking+0x7b>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11ca <set_blocking+0x8a>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11cf <set_blocking+0x8f>
mov    -0x8(%rbp),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    1205 <set_blocking+0xc5>
lea    0xe2d(%rip),%rdi
call   1050 <fluff_traceback_set@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121f <set_blocking+0xdf>
mov    $0x0,%al
call   1040 <fluff_traceback_drop@plt>
movl   $0x0,-0x4(%rbp)
jmp    121f <set_blocking+0xdf>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_blocking>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xeb0(%rip),%rdi
call   1060 <fluff_traceback_grab@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
je     1165 <set_blocking+0x25>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %rax,%rbx
test   %ebx,%ebx
js     11b5 <set_blocking+0x75>
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
mov    %edx,%eax
not    %eax
and    %ebx,%eax
or     %ebx,%edx
test   %r14d,%r14d
cmovne %eax,%edx
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1030 <fcntl@plt>
test   %rax,%rax
js     11c3 <set_blocking+0x83>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fluff_traceback_drop@plt>
jmp    115e <set_blocking+0x1e>
lea    0xe51(%rip),%rdi
call   1050 <fluff_traceback_set@plt>
jmp    115e <set_blocking+0x1e>
lea    0xe57(%rip),%rdi
call   1050 <fluff_traceback_set@plt>
mov    $0xffffffff,%ebx
jmp    115e <set_blocking+0x1e>

LLVM IR (-O0):
@.str = [13 x i8] c"set_blocking\00"
@F_GETFL = global i32 0
@.str.1 = [20 x i8] c"failed to get flags\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.2 = [20 x i8] c"failed to set flags\00"
define i32 @set_blocking(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 = call i32 @fluff_traceback_grab(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i32 %7, 0
br i1 %8, label %42, label %9
9: ; preds = %2
%10 = load i32, i32* %4
%11 = load i32, i32* @F_GETFL
%12 = call i64 @fcntl(i32 %10, i32 %11, i32 0)
%13 = trunc i64 %12 to i32
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %9
%17 = call i32 @fluff_traceback_set(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %6
store i32 %18, i32* %3
br label %43
19: ; preds = %9
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* @O_NONBLOCK
%24 = xor i32 %23, -1
%25 = load i32, i32* %6
%26 = and i32 %25, %24
store i32 %26, i32* %6
br label %31
27: ; preds = %19
%28 = load i32, i32* @O_NONBLOCK
%29 = load i32, i32* %6
%30 = or i32 %29, %28
store i32 %30, i32* %6
br label %31
31: ; preds = %27, %22
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = load i32, i32* @F_SETFL
%35 = load i32, i32* %6
%36 = call i64 @fcntl(i32 %33, i32 %34, i32 %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i32 @fluff_traceback_set(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %43
40: ; preds = %32
%41 = call i32 (...) @fluff_traceback_drop()
store i32 0, i32* %3
br label %43
42: ; preds = %2
store i32 -1, i32* %3
br label %43
43: ; preds = %42, %40, %38, %16
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [13 x i8] c"set_blocking\00"
@F_GETFL = global i32 0
@.str.1 = [20 x i8] c"failed to get flags\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.2 = [20 x i8] c"failed to set flags\00"
define i32 @set_blocking(i32 %0, i32 %1) {
%3 = tail call i32 @fluff_traceback_grab(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %26
5: ; preds = %2
%6 = load i32, i32* @F_GETFL
%7 = tail call i64 @fcntl(i32 %0, i32 %6, i32 0)
%8 = trunc i64 %7 to i32
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @fluff_traceback_set(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %26
12: ; preds = %5
%13 = icmp eq i32 %1, 0
%14 = load i32, i32* @O_NONBLOCK
%15 = xor i32 %14, -1
%16 = and i32 %15, %8
%17 = or i32 %14, %8
%18 = select i1 %13, i32 %17, i32 %16
%19 = load i32, i32* @F_SETFL
%20 = tail call i64 @fcntl(i32 %0, i32 %19, i32 %18)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = tail call i32 @fluff_traceback_set(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %26
24: ; preds = %12
%25 = tail call i32 (...) @fluff_traceback_drop()
br label %26
26: ; preds = %2, %24, %22, %10
%27 = phi i32 [ %8, %10 ], [ -1, %22 ], [ 0, %24 ], [ -1, %2 ]
ret i32 %27
}