#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 */
short RAND_MAX;
short rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void random_range_shorts(int length, short *ss, short from, short to) {
  srand(time(NULL));
  for (int i = 0; i < length; ++i) {
    ss[i] = (rand() * (to - from) / RAND_MAX);
  }
  return;
}


x86 assembly (clang, -O0):
<random_range_shorts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cx,%ax
mov    %dx,%cx
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %cx,-0x12(%rbp)
mov    %ax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11af <random_range_shorts+0x7f>
mov    $0x0,%al
call   1050 <rand@plt>
cwtl
movswl -0x14(%rbp),%ecx
movswl -0x12(%rbp),%edx
sub    %edx,%ecx
imul   %ecx,%eax
mov    0x2e5c(%rip),%rcx
movswl (%rcx),%ecx
cltd
idiv   %ecx
mov    %ax,%dx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1164 <random_range_shorts+0x34>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_range_shorts>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %rsi,%r13
mov    %edi,%r12d
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %r12d,%r12d
jle    11a2 <random_range_shorts+0x72>
movswl %r15w,%r15d
movswl %r14w,%eax
sub    %eax,%r15d
mov    %r12d,%ebx
mov    0x2e79(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
cwtl
imul   %r15d,%eax
movswl (%r14),%ecx
cltd
idiv   %ecx
mov    %ax,0x0(%r13,%rbp,2)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1180 <random_range_shorts+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i16 0
define void @random_range_shorts(i32 %0, i16* %1, i16 signext %2, i16 signext %3) {
%5 = alloca i32
%6 = alloca i16*
%7 = alloca i16
%8 = alloca i16
%9 = alloca i32
store i32 %0, i32* %5
store i16* %1, i16** %6
store i16 %2, i16* %7
store i16 %3, i16* %8
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
store i32 0, i32* %9
br label %12
12: ; preds = %33, %4
%13 = load i32, i32* %9
%14 = load i32, i32* %5
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %36
16: ; preds = %12
%17 = call signext i16 (...) @rand()
%18 = sext i16 %17 to i32
%19 = load i16, i16* %8
%20 = sext i16 %19 to i32
%21 = load i16, i16* %7
%22 = sext i16 %21 to i32
%23 = sub nsw i32 %20, %22
%24 = mul nsw i32 %18, %23
%25 = load i16, i16* @RAND_MAX
%26 = sext i16 %25 to i32
%27 = sdiv i32 %24, %26
%28 = trunc i32 %27 to i16
%29 = load i16*, i16** %6
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i16, i16* %29, i64 %31
store i16 %28, i16* %32
br label %33
33: ; preds = %16
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %12
36: ; preds = %12
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i16 0
define void @random_range_shorts(i32 %0, i16* nocapture writeonly %1, i16 signext %2, i16 signext %3) {
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = sext i16 %3 to i32
%10 = sext i16 %2 to i32
%11 = sub nsw i32 %9, %10
%12 = zext i32 %0 to i64
br label %14
13: ; preds = %14, %4
ret void
14: ; preds = %8, %14
%15 = phi i64 [ 0, %8 ], [ %24, %14 ]
%16 = tail call signext i16 (...) @rand()
%17 = sext i16 %16 to i32
%18 = mul nsw i32 %11, %17
%19 = load i16, i16* @RAND_MAX
%20 = sext i16 %19 to i32
%21 = sdiv i32 %18, %20
%22 = trunc i32 %21 to i16
%23 = getelementptr inbounds i16, i16* %1, i64 %15
store i16 %22, i16* %23
%24 = add nuw nsw i64 %15, 1
%25 = icmp eq i64 %24, %12
br i1 %25, label %13, label %14
}