#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*/ output;
typedef int /*<<< orphan*/ hash;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, char const);
size_t strlen(char const *const);
char *toc_hash_password(const char *const password) {
  const unsigned char hash[] = "Tic/Toc";
  static char output[(2 * 1024)];
  size_t length;
  int i, newcounter;
  length = strlen(password);
  output[0] = '0';
  output[1] = 'x';
  newcounter = 2;
  for (i = 0; i < length; i++) {
    if (newcounter >= sizeof(output) - 2 - 1)
      return (NULL);
    sprintf(output + newcounter, "%02X",
            password[i] ^ hash[i % (sizeof(hash) - 1)]);
    newcounter += 2;
  }
  output[newcounter] = 0;
  return (output);
}


x86 assembly (clang, -O0):
<toc_hash_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xecd(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
movb   $0x30,0x2ef5(%rip)
movb   $0x78,0x2eef(%rip)
movl   $0x2,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11e6 <toc_hash_password+0xc6>
movslq -0x28(%rbp),%rax
cmp    $0x7fd,%rax
jb     118b <toc_hash_password+0x6b>
movq   $0x0,-0x8(%rbp)
jmp    1200 <toc_hash_password+0xe0>
movslq -0x28(%rbp),%rax
lea    0x2eaa(%rip),%rdi
add    %rax,%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
movslq -0x24(%rbp),%rax
mov    $0x7,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x2c(%rbp),%eax
movzbl -0x18(%rbp,%rdx,1),%ecx
xor    %ecx,%eax
lea    0xe41(%rip),%rsi
movsbl %al,%edx
call   1040 <sprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1160 <toc_hash_password+0x40>
movslq -0x28(%rbp),%rcx
lea    0x2e4f(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e44(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toc_hash_password>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
movw   $0x7830,0x2f04(%rip)
30 78
test   %rax,%rax
je     11c1 <toc_hash_password+0xa1>
mov    %rax,%r13
mov    $0x2,%ebp
movabs $0x2492492492492493,%r14
49 92 24
lea    0xeaa(%rip),%r12
xor    %ebx,%ebx
mov    %rbx,%rax
mul    %r14
cmp    $0x3fe,%rbx
je     11d4 <toc_hash_password+0xb4>
mov    %rbx,%rax
sub    %rdx,%rax
shr    %rax
add    %rdx,%rax
shr    $0x2,%rax
lea    0x0(,%rax,8),%rcx
sub    %rcx,%rax
lea    0x2eaf(%rip),%rcx
lea    (%rcx,%rbp,1),%rdi
add    %rbx,%rax
lea    0xe61(%rip),%rcx
movzbl (%rcx,%rax,1),%eax
xor    (%r15,%rbx,1),%al
movsbl %al,%edx
mov    %r12,%rsi
call   1040 <sprintf@plt>
add    $0x2,%rbp
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1160 <toc_hash_password+0x40>
jmp    11c6 <toc_hash_password+0xa6>
mov    $0x2,%ebp
lea    0x2e73(%rip),%rax
movb   $0x0,0x0(%rbp,%rax,1)
jmp    11d6 <toc_hash_password+0xb6>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.toc_hash_password.hash = [8 x i8] c"Tic/Toc\00"
@toc_hash_password.output = internal global [2048 x i8] zeroinitializer
@.str = [5 x i8] c"%02X\00"
define i8* @toc_hash_password(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [8 x i8]
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
%8 = bitcast [8 x i8]* %4 to i8*
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %5
store i8 48, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @toc_hash_password.output, i64 0, i64 0)
store i8 120, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @toc_hash_password.output, i64 0, i64 1)
store i32 2, i32* %7
store i32 0, i32* %6
br label %11
11: ; preds = %42, %1
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = load i64, i64* %5
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %45
16: ; preds = %11
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = icmp uge i64 %18, 2045
br i1 %19, label %20, label %21
20: ; preds = %16
store i8* null, i8** %2
br label %49
21: ; preds = %16
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @toc_hash_password.output, i64 0, i64 0), i64 %23
%25 = load i8*, i8** %3
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = urem i64 %32, 7
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = xor i32 %30, %36
%38 = trunc i32 %37 to i8
%39 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %38)
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 2
store i32 %41, i32* %7
br label %42
42: ; preds = %21
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %11
45: ; preds = %11
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [2048 x i8], [2048 x i8]* @toc_hash_password.output, i64 0, i64 %47
store i8 0, i8* %48
store i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @toc_hash_password.output, i64 0, i64 0), i8** %2
br label %49
49: ; preds = %45, %20
%50 = load i8*, i8** %2
ret i8* %50
}

LLVM IR (-O2):
@__const.toc_hash_password.hash = [8 x i8] c"Tic/Toc\00"
@toc_hash_password.output = internal global [2048 x i8] zeroinitializer
@.str = [5 x i8] c"%02X\00"
define i8* @toc_hash_password(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
store i8 48, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @toc_hash_password.output, i64 0, i64 0)
store i8 120, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @toc_hash_password.output, i64 0, i64 1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %24, label %4
4: ; preds = %1, %8
%5 = phi i64 [ %20, %8 ], [ 0, %1 ]
%6 = phi i64 [ %19, %8 ], [ 2, %1 ]
%7 = icmp eq i64 %5, 1022
br i1 %7, label %27, label %8
8: ; preds = %4
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* @toc_hash_password.output, i64 0, i64 %6
%10 = getelementptr inbounds i8, i8* %0, i64 %5
%11 = load i8, i8* %10
%12 = trunc i64 %5 to i32
%13 = urem i32 %12, 7
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [8 x i8], [8 x i8]* @__const.toc_hash_password.hash, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = xor i8 %16, %11
%18 = tail call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %17)
%19 = add nuw nsw i64 %6, 2
%20 = add nuw nsw i64 %5, 1
%21 = icmp eq i64 %20, %2
br i1 %21, label %22, label %4
22: ; preds = %8
%23 = and i64 %19, 4294967294
br label %24
24: ; preds = %22, %1
%25 = phi i64 [ 2, %1 ], [ %23, %22 ]
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* @toc_hash_password.output, i64 0, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %4, %24
%28 = phi i8* [ getelementptr inbounds ([2048 x i8], [2048 x i8]* @toc_hash_password.output, i64 0, i64 0), %24 ], [ null, %4 ]
ret i8* %28
}