#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 rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void generate_random_string(char *str, int size) {
  int i;
  static int init = 0;
  if (!init) {
    srand(time(NULL));
    init = 1;
  }
  for (i = 0; i < (size - 1); ++i) {
    str[i] = 'A' + (rand() % 26);
  }
  str[i] = 0;
}


x86 assembly (clang, -O0):
<generate_random_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,0x2ef6(%rip)
jne    1166 <generate_random_string+0x36>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x1,0x2ed6(%rip)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11a9 <generate_random_string+0x79>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116d <generate_random_string+0x3d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_random_string>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
cmpb   $0x0,0x2efc(%rip)
jne    1157 <generate_random_string+0x27>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movb   $0x1,0x2ee5(%rip)
cmp    $0x2,%ebp
jl     11a8 <generate_random_string+0x78>
add    $0xffffffff,%ebp
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <generate_random_string+0x40>
jmp    11aa <generate_random_string+0x7a>
xor    %ebp,%ebp
movb   $0x0,(%r14,%rbp,1)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@generate_random_string.init = internal unnamed_addr global i1 false
define void @generate_random_string(i8* nocapture writeonly %0, i32 %1) {
%3 = load i1, i1* @generate_random_string.init
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
store i1 true, i1* @generate_random_string.init
br label %7
7: ; preds = %4, %2
%8 = add i32 %1, -1
%9 = icmp sgt i32 %1, 1
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = zext i32 %8 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %19, %12 ]
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, 26
%16 = trunc i32 %15 to i8
%17 = add nsw i8 %16, 65
%18 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 %17, i8* %18
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %11
br i1 %20, label %21, label %12
21: ; preds = %12
%22 = zext i32 %8 to i64
br label %23
23: ; preds = %7, %21
%24 = phi i64 [ %22, %21 ], [ 0, %7 ]
%25 = getelementptr inbounds i8, i8* %0, i64 %24
store i8 0, i8* %25
ret void
}