#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 input_line(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
unsigned int strlen(char *);
int cmdshell_init_password(char password[]) {
  char input[1000];
  int retval, retin;
  *input = '\0';
  retin = input_line("Input password: ", input, sizeof input);
  if (!retin) {
    *password = '\0';
    printf("Ok empty\n");
    retval = 1;
  } else {
    unsigned int len = strlen(input);
    if (len <= 100) {
      strcpy(password, input);
      printf("Ok %u characters\n", len);
      retval = 1;
    } else {
      printf("Fail too long password %u, "
             "maximum may be %u characters\n",
             len, 100);
      retval = 0;
    }
  }
  return retval;
}


x86 assembly (clang, -O0):
<cmdshell_init_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x3f0(%rbp)
lea    -0x3f0(%rbp),%rsi
lea    0xe9c(%rip),%rdi
mov    $0x3e8,%edx
call   1060 <input_line@plt>
mov    %eax,-0x3f8(%rbp)
cmpl   $0x0,-0x3f8(%rbp)
jne    11a5 <cmdshell_init_password+0x65>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x3f4(%rbp)
jmp    121f <cmdshell_init_password+0xdf>
lea    -0x3f0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3fc(%rbp)
cmpl   $0x64,-0x3fc(%rbp)
ja     11f7 <cmdshell_init_password+0xb7>
mov    -0x8(%rbp),%rdi
lea    -0x3f0(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x3fc(%rbp),%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x3f4(%rbp)
jmp    121a <cmdshell_init_password+0xda>
mov    -0x3fc(%rbp),%esi
lea    0xe29(%rip),%rdi
mov    $0x64,%edx
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x3f4(%rbp)
jmp    121f <cmdshell_init_password+0xdf>
mov    -0x3f4(%rbp),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmdshell_init_password>:
push   %rbp
push   %rbx
sub    $0x3e8,%rsp
mov    %rdi,%rbx
movb   $0x0,(%rsp)
lea    0xe99(%rip),%rdi
mov    %rsp,%rsi
mov    $0x3e8,%edx
call   1070 <input_line@plt>
test   %eax,%eax
je     11a9 <cmdshell_init_password+0x59>
mov    %rsp,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
cmp    $0x64,%eax
ja     11bf <cmdshell_init_password+0x6f>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe78(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebx
jmp    11d6 <cmdshell_init_password+0x86>
movb   $0x0,(%rbx)
lea    0xea9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
jmp    11d6 <cmdshell_init_password+0x86>
lea    0xe5d(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
mov    $0x64,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Input password: \00"
@.str.1 = [10 x i8] c"Ok empty\0A\00"
@.str.2 = [18 x i8] c"Ok %u characters\0A\00"
@.str.3 = [57 x i8] c"Fail too long password %u, maximum may be %u characters\0A\00"
define i32 @cmdshell_init_password(i8* %0) {
%2 = alloca i8*
%3 = alloca [1000 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
store i8 0, i8* %7
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%9 = call i32 @input_line(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %8, i32 1000)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i8*, i8** %2
store i8 0, i8* %13
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %30
15: ; preds = %1
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp ule i32 %18, 100
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i8*, i8** %2
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i32, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %24)
store i32 1, i32* %4
br label %29
26: ; preds = %15
%27 = load i32, i32* %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 100)
store i32 0, i32* %4
br label %29
29: ; preds = %26, %20
br label %30
30: ; preds = %29, %12
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@.str = [17 x i8] c"Input password: \00"
@.str.2 = [18 x i8] c"Ok %u characters\0A\00"
@.str.3 = [57 x i8] c"Fail too long password %u, maximum may be %u characters\0A\00"
@str = [9 x i8] c"Ok empty\00"
define i32 @cmdshell_init_password(i8* %0) {
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
store i8 0, i8* %3
%4 = call i32 @input_line(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %3, i32 1000)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
store i8 0, i8* %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %16
8: ; preds = %1
%9 = call i32 @strlen(i8* %3)
%10 = icmp ult i32 %9, 101
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i32 @strcpy(i8* %0, i8* %3)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %16
14: ; preds = %8
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 100)
br label %16
16: ; preds = %11, %14, %6
%17 = phi i32 [ 1, %6 ], [ 1, %11 ], [ 0, %14 ]
ret i32 %17
}