#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();
char *gen(int len, char *token) {
  char *pt = token;
  while (len--) {
    int choose = (0) + (long)((double)((double)(2) - (0) + 1.0) *
                              ((rand()) / ((2147483647) + 1.0)));
    if (choose == 0) {
      *pt = ('A') + (long)((double)((double)('Z') - ('A') + 1.0) *
                           ((rand()) / ((2147483647) + 1.0)));
    } else if (choose == 1) {
      *pt = ('a') + (long)((double)((double)('z') - ('a') + 1.0) *
                           ((rand()) / ((2147483647) + 1.0)));
    } else {
      *pt = ('0') + (long)((double)((double)('9') - ('0') + 1.0) *
                           ((rand()) / ((2147483647) + 1.0)));
    }
    pt++;
  }
  *pt = 0;
  return token;
}


x86 assembly (clang, -O0):
<gen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     123a <gen+0x12a>
mov    $0x0,%al
call   1030 <rand@plt>
cvtsi2sd %eax,%xmm1
movsd  0xeba(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xea6(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
add    $0x0,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11ad <gen+0x9d>
mov    $0x0,%al
call   1030 <rand@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe81(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe85(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
add    $0x41,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
jmp    1229 <gen+0x119>
cmpl   $0x1,-0x1c(%rbp)
jne    11f0 <gen+0xe0>
mov    $0x0,%al
call   1030 <rand@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe3e(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe42(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
add    $0x61,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
jmp    1224 <gen+0x114>
mov    $0x0,%al
call   1030 <rand@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe05(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe01(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
add    $0x30,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
jmp    1229 <gen+0x119>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1127 <gen+0x17>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rsi,%rbx
test   %edi,%edi
je     11c0 <gen+0xb0>
mov    %edi,%ebp
mov    %r14,%rbx
jmp    1171 <gen+0x61>
nopl   0x0(%rax)
mov    $0x30,%r15b
movsd  0xedd(%rip),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xeaa(%rip),%xmm1
mulsd  %xmm1,%xmm0
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%rax
add    %r15b,%al
mov    %al,(%rbx)
add    $0x1,%rbx
test   %ebp,%ebp
je     11c0 <gen+0xb0>
add    $0xffffffff,%ebp
xor    %eax,%eax
call   1030 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe76(%rip),%xmm0
mulsd  0xe76(%rip),%xmm0
cvttsd2si %xmm0,%rax
test   %eax,%eax
je     11b0 <gen+0xa0>
cmp    $0x1,%eax
jne    1130 <gen+0x20>
mov    $0x61,%r15b
movsd  0xe65(%rip),%xmm0
jmp    113b <gen+0x2b>
nopl   (%rax)
mov    $0x41,%r15b
movsd  0xe55(%rip),%xmm0
jmp    113b <gen+0x2b>
movb   $0x0,(%rbx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @gen(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
store i8* %7, i8** %5
br label %8
8: ; preds = %53, %2
%9 = load i32, i32* %3
%10 = add nsw i32 %9, -1
store i32 %10, i32* %3
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %56
12: ; preds = %8
%13 = call i32 (...) @rand()
%14 = sitofp i32 %13 to double
%15 = fdiv double %14, 0x41E0000000000000
%16 = fmul double 3.000000e+00, %15
%17 = fptosi double %16 to i64
%18 = add nsw i64 0, %17
%19 = trunc i64 %18 to i32
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %12
%23 = call i32 (...) @rand()
%24 = sitofp i32 %23 to double
%25 = fdiv double %24, 0x41E0000000000000
%26 = fmul double 2.600000e+01, %25
%27 = fptosi double %26 to i64
%28 = add nsw i64 65, %27
%29 = trunc i64 %28 to i8
%30 = load i8*, i8** %5
store i8 %29, i8* %30
br label %53
31: ; preds = %12
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = call i32 (...) @rand()
%36 = sitofp i32 %35 to double
%37 = fdiv double %36, 0x41E0000000000000
%38 = fmul double 2.600000e+01, %37
%39 = fptosi double %38 to i64
%40 = add nsw i64 97, %39
%41 = trunc i64 %40 to i8
%42 = load i8*, i8** %5
store i8 %41, i8* %42
br label %52
43: ; preds = %31
%44 = call i32 (...) @rand()
%45 = sitofp i32 %44 to double
%46 = fdiv double %45, 0x41E0000000000000
%47 = fmul double 1.000000e+01, %46
%48 = fptosi double %47 to i64
%49 = add nsw i64 48, %48
%50 = trunc i64 %49 to i8
%51 = load i8*, i8** %5
store i8 %50, i8* %51
br label %52
52: ; preds = %43, %34
br label %53
53: ; preds = %52, %22
%54 = load i8*, i8** %5
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %5
br label %8
56: ; preds = %8
%57 = load i8*, i8** %5
store i8 0, i8* %57
%58 = load i8*, i8** %4
ret i8* %58
}

LLVM IR (-O2):
define i8* @gen(i32 %0, i8* returned writeonly %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %28, label %4
4: ; preds = %2, %16
%5 = phi i32 [ %7, %16 ], [ %0, %2 ]
%6 = phi i8* [ %26, %16 ], [ %1, %2 ]
%7 = add nsw i32 %5, -1
%8 = tail call i32 (...) @rand()
%9 = sitofp i32 %8 to double
%10 = fmul double %9, 0x3E00000000000000
%11 = fmul double %10, 3.000000e+00
%12 = fptosi double %11 to i64
%13 = trunc i64 %12 to i32
switch i32 %13, label %15 [
i32 0, label %16
i32 1, label %14
]
14: ; preds = %4
br label %16
15: ; preds = %4
br label %16
16: ; preds = %4, %14, %15
%17 = phi double [ 2.600000e+01, %14 ], [ 1.000000e+01, %15 ], [ 2.600000e+01, %4 ]
%18 = phi i8 [ 97, %14 ], [ 48, %15 ], [ 65, %4 ]
%19 = tail call i32 (...) @rand()
%20 = sitofp i32 %19 to double
%21 = fmul double %20, 0x3E00000000000000
%22 = fmul double %21, %17
%23 = fptosi double %22 to i64
%24 = trunc i64 %23 to i8
%25 = add i8 %18, %24
store i8 %25, i8* %6
%26 = getelementptr inbounds i8, i8* %6, i64 1
%27 = icmp eq i32 %7, 0
br i1 %27, label %28, label %4
28: ; preds = %16, %2
%29 = phi i8* [ %1, %2 ], [ %26, %16 ]
store i8 0, i8* %29
ret i8* %1
}