#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 rand();
void des_random_get(unsigned char *buffer, unsigned char len) {
  unsigned char idx = 0;
  int randomNo = 0;
  for (idx = 0; idx < len; idx++) {
    if (!(idx % 3))
      randomNo = rand();
    buffer[idx] = (randomNo >> ((idx % 3) << 3)) & 0xff;
  }
}


x86 assembly (clang, -O0):
<des_random_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movb   $0x0,-0xa(%rbp)
movl   $0x0,-0x10(%rbp)
movb   $0x0,-0xa(%rbp)
movzbl -0xa(%rbp),%eax
movzbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jge    119b <des_random_get+0x8b>
movzbl -0xa(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1160 <des_random_get+0x50>
mov    $0x0,%al
call   1030 <rand@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
movzbl -0xa(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    -0x14(%rbp),%eax
mov    %edx,%ecx
shl    $0x3,%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movzbl -0xa(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0xa(%rbp),%al
add    $0x1,%al
mov    %al,-0xa(%rbp)
jmp    1131 <des_random_get+0x21>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<des_random_get>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
je     1177 <des_random_get+0x67>
mov    %rdi,%r14
movzbl %sil,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
jmp    1147 <des_random_get+0x37>
nopl   0x0(%rax,%rax,1)
mov    %eax,%edx
mov    %r12d,%ecx
sar    %cl,%edx
mov    %dl,(%r14,%rbp,1)
add    $0x1,%rbp
add    $0x8,%bl
cmp    %rbp,%r15
je     1177 <des_random_get+0x67>
movzbl %bpl,%ecx
imul   $0xab,%ecx,%ecx
shr    $0x9,%ecx
lea    0x0(,%rcx,8),%edx
lea    (%rdx,%rdx,2),%edx
mov    %ebx,%r12d
sub    %dl,%r12b
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
add    %bpl,%cl
jne    1130 <des_random_get+0x20>
xor    %eax,%eax
call   1030 <rand@plt>
jmp    1130 <des_random_get+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @des_random_get(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
%6 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
store i8 0, i8* %5
store i32 0, i32* %6
store i8 0, i8* %5
br label %7
7: ; preds = %33, %2
%8 = load i8, i8* %5
%9 = zext i8 %8 to i32
%10 = load i8, i8* %4
%11 = zext i8 %10 to i32
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %36
13: ; preds = %7
%14 = load i8, i8* %5
%15 = zext i8 %14 to i32
%16 = srem i32 %15, 3
%17 = icmp ne i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = call i32 (...) @rand()
store i32 %19, i32* %6
br label %20
20: ; preds = %18, %13
%21 = load i32, i32* %6
%22 = load i8, i8* %5
%23 = zext i8 %22 to i32
%24 = srem i32 %23, 3
%25 = shl i32 %24, 3
%26 = ashr i32 %21, %25
%27 = and i32 %26, 255
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %3
%30 = load i8, i8* %5
%31 = zext i8 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 %28, i8* %32
br label %33
33: ; preds = %20
%34 = load i8, i8* %5
%35 = add i8 %34, 1
store i8 %35, i8* %5
br label %7
36: ; preds = %7
ret void
}

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