#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*/ TCSANOW;
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int setecho(int fd, int onoff) {
  struct termios term;
  if (tcgetattr(fd, &term) < 0)
    return 0;
  if (onoff) {
    term.c_lflag |= ECHO;
  } else {
    term.c_lflag &= ~(ECHO);
  }
  if (tcsetattr(fd, TCSANOW, &term) < 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<setecho>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmp    $0x0,%rax
jge    1150 <setecho+0x30>
movl   $0x0,-0x4(%rbp)
jmp    11b2 <setecho+0x92>
cmpl   $0x0,-0xc(%rbp)
je     116e <setecho+0x4e>
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1180 <setecho+0x60>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <tcsetattr@plt>
cmp    $0x0,%rax
jge    11ab <setecho+0x8b>
movl   $0x0,-0x4(%rbp)
jmp    11b2 <setecho+0x92>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setecho>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%rsi
call   1030 <tcgetattr@plt>
test   %rax,%rax
js     1146 <setecho+0x26>
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
test   %ebp,%ebp
je     114a <setecho+0x2a>
or     %eax,(%rsp)
jmp    114f <setecho+0x2f>
xor    %eax,%eax
jmp    1169 <setecho+0x49>
not    %eax
and    %eax,(%rsp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1040 <tcsetattr@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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