#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__ isalnum(char);
int rand();
void cbusd_rand_str(char *str, int len) {
  int c = 0;
  for (; c < len; c++) {
    for (;;) {
      char x = rand() % 255;
      if (isalnum(x)) {
        str[c] = x;
        break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<cbusd_rand_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1199 <cbusd_rand_str+0x79>
jmp    1147 <cbusd_rand_str+0x27>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
je     1181 <cbusd_rand_str+0x61>
mov    -0x11(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1186 <cbusd_rand_str+0x66>
jmp    1147 <cbusd_rand_str+0x27>
jmp    118b <cbusd_rand_str+0x6b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <cbusd_rand_str+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cbusd_rand_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1183 <cbusd_rand_str+0x63>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rbx
shr    $0x20,%rbx
add    %eax,%ebx
mov    %ebx,%ecx
shr    $0x1f,%ecx
sar    $0x7,%ebx
add    %ecx,%ebx
mov    %ebx,%ecx
shl    $0x8,%ecx
sub    %ecx,%ebx
add    %eax,%ebx
movsbl %bl,%edi
call   1030 <isalnum@plt>
test   %rax,%rax
je     1140 <cbusd_rand_str+0x20>
mov    %bl,(%r14,%r12,1)
add    $0x1,%r12
cmp    %r15,%r12
jne    1140 <cbusd_rand_str+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @cbusd_rand_str(i8* nocapture writeonly %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %14
%7 = phi i64 [ 0, %4 ], [ %17, %14 ]
br label %8
8: ; preds = %6, %8
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 255
%11 = trunc i32 %10 to i8
%12 = tail call i64 @isalnum(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %8, label %14
14: ; preds = %8
%15 = trunc i32 %10 to i8
%16 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 %15, i8* %16
%17 = add nuw nsw i64 %7, 1
%18 = icmp eq i64 %17, %5
br i1 %18, label %19, label %6
19: ; preds = %14, %2
ret void
}