#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();
void get_random_string(char *str, size_t size) {
  const char charset[] = "abcdefghijklmnopqrstuvwxyz";
  int i;
  for (i = 0; i < size; i++) {
    int index = rand() % (sizeof charset - 1);
    str[i] = charset[index];
  }
  str[size] = '\0';
}


x86 assembly (clang, -O0):
<get_random_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xed9(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed6(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xed3(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed0(%rip),%ax
mov    %ax,-0x18(%rbp)
mov    0xec8(%rip),%al
mov    %al,-0x16(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a3 <get_random_string+0x93>
mov    $0x0,%al
call   1030 <rand@plt>
cltq
mov    $0x1a,%ecx
xor    %edx,%edx
div    %rcx
mov    %edx,%eax
mov    %eax,-0x38(%rbp)
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    115c <get_random_string+0x4c>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_random_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r13
mov    %rdi,%r14
test   %rsi,%rsi
je     1174 <get_random_string+0x64>
movabs $0x4ec4ec4ec4ec4ec5,%r15
ec c4 4e
lea    0xecb(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
mul    %r15
shr    $0x3,%rdx
lea    (%rdx,%rdx,4),%rax
lea    (%rax,%rax,4),%rax
add    %rdx,%rax
sub    %rax,%rcx
movzbl (%r12,%rcx,1),%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1140 <get_random_string+0x30>
movb   $0x0,(%r14,%r13,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.get_random_string.charset = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
define void @get_random_string(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [27 x i8]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = bitcast [27 x i8]* %5 to i8*
store i32 0, i32* %6
br label %9
9: ; preds = %27, %2
%10 = load i32, i32* %6
%11 = sext i32 %10 to i64
%12 = load i64, i64* %4
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %30
14: ; preds = %9
%15 = call i32 (...) @rand()
%16 = sext i32 %15 to i64
%17 = urem i64 %16, 26
%18 = trunc i64 %17 to i32
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [27 x i8], [27 x i8]* %5, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = load i8*, i8** %3
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 %22, i8* %26
br label %27
27: ; preds = %14
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %9
30: ; preds = %9
%31 = load i8*, i8** %3
%32 = load i64, i64* %4
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8 0, i8* %33
ret void
}

LLVM IR (-O2):
@__const.get_random_string.charset = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
define void @get_random_string(i8* nocapture writeonly %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %14, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %12, %4 ], [ 0, %2 ]
%6 = tail call i32 (...) @rand()
%7 = sext i32 %6 to i64
%8 = urem i64 %7, 26
%9 = getelementptr inbounds [27 x i8], [27 x i8]* @__const.get_random_string.charset, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 %10, i8* %11
%12 = add nuw i64 %5, 1
%13 = icmp eq i64 %12, %1
br i1 %13, label %14, label %4
14: ; preds = %4, %2
%15 = getelementptr inbounds i8, i8* %0, i64 %1
store i8 0, i8* %15
ret void
}