#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 */
char rand();
size_t randomize_buffer(char *buffer, size_t len) {
  size_t no_chars = len - 1;
  size_t i;
  for (i = 0; i < no_chars; ++i) {
    buffer[i] = rand() % ('Z' - 'A' + 1) + 'A';
  };
  buffer[no_chars] = '\0';
  return no_chars;
}


x86 assembly (clang, -O0):
<randomize_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1173 <randomize_buffer+0x63>
mov    $0x0,%al
call   1030 <rand@plt>
movsbl %al,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1134 <randomize_buffer+0x24>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomize_buffer>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
add    $0xffffffffffffffff,%r15
je     1164 <randomize_buffer+0x54>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <rand@plt>
movsbl %al,%eax
imul   $0x4f,%eax,%ecx
movzwl %cx,%edx
shr    $0xb,%ecx
shr    $0xf,%edx
add    %cl,%dl
movzbl %dl,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %dl,%al
add    $0x41,%al
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <randomize_buffer+0x20>
movb   $0x0,(%r14,%r15,1)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @randomize_buffer(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
%8 = sub i64 %7, 1
store i64 %8, i64* %5
store i64 0, i64* %6
br label %9
9: ; preds = %22, %2
%10 = load i64, i64* %6
%11 = load i64, i64* %5
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = call signext i8 (...) @rand()
%15 = sext i8 %14 to i32
%16 = srem i32 %15, 26
%17 = add nsw i32 %16, 65
%18 = trunc i32 %17 to i8
%19 = load i8*, i8** %3
%20 = load i64, i64* %6
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8 %18, i8* %21
br label %22
22: ; preds = %13
%23 = load i64, i64* %6
%24 = add i64 %23, 1
store i64 %24, i64* %6
br label %9
25: ; preds = %9
%26 = load i8*, i8** %3
%27 = load i64, i64* %5
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8 0, i8* %28
%29 = load i64, i64* %5
ret i64 %29
}

LLVM IR (-O2):
define i64 @randomize_buffer(i8* nocapture writeonly %0, i64 %1) {
%3 = add i64 %1, -1
%4 = icmp eq i64 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %2, %5
%6 = phi i64 [ %11, %5 ], [ 0, %2 ]
%7 = tail call signext i8 (...) @rand()
%8 = srem i8 %7, 26
%9 = add nsw i8 %8, 65
%10 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 %9, i8* %10
%11 = add nuw i64 %6, 1
%12 = icmp eq i64 %11, %3
br i1 %12, label %13, label %5
13: ; preds = %5, %2
%14 = getelementptr inbounds i8, i8* %0, i64 %3
store i8 0, i8* %14
ret i64 %3
}