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

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int set_mode(int howw) {
  struct termios ttystate;
  tcgetattr(0, &ttystate);
  ttystate.c_lflag &= ~ICANON;
  if (howw == 1) {
    ttystate.c_lflag &= ~ECHO;
  }
  ttystate.c_cc[VMIN] = 1;
  tcsetattr(0, TCSANOW, &ttystate);
}


x86 assembly (clang, -O0):
<set_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
xor    %edi,%edi
lea    -0x18(%rbp),%rsi
call   1030 <tcgetattr@plt>
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1164 <set_mode+0x44>
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e69(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1040 <tcsetattr@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_mode>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
xor    %edi,%edi
call   1030 <tcgetattr@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x8(%rsp),%eax
mov    %eax,0x8(%rsp)
cmp    $0x1,%ebx
jne    115a <set_mode+0x3a>
mov    0x2e90(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,%eax
mov    %eax,0x8(%rsp)
mov    (%rsp),%rax
mov    0x2e73(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1040 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

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