#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 */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int read_password(char *result) {
  char passwd[256];
  char *ptr;
  if (fgets(passwd, 256, stdin) == NULL)
    return 0;
  ptr = strchr(passwd, '\n');
  if (ptr != NULL)
    *ptr = '\0';
  if (strlen(passwd) > 8) {
    memset(passwd + 8, 0, strlen(passwd) - 8);
    fprintf(stderr, "Warning: password truncated to the length of 8.\n");
  }
  strcpy(result, passwd);
  memset(passwd, 0, strlen(passwd));
  return 1;
}


x86 assembly (clang, -O0):
<read_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    119f <read_password+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    126b <read_password+0x10b>
lea    -0x110(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     11cf <read_password+0x6f>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
jle    122a <read_password+0xca>
lea    -0x110(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x120(%rbp),%rdi
mov    %eax,%edx
sub    $0x8,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    0xddb(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x128(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_password>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r15
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     1204 <read_password+0xa4>
mov    %rsp,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     119f <read_password+0x3f>
movb   $0x0,(%rax)
mov    %rsp,%rdi
call   1040 <strlen@plt>
cmp    $0x9,%eax
jl     11db <read_password+0x7b>
lea    0x8(%rsp),%r14
mov    %rsp,%rdi
call   1040 <strlen@plt>
lea    -0x8(%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1080 <fprintf@plt>
mov    %rsp,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1060 <memset@plt>
mov    $0x1,%eax
jmp    1206 <read_password+0xa6>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Warning: password truncated to the length of 8.\0A\00"
define i32 @read_password(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca i8*
store i8* %0, i8** %3
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %6, i32 256, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %39
11: ; preds = %1
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%13 = call i8* @strchr(i8* %12, i8 signext 10)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load i8*, i8** %5
store i8 0, i8* %17
br label %18
18: ; preds = %16, %11
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = icmp sgt i32 %20, 8
br i1 %21, label %22, label %31
22: ; preds = %18
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 8
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %26, 8
%28 = call i32 @memset(i8* %24, i32 0, i32 %27)
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %22, %18
%32 = load i8*, i8** %3
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%34 = call i32 @strcpy(i8* %32, i8* %33)
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = call i32 @memset(i8* %35, i32 0, i32 %37)
store i32 1, i32* %2
br label %39
39: ; preds = %31, %10
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Warning: password truncated to the length of 8.\0A\00"
define i32 @read_password(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = call i32* @fgets(i8* %3, i32 256, i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %25, label %7
7: ; preds = %1
%8 = call i8* @strchr(i8* %3, i8 signext 10)
%9 = icmp eq i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %7
store i8 0, i8* %8
br label %11
11: ; preds = %10, %7
%12 = call i32 @strlen(i8* %3)
%13 = icmp sgt i32 %12, 8
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 8
%16 = call i32 @strlen(i8* %3)
%17 = add nsw i32 %16, -8
%18 = call i32 @memset(i8* %15, i32 0, i32 %17)
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %14, %11
%22 = call i32 @strcpy(i8* %0, i8* %3)
%23 = call i32 @strlen(i8* %3)
%24 = call i32 @memset(i8* %3, i32 0, i32 %23)
br label %25
25: ; preds = %1, %21
%26 = phi i32 [ 1, %21 ], [ 0, %1 ]
ret i32 %26
}