#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 /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int tcgetattr(int /*<<< orphan*/, struct termios *);
int tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int main(int argc, char *argv[]) {
  struct termios info;
  int val;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <y/n>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((val = tcgetattr(0, &info)) == -1) {
    perror("tcgetattr() failed");
    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() failed");
    exit(EXIT_FAILURE);
  }
  return 0;
}


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     119a <main+0x4a>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %edi,%edi
lea    -0x18(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11cb <main+0x7b>
lea    0xe59(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x79,%eax
jne    11f3 <main+0xa3>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1205 <main+0xb5>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    123c <main+0xec>
lea    0xdfb(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11ae <main+0x5e>
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1040 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     11c8 <main+0x78>
mov    0x8(%rbx),%rax
cmpb   $0x79,(%rax)
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
jne    1186 <main+0x36>
or     %eax,0x8(%rsp)
jmp    118c <main+0x3c>
not    %eax
and    %eax,0x8(%rsp)
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1050 <tcsetattr@plt>
cmp    $0xffffffff,%eax
je     11d1 <main+0x81>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe3f(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11dd <main+0x8d>
lea    0xe42(%rip),%rdi
jmp    11d8 <main+0x88>
lea    0xe4c(%rip),%rdi
call   1060 <perror@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
%struct.termios = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"Usage: %s <y/n>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [19 x i8] c"tcgetattr() failed\00"
@ECHO = global i32 0
@TCSANOW = global i32 0
@.str.2 = [19 x i8] c"tcsetattr() failed\00"
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 %12, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = call i32 @tcgetattr(i32 0, %struct.termios* %3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %12
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 121
%24 = load i32, i32* @ECHO
br i1 %23, label %25, label %29
25: ; preds = %19
%26 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%27 = load i32, i32* %26
%28 = or i32 %27, %24
store i32 %28, i32* %26
br label %34
29: ; preds = %19
%30 = xor i32 %24, -1
%31 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%32 = load i32, i32* %31
%33 = and i32 %32, %30
store i32 %33, i32* %31
br label %34
34: ; preds = %29, %25
%35 = load i32, i32* @TCSANOW
%36 = call i32 @tcsetattr(i32 0, i32 %35, %struct.termios* %3)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %34
ret i32 0
}