#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 strlen(char const *);
void crypt_new(unsigned char *buf, int size) {
  static const char key[] = "Sir Robert McAlpine Fine Cranes";
  int i;
  for (i = 0; i < size; i++)
    buf[i] ^= key[i % strlen(key)];
}


x86 assembly (clang, -O0):
<crypt_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1179 <crypt_new+0x69>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    0xec1(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0xeaa(%rip),%rax
movsbl (%rax,%rcx,1),%esi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
xor    %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <crypt_new+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypt_new>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1151 <crypt_new+0x41>
mov    %rdi,%r14
mov    %esi,%r12d
xor    %ebx,%ebx
lea    0xed5(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
movzbl (%rdx,%r15,1),%eax
xor    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <crypt_new+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@crypt_new.key = internal constant [32 x i8] c"Sir Robert McAlpine Fine Cranes\00"
define void @crypt_new(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %26, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %29
10: ; preds = %6
%11 = load i32, i32* %5
%12 = call i32 @strlen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @crypt_new.key, i64 0, i64 0))
%13 = srem i32 %11, %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [32 x i8], [32 x i8]* @crypt_new.key, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = xor i32 %23, %17
%25 = trunc i32 %24 to i8
store i8 %25, i8* %21
br label %26
26: ; preds = %10
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %6
29: ; preds = %6
ret void
}

LLVM IR (-O2):
@crypt_new.key = internal constant [32 x i8] c"Sir Robert McAlpine Fine Cranes\00"
define void @crypt_new(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %17, %6 ]
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @crypt_new.key, i64 0, i64 0))
%9 = trunc i64 %7 to i32
%10 = srem i32 %9, %8
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [32 x i8], [32 x i8]* @crypt_new.key, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %0, i64 %7
%15 = load i8, i8* %14
%16 = xor i8 %15, %13
store i8 %16, i8* %14
%17 = add nuw nsw i64 %7, 1
%18 = icmp eq i64 %17, %5
br i1 %18, label %19, label %6
19: ; preds = %6, %2
ret void
}