#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;
int fcntl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ perror(char *);
int SetBlockingMode(int fd) {
  int flags;
  if ((flags = fcntl(fd, F_GETFL)) == -1) {
    perror("fcntl(F_GETFL)");
    return (-1);
  }
  flags &= ~(O_NONBLOCK);
  if ((fcntl(fd, F_SETFL, flags)) == -1) {
    perror("fcntl(F_SETFL)");
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<SetBlockingMode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    1162 <SetBlockingMode+0x42>
lea    0xeaf(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <SetBlockingMode+0x92>
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11ab <SetBlockingMode+0x8b>
lea    0xe75(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <SetBlockingMode+0x92>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetBlockingMode>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     116b <SetBlockingMode+0x4b>
mov    0x2ea5(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,%eax
mov    0x2e88(%rip),%rcx
mov    (%rcx),%esi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1174 <SetBlockingMode+0x54>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe8e(%rip),%rdi
jmp    117b <SetBlockingMode+0x5b>
lea    0xe94(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1162 <SetBlockingMode+0x42>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [15 x i8] c"fcntl(F_GETFL)\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [15 x i8] c"fcntl(F_SETFL)\00"
define i32 @SetBlockingMode(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* @F_GETFL
%7 = call i32 (i32, i32, ...) @fcntl(i32 %5, i32 %6)
store i32 %7, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %24
11: ; preds = %1
%12 = load i32, i32* @O_NONBLOCK
%13 = xor i32 %12, -1
%14 = load i32, i32* %4
%15 = and i32 %14, %13
store i32 %15, i32* %4
%16 = load i32, i32* %3
%17 = load i32, i32* @F_SETFL
%18 = load i32, i32* %4
%19 = call i32 (i32, i32, ...) @fcntl(i32 %16, i32 %17, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %11
%22 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %24
23: ; preds = %11
store i32 0, i32* %2
br label %24
24: ; preds = %23, %21, %9
%25 = load i32, i32* %2
ret i32 %25
}

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