#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 */
typedef int /*<<< orphan*/ wchar_t;

/* Variables and functions */
int /*<<< orphan*/ *fgetws(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ lpcli_zeromemory(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stdin;
int wcs_to_utf8(int /*<<< orphan*/ *, int, unsigned char *, size_t);
int wcscspn(int /*<<< orphan*/ *, char *);
int lpcli_readpassword_u8(char *out, size_t outl) {
  wchar_t input[512];
  wchar_t *wp = fgetws(input, 512, stdin);
  if (wp == NULL)
    return 1;
  int len = wcscspn(input, L"\r\n");
  if (len == 0)
    return 1;
  len = wcs_to_utf8(input, len, (unsigned char *)out, outl - 1);
  lpcli_zeromemory(input, sizeof input);
  if (len <= 0) {
    return 1;
  }
  out[len] = 0;
  return 0;
}


x86 assembly (clang, -O0):
<lpcli_readpassword_u8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1030 <fgetws@plt>
mov    %rax,-0x828(%rbp)
cmpq   $0x0,-0x828(%rbp)
jne    118e <lpcli_readpassword_u8+0x4e>
movl   $0x1,-0x4(%rbp)
jmp    1224 <lpcli_readpassword_u8+0xe4>
lea    -0x820(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1050 <wcscspn@plt>
mov    %eax,-0x82c(%rbp)
cmpl   $0x0,-0x82c(%rbp)
jne    11c0 <lpcli_readpassword_u8+0x80>
movl   $0x1,-0x4(%rbp)
jmp    1224 <lpcli_readpassword_u8+0xe4>
lea    -0x820(%rbp),%rdi
mov    -0x82c(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
call   1060 <wcs_to_utf8@plt>
mov    %eax,-0x82c(%rbp)
lea    -0x820(%rbp),%rdi
mov    $0x800,%esi
call   1040 <lpcli_zeromemory@plt>
cmpl   $0x0,-0x82c(%rbp)
jg     120e <lpcli_readpassword_u8+0xce>
movl   $0x1,-0x4(%rbp)
jmp    1224 <lpcli_readpassword_u8+0xe4>
mov    -0x10(%rbp),%rax
movslq -0x82c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lpcli_readpassword_u8>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x200,%esi
call   1030 <fgetws@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11b9 <lpcli_readpassword_u8+0x79>
lea    0xe86(%rip),%rsi
mov    %rsp,%rdi
call   1050 <wcscspn@plt>
test   %eax,%eax
je     11b9 <lpcli_readpassword_u8+0x79>
add    $0xffffffffffffffff,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1060 <wcs_to_utf8@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    $0x800,%esi
call   1040 <lpcli_zeromemory@plt>
test   %ebx,%ebx
jle    11b9 <lpcli_readpassword_u8+0x79>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i32] [i32 13, i32 10, i32 0]
define i32 @lpcli_readpassword_u8(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [512 x i32]
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = getelementptr inbounds [512 x i32], [512 x i32]* %6, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32* @fgetws(i32* %9, i32 512, i32 %10)
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %38
15: ; preds = %2
%16 = getelementptr inbounds [512 x i32], [512 x i32]* %6, i64 0, i64 0
%17 = call i32 @wcscspn(i32* %16, i8* bitcast ([3 x i32]* @.str to i8*))
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %3
br label %38
21: ; preds = %15
%22 = getelementptr inbounds [512 x i32], [512 x i32]* %6, i64 0, i64 0
%23 = load i32, i32* %8
%24 = load i8*, i8** %4
%25 = load i64, i64* %5
%26 = sub i64 %25, 1
%27 = call i32 @wcs_to_utf8(i32* %22, i32 %23, i8* %24, i64 %26)
store i32 %27, i32* %8
%28 = getelementptr inbounds [512 x i32], [512 x i32]* %6, i64 0, i64 0
%29 = call i32 @lpcli_zeromemory(i32* %28, i32 2048)
%30 = load i32, i32* %8
%31 = icmp sle i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %21
store i32 1, i32* %3
br label %38
33: ; preds = %21
%34 = load i8*, i8** %4
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
store i32 0, i32* %3
br label %38
38: ; preds = %33, %32, %20, %14
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i32] [i32 13, i32 10, i32 0]
define i32 @lpcli_readpassword_u8(i8* %0, i64 %1) {
%3 = alloca [512 x i32]
%4 = bitcast [512 x i32]* %3 to i8*
%5 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32* @fgetws(i32* %5, i32 512, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %20, label %9
9: ; preds = %2
%10 = call i32 @wcscspn(i32* %5, i8* bitcast ([3 x i32]* @.str to i8*))
%11 = icmp eq i32 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %9
%13 = add i64 %1, -1
%14 = call i32 @wcs_to_utf8(i32* %5, i32 %10, i8* %0, i64 %13)
%15 = call i32 @lpcli_zeromemory(i32* %5, i32 2048)
%16 = icmp slt i32 %14, 1
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = zext i32 %14 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %17, %9, %12, %2
%21 = phi i32 [ 1, %2 ], [ 0, %17 ], [ 1, %9 ], [ 1, %12 ]
ret i32 %21
}