#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_lflag;
};

/* Variables and functions */
int ECHO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(struct termios *);
struct termios *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int main(int argc, char *argv[]) {
  struct termios *current;
  int c_lflag_bkp;
  char line[124];
  current = malloc(sizeof(struct termios));
  tcgetattr(STDIN_FILENO, current);
  printf("c_flags is: %i\n", (int)current->c_lflag);
  if (current->c_lflag && ECHO) {
    printf("ECHO is enabled\n");
  }
  c_lflag_bkp = current->c_lflag;
  current->c_lflag &= ~ECHO;
  printf("FLAGS is now: %i\n", (int)current->c_lflag);
  if (current->c_lflag && ~ECHO) {
    printf("ECHO is now disabled\n");
  }
  tcsetattr(STDIN_FILENO, 0, current);
  printf("Enter Password: ");
  fgets(line, 124, stdin);
  printf("\n");
  printf("Restoring saved settings\n");
  current->c_lflag = c_lflag_bkp;
  tcsetattr(STDIN_FILENO, 0, current);
  free(current);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
je     11e8 <main+0x78>
mov    0x2e0f(%rip),%rax
cmpl   $0x0,(%rax)
je     11e8 <main+0x78>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x18(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
je     1249 <main+0xd9>
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
cmp    $0x0,%eax
je     1249 <main+0xd9>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1080 <tcsetattr@plt>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2d6f(%rip),%rax
mov    (%rax),%edx
mov    $0x7c,%esi
call   1050 <fgets@plt>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1080 <tcsetattr@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    0x2e1f(%rip),%r14
mov    (%r14),%edi
mov    %rax,%rsi
call   1090 <tcgetattr@plt>
mov    (%rbx),%esi
lea    0xe3b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rbx),%ebp
mov    0x2e0b(%rip),%r15
mov    (%r15),%esi
test   %ebp,%ebp
je     11f1 <main+0x61>
test   %esi,%esi
je     11f1 <main+0x61>
lea    0xe7a(%rip),%rdi
call   1050 <puts@plt>
mov    (%rbx),%ebp
mov    (%r15),%esi
not    %esi
and    %ebp,%esi
mov    %esi,(%rbx)
lea    0xe12(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,(%rbx)
je     121c <main+0x8c>
cmpl   $0xffffffff,(%r15)
je     121c <main+0x8c>
lea    0xe35(%rip),%rdi
call   1050 <puts@plt>
mov    (%r14),%edi
xor    %esi,%esi
mov    %rbx,%rdx
call   10a0 <tcsetattr@plt>
lea    0xdf2(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x7c,%esi
call   1070 <fgets@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xdd5(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,(%rbx)
mov    (%r14),%edi
xor    %esi,%esi
mov    %rbx,%rdx
call   10a0 <tcsetattr@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@.str = [16 x i8] c"c_flags is: %i\0A\00"
@ECHO = global i32 0
@.str.1 = [17 x i8] c"ECHO is enabled\0A\00"
@.str.2 = [18 x i8] c"FLAGS is now: %i\0A\00"
@.str.3 = [22 x i8] c"ECHO is now disabled\0A\00"
@.str.4 = [17 x i8] c"Enter Password: \00"
@stdin = global i32 0
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [26 x i8] c"Restoring saved settings\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.termios*
%7 = alloca i32
%8 = alloca [124 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call %struct.termios* @malloc(i32 4)
store %struct.termios* %9, %struct.termios** %6
%10 = load i32, i32* @STDIN_FILENO
%11 = load %struct.termios*, %struct.termios** %6
%12 = call i32 @tcgetattr(i32 %10, %struct.termios* %11)
%13 = load %struct.termios*, %struct.termios** %6
%14 = getelementptr inbounds %struct.termios, %struct.termios* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load %struct.termios*, %struct.termios** %6
%18 = getelementptr inbounds %struct.termios, %struct.termios* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %2
%22 = load i32, i32* @ECHO
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %21, %2
%27 = load %struct.termios*, %struct.termios** %6
%28 = getelementptr inbounds %struct.termios, %struct.termios* %27, i32 0, i32 0
%29 = load i32, i32* %28
store i32 %29, i32* %7
%30 = load i32, i32* @ECHO
%31 = xor i32 %30, -1
%32 = load %struct.termios*, %struct.termios** %6
%33 = getelementptr inbounds %struct.termios, %struct.termios* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = and i32 %34, %31
store i32 %35, i32* %33
%36 = load %struct.termios*, %struct.termios** %6
%37 = getelementptr inbounds %struct.termios, %struct.termios* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load %struct.termios*, %struct.termios** %6
%41 = getelementptr inbounds %struct.termios, %struct.termios* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %26
%45 = load i32, i32* @ECHO
%46 = xor i32 %45, -1
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %48, %44, %26
%51 = load i32, i32* @STDIN_FILENO
%52 = load %struct.termios*, %struct.termios** %6
%53 = call i32 @tcsetattr(i32 %51, i32 0, %struct.termios* %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%55 = getelementptr inbounds [124 x i8], [124 x i8]* %8, i64 0, i64 0
%56 = load i32, i32* @stdin
%57 = call i32 @fgets(i8* %55, i32 124, i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%60 = load i32, i32* %7
%61 = load %struct.termios*, %struct.termios** %6
%62 = getelementptr inbounds %struct.termios, %struct.termios* %61, i32 0, i32 0
store i32 %60, i32* %62
%63 = load i32, i32* @STDIN_FILENO
%64 = load %struct.termios*, %struct.termios** %6
%65 = call i32 @tcsetattr(i32 %63, i32 0, %struct.termios* %64)
%66 = load %struct.termios*, %struct.termios** %6
%67 = call i32 @free(%struct.termios* %66)
%68 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@.str = [16 x i8] c"c_flags is: %i\0A\00"
@ECHO = global i32 0
@.str.2 = [18 x i8] c"FLAGS is now: %i\0A\00"
@.str.4 = [17 x i8] c"Enter Password: \00"
@stdin = global i32 0
@str = [25 x i8] c"Restoring saved settings\00"
@str.7 = [21 x i8] c"ECHO is now disabled\00"
@str.8 = [16 x i8] c"ECHO is enabled\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [124 x i8]
%4 = getelementptr inbounds [124 x i8], [124 x i8]* %3, i64 0, i64 0
%5 = tail call %struct.termios* @malloc(i32 4)
%6 = load i32, i32* @STDIN_FILENO
%7 = tail call i32 @tcgetattr(i32 %6, %struct.termios* %5)
%8 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %8
%12 = icmp ne i32 %11, 0
%13 = load i32, i32* @ECHO
%14 = icmp ne i32 %13, 0
%15 = select i1 %12, i1 %14, i1 false
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.8, i64 0, i64 0))
%18 = load i32, i32* %8
%19 = load i32, i32* @ECHO
br label %20
20: ; preds = %16, %2
%21 = phi i32 [ %19, %16 ], [ %13, %2 ]
%22 = phi i32 [ %18, %16 ], [ %11, %2 ]
%23 = xor i32 %21, -1
%24 = and i32 %22, %23
store i32 %24, i32* %8
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 0
%28 = load i32, i32* @ECHO
%29 = icmp eq i32 %28, -1
%30 = select i1 %27, i1 true, i1 %29
br i1 %30, label %33, label %31
31: ; preds = %20
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0))
br label %33
33: ; preds = %31, %20
%34 = load i32, i32* @STDIN_FILENO
%35 = tail call i32 @tcsetattr(i32 %34, i32 0, %struct.termios* %5)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* @stdin
%38 = call i32 @fgets(i8* %4, i32 124, i32 %37)
%39 = call i32 @putchar(i32 10)
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
store i32 %22, i32* %8
%41 = load i32, i32* @STDIN_FILENO
%42 = call i32 @tcsetattr(i32 %41, i32 0, %struct.termios* %5)
%43 = call i32 @free(%struct.termios* %5)
%44 = call i32 @exit(i32 0)
unreachable
}