#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 */
typedef int /*<<< orphan*/ allowed_chars;

/* Variables and functions */
char *onion_low_scalar_malloc(int);
int /*<<< orphan*/ onion_random_generate(char *, int);
char *onion_sessions_generate_id() {
  char allowed_chars[] =
      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  char *ret = onion_low_scalar_malloc(33);
  onion_random_generate(ret, 32);
  int i;
  for (i = 0; i < 32; i++) {
    ret[i] = allowed_chars[ret[i] % (sizeof(allowed_chars) - 1)];
  }
  ret[i] = '\0';
  return ret;
}


x86 assembly (clang, -O0):
<onion_sessions_generate_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x40(%rbp),%rdi
lea    0xebd(%rip),%rsi
mov    $0x3f,%edx
call   1030 <memcpy@plt>
mov    $0x21,%edi
call   1050 <onion_low_scalar_malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    $0x20,%esi
call   1040 <onion_random_generate@plt>
movl   $0x0,-0x4c(%rbp)
cmpl   $0x20,-0x4c(%rbp)
jge    11ae <onion_sessions_generate_id+0x7e>
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsbq (%rax,%rcx,1),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x40(%rbp,%rdx,1),%dl
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1170 <onion_sessions_generate_id+0x40>
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x48(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<onion_sessions_generate_id>:
push   %rbx
mov    $0x21,%edi
call   1040 <onion_low_scalar_malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x20,%esi
call   1030 <onion_random_generate@plt>
mov    $0x1,%ecx
movabs $0x8421084210842109,%r8
08 21 84
lea    0xeaf(%rip),%r9
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbq -0x1(%rbx,%rcx,1),%rsi
mov    %rsi,%rax
shr    %rax
mul    %r8
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rdi
sub    %rax,%rdi
add    %rdx,%rdi
add    %rsi,%rdi
movzbl (%r9,%rdi,1),%eax
mov    %al,-0x1(%rbx,%rcx,1)
movsbq (%rbx,%rcx,1),%rsi
mov    %rsi,%rax
shr    %rax
mul    %r8
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rdi
sub    %rax,%rdi
add    %rdx,%rdi
add    %rsi,%rdi
movzbl (%r9,%rdi,1),%eax
mov    %al,(%rbx,%rcx,1)
add    $0x2,%rcx
cmp    $0x21,%rcx
jne    1160 <onion_sessions_generate_id+0x40>
movb   $0x0,0x20(%rbx)
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@__const.onion_sessions_generate_id.allowed_chars = [63 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\00"
define i8* @onion_sessions_generate_id() {
%1 = tail call i8* @onion_low_scalar_malloc(i32 33)
%2 = tail call i32 @onion_random_generate(i8* %1, i32 32)
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ 0, %0 ], [ %18, %3 ]
%5 = getelementptr inbounds i8, i8* %1, i64 %4
%6 = load i8, i8* %5
%7 = sext i8 %6 to i64
%8 = urem i64 %7, 62
%9 = getelementptr inbounds [63 x i8], [63 x i8]* @__const.onion_sessions_generate_id.allowed_chars, i64 0, i64 %8
%10 = load i8, i8* %9
store i8 %10, i8* %5
%11 = or i64 %4, 1
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i64
%15 = urem i64 %14, 62
%16 = getelementptr inbounds [63 x i8], [63 x i8]* @__const.onion_sessions_generate_id.allowed_chars, i64 0, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %12
%18 = add nuw nsw i64 %4, 2
%19 = icmp eq i64 %18, 32
br i1 %19, label %20, label %3
20: ; preds = %3
%21 = getelementptr inbounds i8, i8* %1, i64 32
store i8 0, i8* %21
ret i8* %1
}