#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 */
scalar_t__ space(int);
scalar_t__ strlen(char const *);
int urn();
char *random_string(int l, const char symbols[]) {
  char *r;
  int i, rn, base;
  base = (int)strlen(symbols);
  r = (char *)space(sizeof(char) * (l + 1));
  for (i = 0; i < l; i++) {
    rn = (int)(urn() * base);
    r[i] = symbols[rn];
  }
  r[l] = '\0';
  return r;
}


x86 assembly (clang, -O0):
<random_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <space@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a7 <random_string+0x77>
mov    $0x0,%al
call   1050 <urn@plt>
imul   -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <random_string+0x39>
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
lea    0x1(%r14),%edi
call   1030 <space@plt>
mov    %rax,%r13
test   %r14d,%r14d
jle    1190 <random_string+0x60>
mov    %r14d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <urn@plt>
imul   %r12d,%eax
cltq
movzbl (%r15,%rax,1),%eax
mov    %al,0x0(%r13,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1170 <random_string+0x40>
movslq %r14d,%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @random_string(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = trunc i64 %10 to i32
store i32 %11, i32* %8
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = mul i64 1, %14
%16 = trunc i64 %15 to i32
%17 = call i64 @space(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %5
store i32 0, i32* %6
br label %19
19: ; preds = %36, %2
%20 = load i32, i32* %6
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %39
23: ; preds = %19
%24 = call i32 (...) @urn()
%25 = load i32, i32* %8
%26 = mul nsw i32 %24, %25
store i32 %26, i32* %7
%27 = load i8*, i8** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %5
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
br label %36
36: ; preds = %23
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %19
39: ; preds = %19
%40 = load i8*, i8** %5
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 0, i8* %43
%44 = load i8*, i8** %5
ret i8* %44
}

LLVM IR (-O2):
define i8* @random_string(i32 %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = trunc i64 %3 to i32
%5 = add nsw i32 %0, 1
%6 = tail call i64 @space(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %21
9: ; preds = %2
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %19, %11 ]
%13 = tail call i32 (...) @urn()
%14 = mul nsw i32 %13, %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %7, i64 %12
store i8 %17, i8* %18
%19 = add nuw nsw i64 %12, 1
%20 = icmp eq i64 %19, %10
br i1 %20, label %21, label %11
21: ; preds = %11, %2
%22 = sext i32 %0 to i64
%23 = getelementptr inbounds i8, i8* %7, i64 %22
store i8 0, i8* %23
ret i8* %7
}