#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int);
int rand();
void randomiseRange(FILE *fd, int start, int length) {
  for (int i = start; i < start + length; i++)
    fprintf(fd, "p16f685.ramData[0x%.3x] = 0x%.2x\n", i, rand() & 0xff);
}


x86 assembly (clang, -O0):
<randomiseRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    1187 <randomiseRange+0x67>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    %eax,%ecx
and    $0xff,%ecx
lea    0xe8c(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1138 <randomiseRange+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomiseRange>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    115e <randomiseRange+0x3e>
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
add    %esi,%ebx
lea    0xec5(%rip),%r15
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
movzbl %al,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <fprintf@plt>
add    $0x1,%ebp
cmp    %ebx,%ebp
jl     1140 <randomiseRange+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"p16f685.ramData[0x%.3x] = 0x%.2x\0A\00"
define void @randomiseRange(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
store i32 %8, i32* %7
br label %9
9: ; preds = %21, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = add nsw i32 %11, %12
%14 = icmp slt i32 %10, %13
br i1 %14, label %15, label %24
15: ; preds = %9
%16 = load i32*, i32** %4
%17 = load i32, i32* %7
%18 = call i32 (...) @rand()
%19 = and i32 %18, 255
%20 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %19)
br label %21
21: ; preds = %15
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %9
24: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"p16f685.ramData[0x%.3x] = 0x%.2x\0A\00"
define void @randomiseRange(i32* nocapture %0, i32 %1, i32 %2) {
%4 = add nsw i32 %2, %1
%5 = icmp sgt i32 %2, 0
br i1 %5, label %7, label %6
6: ; preds = %7, %3
ret void
7: ; preds = %3, %7
%8 = phi i32 [ %12, %7 ], [ %1, %3 ]
%9 = tail call i32 (...) @rand()
%10 = and i32 %9, 255
%11 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %10)
%12 = add nsw i32 %8, 1
%13 = icmp slt i32 %12, %4
br i1 %13, label %7, label %6
}