#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 /*<<< orphan*/ memcpy(char *, unsigned char *, int const);
int strlen(char *);
void decrypt_old(unsigned char *buf, int size) {
  char key[] = "SCEEDEMO2DISC";
  const int keylen = strlen(key);
  int i, j;
  for (i = 0, j = 0; i < size; i++, j++) {
    if (j == keylen) {
      memcpy(key, &buf[i - keylen], keylen);
      j = 0;
    }
    buf[i] ^= key[j];
  }
}


x86 assembly (clang, -O0):
<decrypt_old>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x1a(%rbp)
mov    0xec8(%rip),%eax
mov    %eax,-0x12(%rbp)
mov    0xec2(%rip),%ax
mov    %ax,-0xe(%rbp)
lea    -0x1a(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d3 <decrypt_old+0xb3>
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    11a2 <decrypt_old+0x82>
lea    -0x1a(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x24(%rbp),%eax
sub    -0x20(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0x20(%rbp),%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x28(%rbp)
movslq -0x28(%rbp),%rax
movsbl -0x1a(%rbp,%rax,1),%esi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
xor    %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1168 <decrypt_old+0x48>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decrypt_old>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
movabs $0x43534944324f4d,%rax
mov    %rax,0xe(%rsp)
movabs $0x4f4d454445454353,%rax
45 4d 4f
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <strlen@plt>
test   %r14d,%r14d
jle    11ad <decrypt_old+0x8d>
mov    %eax,%ebp
cltq
mov    %r14d,%r13d
mov    %r15,%r12
sub    %rax,%r12
xor    %ebx,%ebx
lea    0x8(%rsp),%r14
xor    %eax,%eax
jmp    1197 <decrypt_old+0x77>
nopl   0x0(%rax)
cltq
movzbl 0x8(%rsp,%rax,1),%ecx
xor    %cl,(%r15,%rbx,1)
add    $0x1,%rbx
add    $0x1,%eax
cmp    %rbx,%r13
je     11ad <decrypt_old+0x8d>
cmp    %ebp,%eax
jne    1180 <decrypt_old+0x60>
lea    (%r12,%rbx,1),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
jmp    1180 <decrypt_old+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.decrypt_old.key = [14 x i8] c"SCEEDEMO2DISC\00"
define void @decrypt_old(i8* %0, i32 %1) {
%3 = alloca [14 x i8]
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%5 = call i32 @strlen(i8* %4)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %29
7: ; preds = %2
%8 = sext i32 %5 to i64
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %7, %18
%11 = phi i64 [ 0, %7 ], [ %26, %18 ]
%12 = phi i32 [ 0, %7 ], [ %27, %18 ]
%13 = icmp eq i32 %12, %5
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = sub nsw i64 %11, %8
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = call i32 @memcpy(i8* %4, i8* %16, i32 %5)
br label %18
18: ; preds = %14, %10
%19 = phi i32 [ 0, %14 ], [ %12, %10 ]
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %0, i64 %11
%24 = load i8, i8* %23
%25 = xor i8 %24, %22
store i8 %25, i8* %23
%26 = add nuw nsw i64 %11, 1
%27 = add nsw i32 %19, 1
%28 = icmp eq i64 %26, %9
br i1 %28, label %29, label %10
29: ; preds = %18, %2
ret void
}