#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 size_t uint32_t;
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
int const rand();
int strlen(char const *);
int32_t fsfat_test_filename_gen(char *name, const size_t len) {
  size_t i;
  uint32_t pos = 0;
  const char *buf =
      "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!$-_@";
  const int buf_len = strlen(buf);
  do {
  } while (0);
  for (i = 0; i < len; i++) {
    pos = rand() % (buf_len);
    name[i] = buf[pos];
  }
  return 0;
}


x86 assembly (clang, -O0):
<fsfat_test_filename_gen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xec1(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
jmp    1154 <fsfat_test_filename_gen+0x34>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a3 <fsfat_test_filename_gen+0x83>
mov    $0x0,%al
call   1040 <rand@plt>
cltd
idivl  -0x2c(%rbp)
movslq %edx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115c <fsfat_test_filename_gen+0x3c>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsfat_test_filename_gen>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xecb(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %r12,%r12
je     116f <fsfat_test_filename_gen+0x4f>
mov    %eax,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
cltd
idiv   %ebp
movslq %edx,%rax
movzbl (%rax,%r15,1),%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <fsfat_test_filename_gen+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [68 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!$-_@\00"
define i32 @fsfat_test_filename_gen(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %6
store i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i8*, i8** %7
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
br label %11
11: ; preds = %2
br label %12
12: ; preds = %11
store i64 0, i64* %5
br label %13
13: ; preds = %29, %12
%14 = load i64, i64* %5
%15 = load i64, i64* %4
%16 = icmp ult i64 %14, %15
br i1 %16, label %17, label %32
17: ; preds = %13
%18 = call i32 (...) @rand()
%19 = load i32, i32* %8
%20 = srem i32 %18, %19
%21 = sext i32 %20 to i64
store i64 %21, i64* %6
%22 = load i8*, i8** %7
%23 = load i64, i64* %6
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = load i8, i8* %24
%26 = load i8*, i8** %3
%27 = load i64, i64* %5
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8 %25, i8* %28
br label %29
29: ; preds = %17
%30 = load i64, i64* %5
%31 = add i64 %30, 1
store i64 %31, i64* %5
br label %13
32: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [68 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!$-_@\00"
define i32 @fsfat_test_filename_gen(i8* nocapture writeonly %0, i64 %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %1, 0
br i1 %4, label %15, label %5
5: ; preds = %2, %5
%6 = phi i64 [ %13, %5 ], [ 0, %2 ]
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, %3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [68 x i8], [68 x i8]* @.str, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 %11, i8* %12
%13 = add nuw i64 %6, 1
%14 = icmp eq i64 %13, %1
br i1 %14, label %15, label %5
15: ; preds = %5, %2
ret i32 0
}