#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*/ password;
typedef int /*<<< orphan*/ DES_key_schedule;
typedef char DES_cblock;

/* Variables and functions */
int /*<<< orphan*/ DES_cbc_cksum(unsigned char *, char *, int,
                                 int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ DES_key_sched(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ des_set_odd_parity(char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void afs_transarc_StringToKey(char *str, char *cell, DES_cblock *key) {
  DES_key_schedule schedule;
  DES_cblock temp_key;
  DES_cblock ivec;
  char password[512];
  int passlen;
  strncpy(password, str, sizeof(password));
  password[sizeof(password) - 1] = '\0';
  if ((passlen = strlen(password)) < sizeof(password) - 1)
    strncat(password, cell, sizeof(password) - passlen);
  if ((passlen = strlen(password)) > sizeof(password))
    passlen = sizeof(password);
  memcpy(&ivec, "kerberos", 8);
  memcpy(&temp_key, "kerberos", 8);
  des_set_odd_parity(&temp_key);
  DES_key_sched(&temp_key, &schedule);
  DES_cbc_cksum((unsigned char *)password, &ivec, passlen, &schedule, &ivec);
  memcpy(&temp_key, &ivec, 8);
  des_set_odd_parity(&temp_key);
  DES_key_sched(&temp_key, &schedule);
  DES_cbc_cksum((unsigned char *)password, key, passlen, &schedule, &ivec);
  des_set_odd_parity(key);
}


x86 assembly (clang, -O0):
<afs_transarc_StringToKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x224(%rbp)
cltq
cmp    $0x1ff,%rax
jae    11e1 <afs_transarc_StringToKey+0x71>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x224(%rbp),%rcx
mov    $0x200,%eax
sub    %rcx,%rax
mov    %eax,%edx
call   1060 <strncat@plt>
lea    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x224(%rbp)
cltq
cmp    $0x200,%rax
jbe    120b <afs_transarc_StringToKey+0x9b>
movl   $0x200,-0x224(%rbp)
lea    0xdee(%rip),%rsi
lea    -0x1e(%rbp),%rdi
mov    $0x8,%edx
call   1070 <memcpy@plt>
lea    0xdd9(%rip),%rsi
lea    -0x1d(%rbp),%rdi
mov    $0x8,%edx
call   1070 <memcpy@plt>
lea    -0x1d(%rbp),%rdi
call   1090 <des_set_odd_parity@plt>
lea    -0x1d(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1080 <DES_key_sched@plt>
lea    -0x220(%rbp),%rdi
mov    -0x224(%rbp),%edx
lea    -0x1e(%rbp),%r8
lea    -0x1c(%rbp),%rcx
mov    %r8,%rsi
call   1040 <DES_cbc_cksum@plt>
lea    -0x1d(%rbp),%rdi
lea    -0x1e(%rbp),%rsi
mov    $0x8,%edx
call   1070 <memcpy@plt>
lea    -0x1d(%rbp),%rdi
call   1090 <des_set_odd_parity@plt>
lea    -0x1d(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1080 <DES_key_sched@plt>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x224(%rbp),%edx
lea    -0x1c(%rbp),%rcx
lea    -0x1e(%rbp),%r8
call   1040 <DES_cbc_cksum@plt>
mov    -0x18(%rbp),%rdi
call   1090 <des_set_odd_parity@plt>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<afs_transarc_StringToKey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rsi
lea    0x10(%rsp),%rbx
mov    $0x200,%ebp
mov    %rbx,%rdi
mov    $0x200,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x20f(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x1fe,%eax
ja     11cc <afs_transarc_StringToKey+0x5c>
mov    $0x200,%edx
sub    %eax,%edx
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
call   1060 <strncat@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    $0x200,%eax
cmovb  %eax,%ebp
lea    0xe18(%rip),%r13
lea    0xa(%rsp),%r12
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x8,%edx
call   1070 <memcpy@plt>
lea    0xb(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x8,%edx
call   1070 <memcpy@plt>
mov    %rbx,%rdi
call   1090 <des_set_odd_parity@plt>
lea    0xc(%rsp),%r13
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <DES_key_sched@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r13,%rcx
mov    %r12,%r8
call   1040 <DES_cbc_cksum@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x8,%edx
call   1070 <memcpy@plt>
mov    %rbx,%rdi
call   1090 <des_set_odd_parity@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <DES_key_sched@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r13,%rcx
mov    %r12,%r8
call   1040 <DES_cbc_cksum@plt>
mov    %r15,%rdi
call   1090 <des_set_odd_parity@plt>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"kerberos\00"
define void @afs_transarc_StringToKey(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
%10 = alloca [512 x i8]
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = call i32 @strncpy(i8* %12, i8* %13, i32 512)
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 511
store i8 0, i8* %15
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %11
%18 = sext i32 %17 to i64
%19 = icmp ult i64 %18, 511
br i1 %19, label %20, label %28
20: ; preds = %3
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%22 = load i8*, i8** %5
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = sub i64 512, %24
%26 = trunc i64 %25 to i32
%27 = call i32 @strncat(i8* %21, i8* %22, i32 %26)
br label %28
28: ; preds = %20, %3
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
store i32 %30, i32* %11
%31 = sext i32 %30 to i64
%32 = icmp ugt i64 %31, 512
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 512, i32* %11
br label %34
34: ; preds = %33, %28
%35 = call i32 @memcpy(i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%36 = call i32 @memcpy(i8* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%37 = call i32 @des_set_odd_parity(i8* %8)
%38 = call i32 @DES_key_sched(i8* %8, i32* %7)
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%40 = load i32, i32* %11
%41 = call i32 @DES_cbc_cksum(i8* %39, i8* %9, i32 %40, i32* %7, i8* %9)
%42 = call i32 @memcpy(i8* %8, i8* %9, i32 8)
%43 = call i32 @des_set_odd_parity(i8* %8)
%44 = call i32 @DES_key_sched(i8* %8, i32* %7)
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%46 = load i8*, i8** %6
%47 = load i32, i32* %11
%48 = call i32 @DES_cbc_cksum(i8* %45, i8* %46, i32 %47, i32* %7, i8* %9)
%49 = load i8*, i8** %6
%50 = call i32 @des_set_odd_parity(i8* %49)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"kerberos\00"
define void @afs_transarc_StringToKey(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca [512 x i8]
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%10 = call i32 @strncpy(i8* %9, i8* %0, i32 512)
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 511
store i8 0, i8* %11
%12 = call i32 @strlen(i8* %9)
%13 = icmp ult i32 %12, 511
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = sub nuw nsw i32 512, %12
%16 = call i32 @strncat(i8* %9, i8* %1, i32 %15)
br label %17
17: ; preds = %14, %3
%18 = call i32 @strlen(i8* %9)
%19 = icmp ult i32 %18, 512
%20 = select i1 %19, i32 %18, i32 512
%21 = call i32 @memcpy(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%22 = call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%23 = call i32 @des_set_odd_parity(i8* %5)
%24 = call i32 @DES_key_sched(i8* %5, i32* %4)
%25 = call i32 @DES_cbc_cksum(i8* %9, i8* %6, i32 %20, i32* %4, i8* %6)
%26 = call i32 @memcpy(i8* %5, i8* %6, i32 8)
%27 = call i32 @des_set_odd_parity(i8* %5)
%28 = call i32 @DES_key_sched(i8* %5, i32* %4)
%29 = call i32 @DES_cbc_cksum(i8* %9, i8* %2, i32 %20, i32* %4, i8* %6)
%30 = call i32 @des_set_odd_parity(i8* %2)
ret void
}