#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 termio {
  int /*<<< orphan*/ c_lflag;
};
typedef int /*<<< orphan*/ password;

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ TCGETA;
int /*<<< orphan*/ TCSETA;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct termio *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
const char *read_password(void) {
  static char password[1024];
  struct termio saved, no_echo;
  printf("Password: ");
  (void)ioctl(0, TCGETA, &saved);
  no_echo = saved;
  no_echo.c_lflag &= ~ECHO;
  (void)ioctl(0, TCSETA, &no_echo);
  fgets(password, sizeof(password), stdin);
  (void)ioctl(0, TCSETA, &saved);
  puts("");
  if (strchr(password, '\n'))
    *strchr(password, '\n') = '\0';
  return password;
}


x86 assembly (clang, -O0):
<read_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1060 <ioctl@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1060 <ioctl@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
lea    0x2eac(%rip),%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1060 <ioctl@plt>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
lea    0x2e7b(%rip),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     120d <read_password+0xbd>
lea    0x2e60(%rip),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
lea    0x2e4c(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_password>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xea0(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%r14
xor    %edi,%edi
mov    %r14,%rdx
call   1060 <ioctl@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x8(%rsp),%eax
mov    %eax,(%rsp)
mov    0x2e32(%rip),%rbx
mov    (%rbx),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1060 <ioctl@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
lea    0x2eae(%rip),%r15
mov    %r15,%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    (%rbx),%esi
xor    %edi,%edi
mov    %r14,%rdx
call   1060 <ioctl@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ea <read_password+0x9a>
movb   $0x0,(%rax)
lea    0x2e6f(%rip),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termio = type { i32 }
@read_password.password = internal global [1024 x i8] zeroinitializer
@.str = [11 x i8] c"Password: \00"
@TCGETA = global i32 0
@ECHO = global i32 0
@TCSETA = global i32 0
@stdin = global i32 0
@.str.1 = [1 x i8] zeroinitializer
define i8* @read_password() {
%1 = alloca %struct.termio
%2 = alloca %struct.termio
%3 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @TCGETA
%5 = call i32 @ioctl(i32 0, i32 %4, %struct.termio* %1)
%6 = bitcast %struct.termio* %2 to i8*
%7 = bitcast %struct.termio* %1 to i8*
%8 = load i32, i32* @ECHO
%9 = xor i32 %8, -1
%10 = getelementptr inbounds %struct.termio, %struct.termio* %2, i32 0, i32 0
%11 = load i32, i32* %10
%12 = and i32 %11, %9
store i32 %12, i32* %10
%13 = load i32, i32* @TCSETA
%14 = call i32 @ioctl(i32 0, i32 %13, %struct.termio* %2)
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @read_password.password, i64 0, i64 0), i32 1024, i32 %15)
%17 = load i32, i32* @TCSETA
%18 = call i32 @ioctl(i32 0, i32 %17, %struct.termio* %1)
%19 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%20 = call i8* @strchr(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @read_password.password, i64 0, i64 0), i8 signext 10)
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i8* @strchr(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @read_password.password, i64 0, i64 0), i8 signext 10)
store i8 0, i8* %23
br label %24
24: ; preds = %22, %0
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @read_password.password, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.termio = type { i32 }
@read_password.password = internal global [1024 x i8] zeroinitializer
@.str = [11 x i8] c"Password: \00"
@TCGETA = global i32 0
@ECHO = global i32 0
@TCSETA = global i32 0
@stdin = global i32 0
define i8* @read_password() {
%1 = alloca %struct.termio
%2 = alloca %struct.termio
%3 = bitcast %struct.termio* %1 to i8*
%4 = bitcast %struct.termio* %2 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @TCGETA
%7 = call i32 @ioctl(i32 0, i32 %6, %struct.termio* %1)
%8 = getelementptr inbounds %struct.termio, %struct.termio* %1, i64 0, i32 0
%9 = getelementptr inbounds %struct.termio, %struct.termio* %2, i64 0, i32 0
%10 = load i32, i32* %8
%11 = load i32, i32* @ECHO
%12 = xor i32 %11, -1
%13 = and i32 %10, %12
store i32 %13, i32* %9
%14 = load i32, i32* @TCSETA
%15 = call i32 @ioctl(i32 0, i32 %14, %struct.termio* %2)
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @read_password.password, i64 0, i64 0), i32 1024, i32 %16)
%18 = load i32, i32* @TCSETA
%19 = call i32 @ioctl(i32 0, i32 %18, %struct.termio* %1)
%20 = call i32 @putchar(i32 10)
%21 = call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @read_password.password, i64 0, i64 0), i8 signext 10)
%22 = icmp eq i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %0
store i8 0, i8* %21
br label %24
24: ; preds = %23, %0
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @read_password.password, i64 0, i64 0)
}