#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();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void fill_random_hex_string(char *buf, int len) {
  int i, v;
  srand(time(NULL));
  for (i = 0; i < len; i++) {
    v = rand() % 36;
    if (v >= 26) {
      buf[i] = (char)((v - 26) + '0');
    } else {
      buf[i] = (char)(v + 'A');
    }
  }
  buf[len] = '\0';
}


x86 assembly (clang, -O0):
<fill_random_hex_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bf <fill_random_hex_string+0x8f>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x24,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
cmpl   $0x1a,-0x14(%rbp)
jl     1199 <fill_random_hex_string+0x69>
mov    -0x14(%rbp),%eax
sub    $0x1a,%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11ac <fill_random_hex_string+0x7c>
mov    -0x14(%rbp),%eax
add    $0x41,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11b1 <fill_random_hex_string+0x81>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <fill_random_hex_string+0x26>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_random_hex_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %r14d,%r14d
jle    11a0 <fill_random_hex_string+0x70>
mov    %r14d,%ebp
mov    $0x16,%r15d
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x38e38e39,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
shl    $0x2,%ecx
lea    (%rcx,%rcx,8),%ecx
sub    %ecx,%eax
cmp    $0x1a,%eax
mov    $0x41,%ecx
cmovge %r15d,%ecx
add    %al,%cl
mov    %cl,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <fill_random_hex_string+0x30>
movslq %r14d,%rax
movb   $0x0,(%r12,%rax,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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