#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 */
struct timeval {
  int tv_usec;
  int tv_sec;
};
typedef int /*<<< orphan*/ an;

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
char *malloc(int);
int rand();
int /*<<< orphan*/ srand(int);
char *gen_uuid() {
  char *buf;
  int sz = 10;
  buf = NULL;
  buf = malloc(sz * sizeof(char));
  struct timeval t;
  gettimeofday(&t, NULL);
  srand(t.tv_usec * t.tv_sec);
  static const char an[] = "0123456789"
                           "abcdefghijklmnopqrstuvwxyz"
                           "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int i;
  int j = sz - 1;
  for (i = 0; i < j; ++i) {
    buf[i] = an[rand() % (sizeof(an) - 1)];
  }
  buf[sz - 1] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<gen_uuid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xa,-0xc(%rbp)
movq   $0x0,-0x8(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%edi
imul   -0x14(%rbp),%edi
call   1040 <srand@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11d5 <gen_uuid+0x95>
mov    $0x0,%al
call   1060 <rand@plt>
cltq
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
lea    0xe47(%rip),%rax
mov    (%rax,%rdx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1193 <gen_uuid+0x53>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_uuid>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0xc(%rsp),%edi
imul   0x8(%rsp),%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
shr    %rax
movabs $0x8421084210842109,%r14
08 21 84
mul    %r14
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
lea    0xe55(%rip),%r15
mov    (%r15,%rsi,1),%al
mov    %al,(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
shr    %rax
mul    %r14
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
mov    (%r15,%rsi,1),%al
mov    %al,0x1(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
shr    %rax
mul    %r14
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
mov    (%r15,%rsi,1),%al
mov    %al,0x2(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
shr    %rax
mul    %r14
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
mov    (%r15,%rsi,1),%al
mov    %al,0x3(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
shr    %rax
mul    %r14
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
mov    (%r15,%rsi,1),%al
mov    %al,0x4(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
shr    %rax
mul    %r14
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
mov    (%r15,%rsi,1),%al
mov    %al,0x5(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
shr    %rax
mul    %r14
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
mov    (%r15,%rsi,1),%al
mov    %al,0x6(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
shr    %rax
mul    %r14
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
mov    (%r15,%rsi,1),%al
mov    %al,0x7(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
shr    %rax
mul    %r14
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
mov    (%r15,%rsi,1),%al
mov    %al,0x8(%rbx)
movb   $0x0,0x9(%rbx)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@gen_uuid.an = internal constant [63 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i8* @gen_uuid() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = alloca i32
store i32 10, i32* %2
store i8* null, i8** %1
%6 = load i32, i32* %2
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 1
%9 = trunc i64 %8 to i32
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %1
%11 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%15 = load i32, i32* %14
%16 = mul nsw i32 %13, %15
%17 = call i32 @srand(i32 %16)
%18 = load i32, i32* %2
%19 = sub nsw i32 %18, 1
store i32 %19, i32* %5
store i32 0, i32* %4
br label %20
20: ; preds = %34, %0
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %37
24: ; preds = %20
%25 = call i32 (...) @rand()
%26 = sext i32 %25 to i64
%27 = urem i64 %26, 62
%28 = getelementptr inbounds [63 x i8], [63 x i8]* @gen_uuid.an, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = load i8*, i8** %1
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
br label %34
34: ; preds = %24
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %20
37: ; preds = %20
%38 = load i8*, i8** %1
%39 = load i32, i32* %2
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
store i8 0, i8* %42
%43 = load i8*, i8** %1
ret i8* %43
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@gen_uuid.an = internal unnamed_addr constant [63 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define noalias i8* @gen_uuid() {
%1 = alloca %struct.timeval
%2 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%3 = bitcast %struct.timeval* %1 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%8 = load i32, i32* %7
%9 = mul nsw i32 %8, %6
%10 = tail call i32 @srand(i32 %9)
%11 = tail call i32 (...) @rand()
%12 = sext i32 %11 to i64
%13 = urem i64 %12, 62
%14 = getelementptr inbounds [63 x i8], [63 x i8]* @gen_uuid.an, i64 0, i64 %13
%15 = load i8, i8* %14
store i8 %15, i8* %2
%16 = tail call i32 (...) @rand()
%17 = sext i32 %16 to i64
%18 = urem i64 %17, 62
%19 = getelementptr inbounds [63 x i8], [63 x i8]* @gen_uuid.an, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %20, i8* %21
%22 = tail call i32 (...) @rand()
%23 = sext i32 %22 to i64
%24 = urem i64 %23, 62
%25 = getelementptr inbounds [63 x i8], [63 x i8]* @gen_uuid.an, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %26, i8* %27
%28 = tail call i32 (...) @rand()
%29 = sext i32 %28 to i64
%30 = urem i64 %29, 62
%31 = getelementptr inbounds [63 x i8], [63 x i8]* @gen_uuid.an, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = getelementptr inbounds i8, i8* %2, i64 3
store i8 %32, i8* %33
%34 = tail call i32 (...) @rand()
%35 = sext i32 %34 to i64
%36 = urem i64 %35, 62
%37 = getelementptr inbounds [63 x i8], [63 x i8]* @gen_uuid.an, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = getelementptr inbounds i8, i8* %2, i64 4
store i8 %38, i8* %39
%40 = tail call i32 (...) @rand()
%41 = sext i32 %40 to i64
%42 = urem i64 %41, 62
%43 = getelementptr inbounds [63 x i8], [63 x i8]* @gen_uuid.an, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = getelementptr inbounds i8, i8* %2, i64 5
store i8 %44, i8* %45
%46 = tail call i32 (...) @rand()
%47 = sext i32 %46 to i64
%48 = urem i64 %47, 62
%49 = getelementptr inbounds [63 x i8], [63 x i8]* @gen_uuid.an, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = getelementptr inbounds i8, i8* %2, i64 6
store i8 %50, i8* %51
%52 = tail call i32 (...) @rand()
%53 = sext i32 %52 to i64
%54 = urem i64 %53, 62
%55 = getelementptr inbounds [63 x i8], [63 x i8]* @gen_uuid.an, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = getelementptr inbounds i8, i8* %2, i64 7
store i8 %56, i8* %57
%58 = tail call i32 (...) @rand()
%59 = sext i32 %58 to i64
%60 = urem i64 %59, 62
%61 = getelementptr inbounds [63 x i8], [63 x i8]* @gen_uuid.an, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = getelementptr inbounds i8, i8* %2, i64 8
store i8 %62, i8* %63
%64 = getelementptr inbounds i8, i8* %2, i64 9
store i8 0, i8* %64
ret i8* %2
}