#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;
};
struct spwd {
  int /*<<< orphan*/ sp_pwdp;
};
typedef int /*<<< orphan*/ pass;

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ crypt(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
struct spwd *getspnam(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(int /*<<< orphan*/);
scalar_t__ tcgetattr(int /*<<< orphan*/, struct termios *);
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main() {
  struct termios tattr;
  struct termios tattr2;
  char user[20] = {0};
  char pass[20] = {0};
  write(STDOUT_FILENO, "\nUser: ", 7);
  scanf("%19s", user);
  struct spwd *spwd = getspnam(user);
  if (!spwd || strlen(spwd->sp_pwdp) < 13) {
    printf("can not read /etc/shadow for user %s\n", user);
    exit(1);
  }
  assert(0 == tcgetattr(STDIN_FILENO, &tattr));
  tattr2 = tattr;
  tattr.c_lflag &= ~ECHO;
  assert(0 == tcsetattr(STDIN_FILENO, TCSANOW, &tattr));
  write(STDOUT_FILENO, "Password: ", 10);
  scanf("%19s", pass);
  assert(0 == tcsetattr(STDIN_FILENO, TCSANOW, &tattr2));
  if (strcmp(spwd->sp_pwdp, crypt(pass, spwd->sp_pwdp))) {
    printf("Invalid password for user %s\n", user);
  } else {
    printf("\nValid password for user %s\n", user);
  }
  memset(pass, 0, sizeof(pass));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
mov    $0x7,%edx
call   1030 <write@plt>
lea    -0x30(%rbp),%rsi
lea    0xdf4(%rip),%rdi
call   10a0 <scanf@plt>
lea    -0x30(%rbp),%rdi
call   10d0 <getspnam@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1245 <main+0x85>
mov    -0x58(%rbp),%rax
mov    (%rax),%edi
call   1050 <strlen@plt>
cmp    $0xd,%eax
jge    125f <main+0x9f>
lea    -0x30(%rbp),%rsi
lea    0xdbd(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   10b0 <tcgetattr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
mov    0x2d32(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   10c0 <tcsetattr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    0xd55(%rip),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
lea    -0x50(%rbp),%rsi
lea    0xd15(%rip),%rdi
call   10a0 <scanf@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
mov    0x2cd8(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   10c0 <tcsetattr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x58(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    (%rax),%esi
call   1040 <crypt@plt>
mov    -0x5c(%rbp),%edi
mov    %eax,%esi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1369 <main+0x1a9>
lea    -0x30(%rbp),%rsi
lea    0xcdf(%rip),%rdi
call   1060 <printf@plt>
jmp    1379 <main+0x1b9>
lea    -0x30(%rbp),%rsi
lea    0xce8(%rip),%rdi
call   1060 <printf@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movl   $0x0,0x40(%rsp)
mov    0x2dff(%rip),%r15
mov    (%r15),%edi
lea    0xe05(%rip),%rsi
mov    $0x7,%edx
call   1030 <write@plt>
lea    0xdfc(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   10a0 <scanf@plt>
mov    %rbx,%rdi
call   10d0 <getspnam@plt>
test   %rax,%rax
je     1338 <main+0x178>
mov    %rax,%rbx
mov    (%rax),%edi
call   1050 <strlen@plt>
cmp    $0xc,%eax
jle    1338 <main+0x178>
mov    0x2d84(%rip),%r12
mov    (%r12),%edi
mov    %rsp,%r14
mov    %r14,%rsi
call   10b0 <tcgetattr@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    (%rsp),%eax
mov    %eax,0x8(%rsp)
mov    0x2d69(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,(%rsp)
mov    (%r12),%edi
mov    0x2d5d(%rip),%r13
mov    0x0(%r13),%esi
mov    %r14,%rdx
call   10c0 <tcsetattr@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    (%r15),%edi
lea    0xd8c(%rip),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
lea    0xd50(%rip),%rdi
lea    0x30(%rsp),%r14
mov    %r14,%rsi
call   10a0 <scanf@plt>
mov    (%r12),%edi
mov    0x0(%r13),%esi
lea    0x8(%rsp),%rdx
call   10c0 <tcsetattr@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    (%rbx),%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <crypt@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1080 <strcmp@plt>
test   %rax,%rax
lea    0xd58(%rip),%rax
lea    0xd33(%rip),%rdi
cmove  %rax,%rdi
lea    0x10(%rsp),%rsi
call   1060 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xcce(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
%struct.spwd = type { i32 }
@STDOUT_FILENO = global i32 0
@.str = [8 x i8] c"\0AUser: \00"
@.str.1 = [5 x i8] c"%19s\00"
@.str.2 = [38 x i8] c"can not read /etc/shadow for user %s\0A\00"
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
@.str.3 = [11 x i8] c"Password: \00"
@.str.4 = [30 x i8] c"Invalid password for user %s\0A\00"
@.str.5 = [29 x i8] c"\0AValid password for user %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = alloca [20 x i8]
%5 = alloca [20 x i8]
%6 = alloca %struct.spwd*
store i32 0, i32* %1
%7 = bitcast [20 x i8]* %4 to i8*
%8 = bitcast [20 x i8]* %5 to i8*
%9 = load i32, i32* @STDOUT_FILENO
%10 = call i32 @write(i32 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%14 = call %struct.spwd* @getspnam(i8* %13)
store %struct.spwd* %14, %struct.spwd** %6
%15 = load %struct.spwd*, %struct.spwd** %6
%16 = icmp ne %struct.spwd* %15, null
br i1 %16, label %17, label %23
17: ; preds = %0
%18 = load %struct.spwd*, %struct.spwd** %6
%19 = getelementptr inbounds %struct.spwd, %struct.spwd* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @strlen(i32 %20)
%22 = icmp slt i32 %21, 13
br i1 %22, label %23, label %27
23: ; preds = %17, %0
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %17
%28 = load i32, i32* @STDIN_FILENO
%29 = call i64 @tcgetattr(i32 %28, %struct.termios* %2)
%30 = icmp eq i64 0, %29
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = bitcast %struct.termios* %3 to i8*
%34 = bitcast %struct.termios* %2 to i8*
%35 = load i32, i32* @ECHO
%36 = xor i32 %35, -1
%37 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%38 = load i32, i32* %37
%39 = and i32 %38, %36
store i32 %39, i32* %37
%40 = load i32, i32* @STDIN_FILENO
%41 = load i32, i32* @TCSANOW
%42 = call i64 @tcsetattr(i32 %40, i32 %41, %struct.termios* %2)
%43 = icmp eq i64 0, %42
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i32, i32* @STDOUT_FILENO
%47 = call i32 @write(i32 %46, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 10)
%48 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%49 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %48)
%50 = load i32, i32* @STDIN_FILENO
%51 = load i32, i32* @TCSANOW
%52 = call i64 @tcsetattr(i32 %50, i32 %51, %struct.termios* %3)
%53 = icmp eq i64 0, %52
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = load %struct.spwd*, %struct.spwd** %6
%57 = getelementptr inbounds %struct.spwd, %struct.spwd* %56, i32 0, i32 0
%58 = load i32, i32* %57
%59 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%60 = load %struct.spwd*, %struct.spwd** %6
%61 = getelementptr inbounds %struct.spwd, %struct.spwd* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = call i32 @crypt(i8* %59, i32 %62)
%64 = call i64 @strcmp(i32 %58, i32 %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %27
%67 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%68 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %67)
br label %72
69: ; preds = %27
%70 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%71 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %69, %66
%73 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%74 = call i32 @memset(i8* %73, i32 0, i32 20)
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32 }
%struct.spwd = type { i32 }
@STDOUT_FILENO = global i32 0
@.str = [8 x i8] c"\0AUser: \00"
@.str.1 = [5 x i8] c"%19s\00"
@.str.2 = [38 x i8] c"can not read /etc/shadow for user %s\0A\00"
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
@.str.3 = [11 x i8] c"Password: \00"
@.str.4 = [30 x i8] c"Invalid password for user %s\0A\00"
@.str.5 = [29 x i8] c"\0AValid password for user %s\0A\00"
define i32 @main() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = alloca [20 x i8]
%4 = alloca [20 x i8]
%5 = bitcast %struct.termios* %1 to i8*
%6 = bitcast %struct.termios* %2 to i8*
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @STDOUT_FILENO
%10 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%11 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%12 = call %struct.spwd* @getspnam(i8* %7)
%13 = icmp eq %struct.spwd* %12, null
br i1 %13, label %19, label %14
14: ; preds = %0
%15 = getelementptr inbounds %struct.spwd, %struct.spwd* %12, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @strlen(i32 %16)
%18 = icmp slt i32 %17, 13
br i1 %18, label %19, label %22
19: ; preds = %14, %0
%20 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = load i32, i32* @STDIN_FILENO
%24 = call i64 @tcgetattr(i32 %23, %struct.termios* %1)
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%29 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%30 = load i32, i32* %28
store i32 %30, i32* %29
%31 = load i32, i32* @ECHO
%32 = xor i32 %31, -1
%33 = and i32 %30, %32
store i32 %33, i32* %28
%34 = load i32, i32* @STDIN_FILENO
%35 = load i32, i32* @TCSANOW
%36 = call i64 @tcsetattr(i32 %34, i32 %35, %struct.termios* %1)
%37 = icmp eq i64 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i32, i32* @STDOUT_FILENO
%41 = call i32 @write(i32 %40, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 10)
%42 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%43 = load i32, i32* @STDIN_FILENO
%44 = load i32, i32* @TCSANOW
%45 = call i64 @tcsetattr(i32 %43, i32 %44, %struct.termios* %2)
%46 = icmp eq i64 %45, 0
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
%49 = load i32, i32* %15
%50 = call i32 @crypt(i8* %8, i32 %49)
%51 = call i64 @strcmp(i32 %49, i32 %50)
%52 = icmp eq i64 %51, 0
%53 = select i1 %52, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0)
%54 = call i32 @printf(i8* %53, i8* %7)
%55 = call i32 @memset(i8* %8, i32 0, i32 20)
ret i32 0
}