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

/* Variables and functions */
scalar_t__ password_to_key(char *, int /*<<< orphan*/, unsigned char *, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int password_testall(void) {
  unsigned char out[1024];
  char *test_vect[][2] = {
      {"test", "60A92A4C499497A6A50CC02F09A07054482B07F2"},
      {"longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglon"
       "g"
       "longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglon"
       "g"
       "longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglon"
       "g",
       "A0FECE50949C2B79CC3158A5A616EB2A11B42D92"},
      {"GreyGoo", "C935B7591066C8DA29EB9A1A81E6B724647FEEF4"},
  };
  unsigned int i;
  for (i = 0; i < sizeof(test_vect) / sizeof(test_vect[0]); ++i) {
    if (password_to_key(test_vect[i][0], strlen(test_vect[i][0]), out,
                        sizeof(out)) ||
        strcmp(test_vect[i][1], (char *)out)) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<password_testall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
lea    0xe9b(%rip),%rax
mov    %rax,-0x440(%rbp)
lea    0xe92(%rip),%rax
mov    %rax,-0x438(%rbp)
lea    0xead(%rip),%rax
mov    %rax,-0x430(%rbp)
lea    0xf78(%rip),%rax
mov    %rax,-0x428(%rbp)
lea    0xf93(%rip),%rax
mov    %rax,-0x420(%rbp)
lea    0xf8d(%rip),%rax
mov    %rax,-0x418(%rbp)
movl   $0x0,-0x444(%rbp)
mov    -0x444(%rbp),%eax
cmp    $0x3,%rax
jae    1283 <password_testall+0x143>
mov    -0x444(%rbp),%eax
mov    %eax,%ecx
lea    -0x440(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rax
mov    %rax,-0x450(%rbp)
mov    -0x444(%rbp),%eax
mov    %eax,%ecx
lea    -0x440(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x450(%rbp),%rdi
mov    %eax,%esi
lea    -0x410(%rbp),%rdx
mov    $0x400,%ecx
call   1060 <password_to_key@plt>
cmp    $0x0,%rax
jne    125e <password_testall+0x11e>
mov    -0x444(%rbp),%eax
mov    %eax,%ecx
lea    -0x440(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rdi
lea    -0x410(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     126a <password_testall+0x12a>
movl   $0xffffffff,-0x4(%rbp)
jmp    128a <password_testall+0x14a>
jmp    126f <password_testall+0x12f>
mov    -0x444(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x444(%rbp)
jmp    11bc <password_testall+0x7c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<password_testall>:
push   %r14
push   %rbx
sub    $0x408,%rsp
lea    0xebf(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x400,%ecx
call   1050 <password_to_key@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    11f1 <password_testall+0xc1>
lea    0xe95(%rip),%rdi
mov    %rsp,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11f1 <password_testall+0xc1>
lea    0xeaa(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rsp,%rdx
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x400,%ecx
call   1050 <password_to_key@plt>
test   %rax,%rax
jne    11f1 <password_testall+0xc1>
lea    0xf5d(%rip),%rdi
mov    %rsp,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11f1 <password_testall+0xc1>
lea    0xf72(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rsp,%rdx
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x400,%ecx
call   1050 <password_to_key@plt>
test   %rax,%rax
jne    11f1 <password_testall+0xc1>
lea    0xf54(%rip),%rdi
mov    %rsp,%rsi
call   1040 <strcmp@plt>
neg    %rax
sbb    %ebx,%ebx
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"test\00"
@.str.1 = [41 x i8] c"60A92A4C499497A6A50CC02F09A07054482B07F2\00"
@.str.2 = [217 x i8] c"longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong\00"
@.str.3 = [41 x i8] c"A0FECE50949C2B79CC3158A5A616EB2A11B42D92\00"
@.str.4 = [8 x i8] c"GreyGoo\00"
@.str.5 = [41 x i8] c"C935B7591066C8DA29EB9A1A81E6B724647FEEF4\00"
define i32 @password_testall() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca [3 x [2 x i8*]]
%4 = alloca i32
%5 = bitcast [3 x [2 x i8*]]* %3 to i8*
%6 = bitcast i8* %5 to [3 x [2 x i8*]]*
%7 = getelementptr inbounds [3 x [2 x i8*]], [3 x [2 x i8*]]* %6, i32 0, i32 0
%8 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i32 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i32 0, i32 1
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [3 x [2 x i8*]], [3 x [2 x i8*]]* %6, i32 0, i32 1
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i32 0, i32 0
store i8* getelementptr inbounds ([217 x i8], [217 x i8]* @.str.2, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i32 0, i32 1
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [3 x [2 x i8*]], [3 x [2 x i8*]]* %6, i32 0, i32 2
%14 = getelementptr inbounds [2 x i8*], [2 x i8*]* %13, i32 0, i32 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %13, i32 0, i32 1
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i32 0, i32 0), i8** %15
store i32 0, i32* %4
br label %16
16: ; preds = %46, %0
%17 = load i32, i32* %4
%18 = zext i32 %17 to i64
%19 = icmp ult i64 %18, 3
br i1 %19, label %20, label %49
20: ; preds = %16
%21 = load i32, i32* %4
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [3 x [2 x i8*]], [3 x [2 x i8*]]* %3, i64 0, i64 %22
%24 = getelementptr inbounds [2 x i8*], [2 x i8*]* %23, i64 0, i64 0
%25 = load i8*, i8** %24
%26 = load i32, i32* %4
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [3 x [2 x i8*]], [3 x [2 x i8*]]* %3, i64 0, i64 %27
%29 = getelementptr inbounds [2 x i8*], [2 x i8*]* %28, i64 0, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%33 = call i64 @password_to_key(i8* %25, i32 %31, i8* %32, i32 1024)
%34 = icmp ne i64 %33, 0
br i1 %34, label %44, label %35
35: ; preds = %20
%36 = load i32, i32* %4
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds [3 x [2 x i8*]], [3 x [2 x i8*]]* %3, i64 0, i64 %37
%39 = getelementptr inbounds [2 x i8*], [2 x i8*]* %38, i64 0, i64 1
%40 = load i8*, i8** %39
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%42 = call i64 @strcmp(i8* %40, i8* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %35, %20
store i32 -1, i32* %1
br label %50
45: ; preds = %35
br label %46
46: ; preds = %45
%47 = load i32, i32* %4
%48 = add i32 %47, 1
store i32 %48, i32* %4
br label %16
49: ; preds = %16
store i32 0, i32* %1
br label %50
50: ; preds = %49, %44
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@.str = [5 x i8] c"test\00"
@.str.1 = [41 x i8] c"60A92A4C499497A6A50CC02F09A07054482B07F2\00"
@.str.2 = [217 x i8] c"longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong\00"
@.str.3 = [41 x i8] c"A0FECE50949C2B79CC3158A5A616EB2A11B42D92\00"
@.str.4 = [8 x i8] c"GreyGoo\00"
@.str.5 = [41 x i8] c"C935B7591066C8DA29EB9A1A81E6B724647FEEF4\00"
define i32 @password_testall() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = call i64 @password_to_key(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %2, i32 1024)
%5 = icmp eq i64 %4, 0
br i1 %5, label %21, label %24
6: ; preds = %21
%7 = call i32 @strlen(i8* getelementptr inbounds ([217 x i8], [217 x i8]* @.str.2, i64 0, i64 0))
%8 = call i64 @password_to_key(i8* getelementptr inbounds ([217 x i8], [217 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* %2, i32 1024)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %6
%11 = call i64 @strcmp(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%15 = call i64 @password_to_key(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %14, i8* %2, i32 1024)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = call i64 @strcmp(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%19 = icmp ne i64 %18, 0
%20 = sext i1 %19 to i32
br label %24
21: ; preds = %0
%22 = call i64 @strcmp(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %6, label %24
24: ; preds = %17, %13, %10, %6, %0, %21
%25 = phi i32 [ -1, %21 ], [ -1, %0 ], [ -1, %6 ], [ -1, %10 ], [ -1, %13 ], [ %20, %17 ]
ret i32 %25
}