#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 random();
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void create_password(char *dst, size_t len) {
  srandom(time(NULL));
  for (size_t i = 0; i < len - 1; i++) {
    dst[i] = 'A' + random() % ('Z' - 'A');
  }
  dst[len - 1] = '\0';
}


x86 assembly (clang, -O0):
<create_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    119e <create_password+0x6e>
mov    $0x0,%al
call   1050 <random@plt>
movsbl %al,%eax
mov    $0x19,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1158 <create_password+0x28>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_password>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
add    $0xffffffffffffffff,%r15
je     1195 <create_password+0x65>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <random@plt>
movsbl %al,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rax,%rcx,8),%ecx
movzwl %cx,%edx
shr    $0xa,%ecx
shr    $0xf,%edx
add    %cl,%dl
movzbl %dl,%ecx
lea    (%rcx,%rcx,4),%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %cl,%al
add    $0x41,%al
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <create_password+0x30>
movb   $0x0,(%r14,%r15,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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