#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 */
size_t getrand16();
size_t strlen(char *);
int fillstr(char *str, int len, char *mode) {
  int i;
  for (i = 0; i < len; i++) {
    str[i] = mode[getrand16() % strlen(mode)];
  }
  str[i] = 0x00;
  return (0);
}


x86 assembly (clang, -O0):
<fillstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118e <fillstr+0x6e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <getrand16@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    -0x28(%rbp),%rax
mov    (%rax,%rdx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113a <fillstr+0x1a>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fillstr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
test   %esi,%esi
jle    1184 <fillstr+0x64>
mov    %rdx,%r15
mov    %esi,%r12d
xor    %ebx,%ebx
jmp    115a <fillstr+0x3a>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rax
xor    %edx,%edx
div    %rcx
movzbl (%r15,%rdx,1),%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
je     1187 <fillstr+0x67>
xor    %eax,%eax
call   1040 <getrand16@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    %r13,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    1140 <fillstr+0x20>
mov    %r13d,%eax
xor    %edx,%edx
div    %ecx
jmp    1148 <fillstr+0x28>
xor    %r12d,%r12d
movb   $0x0,(%r14,%r12,1)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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