#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 */
scalar_t__ RAND_MAX;
int /*<<< orphan*/ printf(char *, char);
float rand();
int strlen(char *);
int /*<<< orphan*/ textcolor(int);
void randomprint(char *in) {
  int i;
  for (i = 0; i < strlen(in); i++) {
    int rnd = (float)6.0 * rand() / (float)RAND_MAX;
    if (rnd == 0)
      textcolor(0);
    if (rnd == 1)
      textcolor(31);
    if (rnd == 2)
      textcolor(32);
    if (rnd == 3)
      textcolor(33);
    if (rnd == 4)
      textcolor(34);
    if (rnd == 5)
      textcolor(35);
    printf("%c", in[i]);
  }
}


x86 assembly (clang, -O0):
<randomprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    1237 <randomprint+0xf7>
mov    $0x0,%al
call   1060 <rand@plt>
movaps %xmm0,%xmm1
movss  0xe7f(%rip),%xmm0
mulss  %xmm1,%xmm0
mov    0x2e5c(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11ad <randomprint+0x6d>
xor    %edi,%edi
call   1050 <textcolor@plt>
cmpl   $0x1,-0x10(%rbp)
jne    11c1 <randomprint+0x81>
mov    $0x1f,%edi
call   1050 <textcolor@plt>
cmpl   $0x2,-0x10(%rbp)
jne    11d5 <randomprint+0x95>
mov    $0x20,%edi
call   1050 <textcolor@plt>
cmpl   $0x3,-0x10(%rbp)
jne    11e9 <randomprint+0xa9>
mov    $0x21,%edi
call   1050 <textcolor@plt>
cmpl   $0x4,-0x10(%rbp)
jne    11fd <randomprint+0xbd>
mov    $0x22,%edi
call   1050 <textcolor@plt>
cmpl   $0x5,-0x10(%rbp)
jne    1211 <randomprint+0xd1>
mov    $0x23,%edi
call   1050 <textcolor@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
lea    0xde4(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1153 <randomprint+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomprint>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r13
call   1030 <strlen@plt>
test   %eax,%eax
jle    11c2 <randomprint+0x82>
mov    0x2e8c(%rip),%r15
lea    0xea5(%rip),%r12
lea    0xe9a(%rip),%r14
xor    %ebx,%ebx
jmp    1191 <randomprint+0x51>
xchg   %ax,%ax
movsbl 0x0(%r13,%rbx,1),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
mov    %r13,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11c2 <randomprint+0x82>
xor    %eax,%eax
call   1060 <rand@plt>
mulss  0xe60(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq (%r15),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
cmp    $0x5,%eax
ja     1170 <randomprint+0x30>
cltq
mov    (%r12,%rax,4),%edi
call   1050 <textcolor@plt>
jmp    1170 <randomprint+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
@.str = [3 x i8] c"%c\00"
define void @randomprint(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %5
5: ; preds = %53, %1
%6 = load i32, i32* %3
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = icmp slt i32 %6, %8
br i1 %9, label %10, label %56
10: ; preds = %5
%11 = call float (...) @rand()
%12 = fmul float 6.000000e+00, %11
%13 = load i64, i64* @RAND_MAX
%14 = sitofp i64 %13 to float
%15 = fdiv float %12, %14
%16 = fptosi float %15 to i32
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = call i32 @textcolor(i32 0)
br label %21
21: ; preds = %19, %10
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @textcolor(i32 31)
br label %26
26: ; preds = %24, %21
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @textcolor(i32 32)
br label %31
31: ; preds = %29, %26
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 3
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 @textcolor(i32 33)
br label %36
36: ; preds = %34, %31
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 4
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @textcolor(i32 34)
br label %41
41: ; preds = %39, %36
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 5
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @textcolor(i32 35)
br label %46
46: ; preds = %44, %41
%47 = load i8*, i8** %2
%48 = load i32, i32* %3
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
%52 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %51)
br label %53
53: ; preds = %46
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 1
store i32 %55, i32* %3
br label %5
56: ; preds = %5
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@.str = [3 x i8] c"%c\00"
@switch.table.randomprint = [6 x i32] [i32 0, i32 31, i32 32, i32 33, i32 34, i32 35]
define void @randomprint(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %26
4: ; preds = %1, %18
%5 = phi i64 [ %22, %18 ], [ 0, %1 ]
%6 = tail call float (...) @rand()
%7 = fmul float %6, 6.000000e+00
%8 = load i64, i64* @RAND_MAX
%9 = sitofp i64 %8 to float
%10 = fdiv float %7, %9
%11 = fptosi float %10 to i32
%12 = icmp ult i32 %11, 6
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.randomprint, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = tail call i32 @textcolor(i32 %16)
br label %18
18: ; preds = %4, %13
%19 = getelementptr inbounds i8, i8* %0, i64 %5
%20 = load i8, i8* %19
%21 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %20)
%22 = add nuw nsw i64 %5, 1
%23 = tail call i32 @strlen(i8* %0)
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %4, label %26
26: ; preds = %18, %1
ret void
}