#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 */

/* Variables and functions */
char *fgets(char *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strcspn(char *, char *);
int lpcli_readpassword_nc(char *out, size_t outl) {
  out = fgets(out, outl, stdin);
  if (out == NULL)
    return 1;
  int len = strcspn(out, "\r\n");
  if (len == 0)
    return 1;
  out[len] = 0;
  return 0;
}


x86 assembly (clang, -O0):
<lpcli_readpassword_nc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2ea9(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1161 <lpcli_readpassword_nc+0x41>
movl   $0x1,-0x4(%rbp)
jmp    119d <lpcli_readpassword_nc+0x7d>
mov    -0x10(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1030 <strcspn@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    118a <lpcli_readpassword_nc+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    119d <lpcli_readpassword_nc+0x7d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lpcli_readpassword_nc>:
push   %rbp
push   %rbx
push   %rax
mov    0x2ebe(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1159 <lpcli_readpassword_nc+0x39>
mov    %rax,%rbx
lea    0xebb(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcspn@plt>
test   %eax,%eax
je     1159 <lpcli_readpassword_nc+0x39>
cltq
movb   $0x0,(%rbx,%rax,1)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"\0D\0A\00"
define i32 @lpcli_readpassword_nc(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i8*, i8** %4
%8 = load i64, i64* %5
%9 = load i32, i32* @stdin
%10 = call i8* @fgets(i8* %7, i64 %8, i32 %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %25
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32 @strcspn(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 1, i32* %3
br label %25
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
store i32 0, i32* %3
br label %25
25: ; preds = %20, %19, %13
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"\0D\0A\00"
define i32 @lpcli_readpassword_nc(i8* %0, i64 %1) {
%3 = load i32, i32* @stdin
%4 = tail call i8* @fgets(i8* %0, i64 %1, i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = tail call i32 @strcspn(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds i8, i8* %4, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %9, %6, %2
%13 = phi i32 [ 1, %2 ], [ 0, %9 ], [ 1, %6 ]
ret i32 %13
}