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


x86 assembly (clang, -O0):
<random_unsigned_shorts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a6 <random_unsigned_shorts+0x76>
mov    $0x0,%al
call   1050 <rand@plt>
movzwl %ax,%eax
mov    0x2e75(%rip),%rcx
movzwl (%rcx),%ecx
sub    $0x0,%ecx
imul   %ecx,%eax
mov    0x2e5d(%rip),%rcx
movzwl (%rcx),%ecx
cltd
idiv   %ecx
mov    %ax,%dx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <random_unsigned_shorts+0x26>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_unsigned_shorts>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %edi,%ebp
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %ebp,%ebp
jle    1197 <random_unsigned_shorts+0x67>
mov    %ebp,%ebp
mov    0x2e90(%rip),%r14
mov    0x2e81(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
movzwl %ax,%ecx
movzwl (%r14),%eax
imul   %ecx,%eax
movzwl (%r15),%ecx
xor    %edx,%edx
div    %ecx
mov    %ax,(%r12,%rbx,2)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <random_unsigned_shorts+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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