#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 /*<<< orphan*/ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSAFLUSH;
scalar_t__ tcgetattr(int /*<<< orphan*/, struct termios *);
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int setsilent(struct termios *initial_term) {
  struct termios term;
  if (tcgetattr(STDIN_FILENO, initial_term) != 0) {
    return -1;
  }
  term = *initial_term;
  term.c_lflag &= ~ECHO;
  term.c_lflag &= ~ICANON;
  if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &term) != 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setsilent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmp    $0x0,%rax
je     1154 <setsilent+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <setsilent+0x99>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <tcsetattr@plt>
cmp    $0x0,%rax
je     11b2 <setsilent+0x92>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <setsilent+0x99>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setsilent>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ea2(%rip),%r14
mov    (%r14),%edi
mov    %rbx,%rsi
call   1030 <tcgetattr@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1178 <setsilent+0x58>
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
mov    0x2e72(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    (%rbx),%eax
mov    %eax,(%rsp)
mov    (%r14),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1040 <tcsetattr@plt>
neg    %rax
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@ICANON = global i32 0
@TCSAFLUSH = global i32 0
define i32 @setsilent(%struct.termios* %0) {
%2 = alloca i32
%3 = alloca %struct.termios*
%4 = alloca %struct.termios
store %struct.termios* %0, %struct.termios** %3
%5 = load i32, i32* @STDIN_FILENO
%6 = load %struct.termios*, %struct.termios** %3
%7 = call i64 @tcgetattr(i32 %5, %struct.termios* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %30
10: ; preds = %1
%11 = load %struct.termios*, %struct.termios** %3
%12 = bitcast %struct.termios* %4 to i8*
%13 = bitcast %struct.termios* %11 to i8*
%14 = load i32, i32* @ECHO
%15 = xor i32 %14, -1
%16 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%17 = load i32, i32* %16
%18 = and i32 %17, %15
store i32 %18, i32* %16
%19 = load i32, i32* @ICANON
%20 = xor i32 %19, -1
%21 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%22 = load i32, i32* %21
%23 = and i32 %22, %20
store i32 %23, i32* %21
%24 = load i32, i32* @STDIN_FILENO
%25 = load i32, i32* @TCSAFLUSH
%26 = call i64 @tcsetattr(i32 %24, i32 %25, %struct.termios* %4)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %10
store i32 -1, i32* %2
br label %30
29: ; preds = %10
store i32 0, i32* %2
br label %30
30: ; preds = %29, %28, %9
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@ICANON = global i32 0
@TCSAFLUSH = global i32 0
define i32 @setsilent(%struct.termios* %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = load i32, i32* @STDIN_FILENO
%5 = tail call i64 @tcgetattr(i32 %4, %struct.termios* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %1
%8 = getelementptr %struct.termios, %struct.termios* %0, i64 0, i32 0
%9 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%10 = load i32, i32* %8
%11 = load i32, i32* @ECHO
%12 = load i32, i32* @ICANON
%13 = or i32 %11, %12
%14 = xor i32 %13, -1
%15 = and i32 %10, %14
store i32 %15, i32* %9
%16 = load i32, i32* @STDIN_FILENO
%17 = load i32, i32* @TCSAFLUSH
%18 = call i64 @tcsetattr(i32 %16, i32 %17, %struct.termios* %2)
%19 = icmp ne i64 %18, 0
%20 = sext i1 %19 to i32
br label %21
21: ; preds = %7, %1
%22 = phi i32 [ -1, %1 ], [ %20, %7 ]
ret i32 %22
}