#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*/ O_RDONLY;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int mpb_input_passwd(void) {
  int i = 0;
  int fd = -1;
  char mpb_passwd[16] = {'\0'};
  char mpb_input[16] = {'\0'};
  struct termios mpb_initialrsettings;
  struct termios mpb_newrsettings;
  fd = open("./.passwd", O_RDONLY);
  if (fd < 0) {
    perror("log_in.c mpb_input_passwd open()");
    exit(1);
  }
  tcgetattr(fileno(stdin), &mpb_initialrsettings);
  mpb_newrsettings = mpb_initialrsettings;
  mpb_newrsettings.c_lflag &= ~ECHO;
  if (0 != tcsetattr(fileno(stdin), TCSAFLUSH, &mpb_newrsettings)) {
    fprintf(stderr, "Could not set attributes\n");
  } else {
    i = 0;
    read(fd, mpb_passwd, 16);
    do {
      fprintf(stdout,
              "\nEnter password("
              "\033[31m"
              "%d"
              "\033[0m"
              " times): ",
              3 - i);
      memset(mpb_input, 0, 16);
      fgets(mpb_input, 16, stdin);
      i++;
    } while ((0 != strcmp(mpb_passwd, mpb_input)) && (i < 3));
    tcsetattr(fileno(stdin), TCSANOW, &mpb_initialrsettings);
  }
  close(fd);
  if (i >= 3)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<mpb_input_passwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
