#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 */
scalar_t__ sprintf(char *, char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
unsigned char *roast_password(char *pass) {
  static char rp[256];
  static char *roast = "Tic/Toc";
  int pos = 2;
  int x;
  strcpy(rp, "0x");
  for (x = 0; (x < 150) && pass[x]; x++)
    pos += sprintf(&rp[pos], "%02x", pass[x] ^ roast[x % strlen(roast)]);
  rp[pos] = '\0';
  return rp;
}


x86 assembly (clang, -O0):
<roast_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
lea    0x2f06(%rip),%rdi
lea    0xeb7(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x96,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jge    1184 <roast_password+0x54>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1194 <roast_password+0x64>
jmp    1218 <roast_password+0xe8>
movslq -0xc(%rbp),%rcx
lea    0x2eb1(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e7c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e6b(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
mov    -0x1c(%rbp),%eax
cltd
idiv   %esi
mov    -0x18(%rbp),%eax
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
xor    %ecx,%eax
lea    0xe16(%rip),%rsi
movsbl %al,%edx
call   1050 <sprintf@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115d <roast_password+0x2d>
movslq -0xc(%rbp),%rcx
lea    0x2e2d(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e22(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roast_password>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0x2f0b(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x2,%r14d
xor    %ebx,%ebx
lea    0xea0(%rip),%r12
movzbl (%r15,%rbx,1),%r13d
test   %r13b,%r13b
je     11ae <roast_password+0x7e>
lea    0x2edf(%rip),%rax
lea    (%rax,%r14,1),%rbp
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
xor    (%rdx,%r12,1),%r13b
movsbl %r13b,%edx
mov    %rbp,%rdi
lea    0xe75(%rip),%rsi
call   1050 <sprintf@plt>
add    %eax,%r14d
add    $0x1,%rbx
movslq %r14d,%r14
cmp    $0x96,%rbx
jne    1160 <roast_password+0x30>
lea    0x2e9b(%rip),%rax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@roast_password.rp = internal global [256 x i8] zeroinitializer
@.str = [8 x i8] c"Tic/Toc\00"
@.str.1 = [3 x i8] c"0x\00"
@.str.2 = [5 x i8] c"%02x\00"
define i8* @roast_password(i8* nocapture %0) {
%2 = tail call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @roast_password.rp, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %3
3: ; preds = %1, %9
%4 = phi i64 [ 0, %1 ], [ %20, %9 ]
%5 = phi i64 [ 2, %1 ], [ %22, %9 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %4
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %24, label %9
9: ; preds = %3
%10 = getelementptr inbounds [256 x i8], [256 x i8]* @roast_password.rp, i64 0, i64 %5
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = trunc i64 %4 to i32
%13 = srem i32 %12, %11
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [8 x i8], [8 x i8]* @.str, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = xor i8 %16, %7
%18 = tail call i64 @sprintf(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8 signext %17)
%19 = add nsw i64 %18, %5
%20 = add nuw nsw i64 %4, 1
%21 = shl i64 %19, 32
%22 = ashr exact i64 %21, 32
%23 = icmp eq i64 %20, 150
br i1 %23, label %24, label %3
24: ; preds = %9, %3
%25 = phi i64 [ %22, %9 ], [ %5, %3 ]
%26 = getelementptr inbounds [256 x i8], [256 x i8]* @roast_password.rp, i64 0, i64 %25
store i8 0, i8* %26
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @roast_password.rp, i64 0, i64 0)
}