#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 */
struct termios {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ _IOLBF;
scalar_t__ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/,
                   int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int unset_cbreak(struct termios *save_termios) {
  if (setvbuf(stdin, NULL, _IOLBF, 0) != 0)
    return -1;
  if (tcsetattr(0, TCSAFLUSH, save_termios) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<unset_cbreak>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1030 <setvbuf@plt>
cmp    $0x0,%rax
je     115f <unset_cbreak+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1190 <unset_cbreak+0x70>
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
xor    %edi,%edi
call   1040 <tcsetattr@plt>
cmp    $0x0,%rax
jge    1189 <unset_cbreak+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    1190 <unset_cbreak+0x70>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unset_cbreak>:
push   %rbx
mov    %rdi,%rbx
mov    0x2eb5(%rip),%rax
mov    (%rax),%edi
mov    0x2e9c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1030 <setvbuf@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
je     114e <unset_cbreak+0x2e>
pop    %rbx
ret
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %rbx,%rdx
call   1040 <tcsetattr@plt>
sar    $0x3f,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@stdin = global i32 0
@_IOLBF = global i32 0
@TCSAFLUSH = global i32 0
define i32 @unset_cbreak(%struct.termios* %0) {
%2 = alloca i32
%3 = alloca %struct.termios*
store %struct.termios* %0, %struct.termios** %3
%4 = load i32, i32* @stdin
%5 = load i32, i32* @_IOLBF
%6 = call i64 @setvbuf(i32 %4, i32* null, i32 %5, i32 0)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %16
9: ; preds = %1
%10 = load i32, i32* @TCSAFLUSH
%11 = load %struct.termios*, %struct.termios** %3
%12 = call i64 @tcsetattr(i32 0, i32 %10, %struct.termios* %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 -1, i32* %2
br label %16
15: ; preds = %9
store i32 0, i32* %2
br label %16
16: ; preds = %15, %14, %8
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stdin = global i32 0
@_IOLBF = global i32 0
@TCSAFLUSH = global i32 0
define i32 @unset_cbreak(%struct.termios* %0) {
%2 = load i32, i32* @stdin
%3 = load i32, i32* @_IOLBF
%4 = tail call i64 @setvbuf(i32 %2, i32* null, i32 %3, i32 0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @TCSAFLUSH
%8 = tail call i64 @tcsetattr(i32 0, i32 %7, %struct.termios* %0)
%9 = ashr i64 %8, 63
%10 = trunc i64 %9 to i32
br label %11
11: ; preds = %6, %1
%12 = phi i32 [ -1, %1 ], [ %10, %6 ]
ret i32 %12
}