#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int tcgetattr(int /*<<< orphan*/, struct termios *);
int tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int main(int argc, char *argv[]) {
  struct termios info;
  if (argc != 2)
    exit(EXIT_FAILURE);
  if (tcgetattr(0, &info) == -1) {
    perror("tcgetattr");
    exit(EXIT_FAILURE);
  }
  if (argv[1][0] == 'y') {
    info.c_lflag |= ECHO;
  } else {
    info.c_lflag &= ~ECHO;
  }
  if (tcsetattr(0, TCSANOW, &info) == -1) {
    perror("tcsetattr");
    exit(EXIT_FAILURE);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     116e <main+0x2e>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
xor    %edi,%edi
lea    -0x18(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    119c <main+0x5c>
lea    0xe77(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x79,%eax
jne    11c4 <main+0x84>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11d6 <main+0x96>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1040 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    120d <main+0xcd>
lea    0xe10(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11ba <main+0x7a>
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1030 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     11a5 <main+0x65>
mov    0x8(%rbx),%rax
cmpb   $0x79,(%rax)
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
jne    1176 <main+0x36>
or     %eax,0x8(%rsp)
jmp    117c <main+0x3c>
not    %eax
and    %eax,0x8(%rsp)
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1040 <tcsetattr@plt>
cmp    $0xffffffff,%eax
je     11ae <main+0x6e>
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe54(%rip),%rdi
jmp    11b5 <main+0x75>
lea    0xe55(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [10 x i8] c"tcgetattr\00"
@ECHO = global i32 0
@TCSANOW = global i32 0
@.str.1 = [10 x i8] c"tcsetattr\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.termios
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = call i32 @tcgetattr(i32 0, %struct.termios* %6)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %12
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 121
br i1 %26, label %27, label %32
27: ; preds = %19
%28 = load i32, i32* @ECHO
%29 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%30 = load i32, i32* %29
%31 = or i32 %30, %28
store i32 %31, i32* %29
br label %38
32: ; preds = %19
%33 = load i32, i32* @ECHO
%34 = xor i32 %33, -1
%35 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%36 = load i32, i32* %35
%37 = and i32 %36, %34
store i32 %37, i32* %35
br label %38
38: ; preds = %32, %27
%39 = load i32, i32* @TCSANOW
%40 = call i32 @tcsetattr(i32 0, i32 %39, %struct.termios* %6)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %38
%47 = load i32, i32* @EXIT_SUCCESS
ret i32 %47
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [10 x i8] c"tcgetattr\00"
@ECHO = global i32 0
@TCSANOW = global i32 0
@.str.1 = [10 x i8] c"tcsetattr\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = call i32 @tcgetattr(i32 0, %struct.termios* %3)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %9
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 121
%21 = load i32, i32* @ECHO
br i1 %20, label %22, label %26
22: ; preds = %16
%23 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%24 = load i32, i32* %23
%25 = or i32 %24, %21
store i32 %25, i32* %23
br label %31
26: ; preds = %16
%27 = xor i32 %21, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
br label %31
31: ; preds = %26, %22
%32 = load i32, i32* @TCSANOW
%33 = call i32 @tcsetattr(i32 0, i32 %32, %struct.termios* %3)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %31
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}