#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 testPrngValue(unsigned int);
void testPrngString(unsigned int iVal, char *aOut, int nOut) {
  int i;
  for (i = 0; i < (nOut - 1); i++) {
    aOut[i] = 'a' + (testPrngValue(iVal + i) % 26);
  }
  aOut[i] = '\0';
}


x86 assembly (clang, -O0):
<testPrngString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1169 <testPrngString+0x59>
mov    -0x4(%rbp),%edi
add    -0x18(%rbp),%edi
call   1030 <testPrngValue@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1129 <testPrngString+0x19>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testPrngString>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edx
jl     116a <testPrngString+0x5a>
add    $0xffffffff,%edx
mov    %edx,%r15d
mov    %edi,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbx,1),%edi
call   1030 <testPrngValue@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x61,%al
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <testPrngString+0x20>
jmp    116d <testPrngString+0x5d>
xor    %r15d,%r15d
movb   $0x0,(%r14,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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