#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 O_NONBLOCK;
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ read(int, char *, int);
int do_return_msg(int fd) {
  int flags = fcntl(fd, F_GETFL, 0);
  fcntl(fd, F_GETFL, flags | (~O_NONBLOCK));
  char c;
  read(fd, &c, 1);
  fcntl(fd, F_GETFL, flags);
  return c;
}


x86 assembly (clang, -O0):
<do_return_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
or     %eax,%edx
call   1030 <fcntl@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    -0x4(%rbp),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
call   1030 <fcntl@plt>
movsbl -0x9(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_return_msg>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2ea7(%rip),%r14
mov    (%r14),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ebp
mov    (%r14),%esi
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
not    %edx
or     %ebp,%edx
mov    %ebx,%edi
call   1030 <fcntl@plt>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <read@plt>
mov    (%r14),%esi
mov    %ebx,%edi
mov    %ebp,%edx
call   1030 <fcntl@plt>
movsbl 0xf(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @do_return_msg(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @F_GETFL
%7 = call i32 @fcntl(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = load i32, i32* @F_GETFL
%10 = load i32, i32* %3
%11 = load i32, i32* @O_NONBLOCK
%12 = xor i32 %11, -1
%13 = or i32 %10, %12
%14 = call i32 @fcntl(i32 %8, i32 %9, i32 %13)
%15 = load i32, i32* %2
%16 = call i32 @read(i32 %15, i8* %4, i32 1)
%17 = load i32, i32* %2
%18 = load i32, i32* @F_GETFL
%19 = load i32, i32* %3
%20 = call i32 @fcntl(i32 %17, i32 %18, i32 %19)
%21 = load i8, i8* %4
%22 = sext i8 %21 to i32
ret i32 %22
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @do_return_msg(i32 %0) {
%2 = alloca i8
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 @fcntl(i32 %0, i32 %3, i32 0)
%5 = load i32, i32* @F_GETFL
%6 = load i32, i32* @O_NONBLOCK
%7 = xor i32 %6, -1
%8 = or i32 %4, %7
%9 = tail call i32 @fcntl(i32 %0, i32 %5, i32 %8)
%10 = call i32 @read(i32 %0, i8* %2, i32 1)
%11 = load i32, i32* @F_GETFL
%12 = tail call i32 @fcntl(i32 %0, i32 %11, i32 %4)
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
ret i32 %14
}