lea    0xdfa(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    122e <mpb_input_passwd+0x6e>
lea    0xdeb(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    %eax,%edi
lea    -0x38(%rbp),%rsi
call   10a0 <tcgetattr@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    %eax,%edi
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   10b0 <tcsetattr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12ab <mpb_input_passwd+0xeb>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1369 <mpb_input_passwd+0x1a9>
movl   $0x0,-0x8(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1050 <read@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
mov    $0x3,%edx
sub    -0x8(%rbp),%edx
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    0x2cdb(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1060 <fgets@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rdx
xor    %eax,%eax
xor    %ecx,%ecx
cmp    %rdx,%rcx
mov    %al,-0x41(%rbp)
je     133c <mpb_input_passwd+0x17c>
cmpl   $0x3,-0x8(%rbp)
setl   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    12c3 <mpb_input_passwd+0x103>
mov    0x2c8a(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    %eax,%edi
mov    0x2c72(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   10b0 <tcsetattr@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x3,-0x8(%rbp)
jl     1387 <mpb_input_passwd+0x1c7>
movl   $0x1,-0x4(%rbp)
jmp    138e <mpb_input_passwd+0x1ce>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpb_input_passwd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
lea    0xe15(%rip),%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     1336 <mpb_input_passwd+0x176>
mov    %eax,%ebp
mov    0x2dd7(%rip),%rbx
mov    (%rbx),%edi
call   1090 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   10a0 <tcgetattr@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rsp),%eax
mov    %eax,0x8(%rsp)
mov    (%rbx),%edi
call   1090 <fileno@plt>
mov    0x2db6(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   10b0 <tcsetattr@plt>
test   %rax,%rax
je     1265 <mpb_input_passwd+0xa5>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %ebp,%edi
jmp    1320 <mpb_input_passwd+0x160>
lea    0x20(%rsp),%r15
mov    %ebp,0xc(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x10,%edx
call   1050 <read@plt>
mov    $0xffffffff,%r14d
mov    $0x3,%ebp
mov    0x2d21(%rip),%r13
lea    0xdaf(%rip),%r12
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
mov    0x0(%r13),%edi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1060 <fgets@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12f2 <mpb_input_passwd+0x132>
add    $0xffffffff,%ebp
cmp    $0x2,%r14d
jb     12a0 <mpb_input_passwd+0xe0>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
call   1090 <fileno@plt>
mov    0x2cc9(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   10b0 <tcsetattr@plt>
xor    %ebx,%ebx
cmp    $0x2,%r14d
setae  %bl
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xccd(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [10 x i8] c"./.passwd\00"
@O_RDONLY = global i32 0
@.str.1 = [33 x i8] c"log_in.c mpb_input_passwd open()\00"
@stdin = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"Could not set attributes\0A\00"
@stdout = global i32 0
@.str.3 = [37 x i8] c"\0AEnter password(\1B[31m%d\1B[0m times): \00"
@TCSANOW = global i32 0
define i32 @mpb_input_passwd() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca %struct.termios
%7 = alloca %struct.termios
store i32 0, i32* %2
store i32 -1, i32* %3
%8 = bitcast [16 x i8]* %4 to i8*
%9 = bitcast [16 x i8]* %5 to i8*
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* @stdin
%19 = call i32 @fileno(i32 %18)
%20 = call i32 @tcgetattr(i32 %19, %struct.termios* %6)
%21 = bitcast %struct.termios* %7 to i8*
%22 = bitcast %struct.termios* %6 to i8*
%23 = load i32, i32* @ECHO
%24 = xor i32 %23, -1
%25 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%26 = load i32, i32* %25
%27 = and i32 %26, %24
store i32 %27, i32* %25
%28 = load i32, i32* @stdin
%29 = call i32 @fileno(i32 %28)
%30 = load i32, i32* @TCSAFLUSH
%31 = call i64 @tcsetattr(i32 %29, i32 %30, %struct.termios* %7)
%32 = icmp ne i64 0, %31
br i1 %32, label %33, label %36
33: ; preds = %17
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %67
36: ; preds = %17
store i32 0, i32* %2
%37 = load i32, i32* %3
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 16)
br label %40
40: ; preds = %60, %36
%41 = load i32, i32* @stdout
%42 = load i32, i32* %2
%43 = sub nsw i32 3, %42
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%46 = call i32 @memset(i8* %45, i32 0, i32 16)
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%48 = load i32, i32* @stdin
%49 = call i32 @fgets(i8* %47, i32 16, i32 %48)
%50 = load i32, i32* %2
%51 = add nsw i32 %50, 1
store i32 %51, i32* %2
br label %52
52: ; preds = %40
%53 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%54 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%55 = call i64 @strcmp(i8* %53, i8* %54)
%56 = icmp ne i64 0, %55
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = load i32, i32* %2
%59 = icmp slt i32 %58, 3
br label %60
60: ; preds = %57, %52
%61 = phi i1 [ false, %52 ], [ %59, %57 ]
br i1 %61, label %40, label %62
62: ; preds = %60
%63 = load i32, i32* @stdin
%64 = call i32 @fileno(i32 %63)
%65 = load i32, i32* @TCSANOW
%66 = call i64 @tcsetattr(i32 %64, i32 %65, %struct.termios* %6)
br label %67
67: ; preds = %62, %33
%68 = load i32, i32* %3
%69 = call i32 @close(i32 %68)
%70 = load i32, i32* %2
%71 = icmp sge i32 %70, 3
br i1 %71, label %72, label %73
72: ; preds = %67
store i32 1, i32* %1
br label %74
73: ; preds = %67
store i32 0, i32* %1
br label %74
74: ; preds = %73, %72
%75 = load i32, i32* %1
ret i32 %75
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [10 x i8] c"./.passwd\00"
@O_RDONLY = global i32 0
@.str.1 = [33 x i8] c"log_in.c mpb_input_passwd open()\00"
@stdin = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"Could not set attributes\0A\00"
@stdout = global i32 0
@.str.3 = [37 x i8] c"\0AEnter password(\1B[31m%d\1B[0m times): \00"
@TCSANOW = global i32 0
define i32 @mpb_input_passwd() {
%1 = alloca [16 x i8]
%2 = alloca [16 x i8]
%3 = alloca %struct.termios
%4 = alloca %struct.termios
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%7 = bitcast %struct.termios* %3 to i8*
%8 = bitcast %struct.termios* %4 to i8*
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = load i32, i32* @stdin
%17 = tail call i32 @fileno(i32 %16)
%18 = call i32 @tcgetattr(i32 %17, %struct.termios* %3)
%19 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%20 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%21 = load i32, i32* %19
%22 = load i32, i32* @ECHO
%23 = xor i32 %22, -1
%24 = and i32 %21, %23
store i32 %24, i32* %20
%25 = load i32, i32* @stdin
%26 = call i32 @fileno(i32 %25)
%27 = load i32, i32* @TCSAFLUSH
%28 = call i64 @tcsetattr(i32 %26, i32 %27, %struct.termios* %4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %15
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @close(i32 %10)
br label %57
34: ; preds = %15
%35 = call i32 @read(i32 %10, i8* %5, i32 16)
br label %36
36: ; preds = %36, %34
%37 = phi i32 [ 0, %34 ], [ %44, %36 ]
%38 = load i32, i32* @stdout
%39 = sub nuw nsw i32 3, %37
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = call i32 @memset(i8* %6, i32 0, i32 16)
%42 = load i32, i32* @stdin
%43 = call i32 @fgets(i8* %6, i32 16, i32 %42)
%44 = add nuw nsw i32 %37, 1
%45 = call i64 @strcmp(i8* %5, i8* %6)
%46 = icmp ne i64 %45, 0
%47 = icmp ult i32 %37, 2
%48 = select i1 %46, i1 %47, i1 false
br i1 %48, label %36, label %49
49: ; preds = %36
%50 = load i32, i32* @stdin
%51 = call i32 @fileno(i32 %50)
%52 = load i32, i32* @TCSANOW
%53 = call i64 @tcsetattr(i32 %51, i32 %52, %struct.termios* %3)
%54 = icmp ugt i32 %37, 1
%55 = call i32 @close(i32 %10)
%56 = zext i1 %54 to i32
br label %57
57: ; preds = %49, %30
%58 = phi i32 [ 0, %30 ], [ %56, %49 ]
ret i32 %58
}