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

/* Variables and functions */
int getpid();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ qhashmd5(char *, int /*<<< orphan*/, unsigned char *);
char *qhex_encode(unsigned char *, int);
int /*<<< orphan*/ rand();
int /*<<< orphan*/ snprintf(char *, int, char *, int, int /*<<< orphan*/,
                            unsigned long, long, char const *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ time(int /*<<< orphan*/ *);
char *qstrunique(const char *seed) {
  long int usec;
  struct timeval tv;
  gettimeofday(&tv, NULL);
  usec = tv.tv_usec;
  char uniquestr[128];
  snprintf(uniquestr, sizeof(uniquestr), "%u%d%lu%ld%s", getpid(), rand(),
           (unsigned long int)time(NULL), usec, (seed != NULL) ? seed : "");
  unsigned char md5hash[16];
  qhashmd5(uniquestr, strlen(uniquestr), md5hash);
  char *md5ascii = qhex_encode(md5hash, 16);
  return md5ascii;
}


x86 assembly (clang, -O0):
<qstrunique>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0xd0(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,-0xcc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %rax,-0xc8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xc0(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1202 <qstrunique+0x82>
mov    -0x8(%rbp),%rax
mov    %rax,-0xe0(%rbp)
jmp    1215 <qstrunique+0x95>
lea    0xe03(%rip),%rax
mov    %rax,-0xe0(%rbp)
jmp    1215 <qstrunique+0x95>
mov    -0xc0(%rbp),%r10
mov    -0xc8(%rbp),%r9
mov    -0xcc(%rbp),%r8d
mov    -0xd0(%rbp),%ecx
mov    -0xd8(%rbp),%rdi
mov    -0xe0(%rbp),%rax
mov    $0x80,%esi
lea    0xdb6(%rip),%rdx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <snprintf@plt>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xe8(%rbp),%rdi
mov    %eax,%esi
lea    -0xb0(%rbp),%rdx
call   1090 <qhashmd5@plt>
lea    -0xb0(%rbp),%rdi
mov    $0x10,%esi
call   1070 <qhex_encode@plt>
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qstrunique>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa0,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x8(%rsp),%r15
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %eax,%r12d
xor    %edi,%edi
call   1080 <time@plt>
test   %rbx,%rbx
lea    0xe44(%rip),%rbp
cmovne %rbx,%rbp
lea    0xe2d(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14d,%ecx
mov    %r12d,%r8d
mov    %rax,%r9
push   %rbp
push   %r15
call   1050 <snprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x10(%rsp),%rbp
mov    %rbx,%rdi
mov    %eax,%esi
mov    %rbp,%rdx
call   1090 <qhashmd5@plt>
mov    %rbp,%rdi
mov    $0x10,%esi
call   1070 <qhex_encode@plt>
add    $0xa0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
@.str = [13 x i8] c"%u%d%lu%ld%s\00"
@.str.1 = [1 x i8] zeroinitializer
define i8* @qstrunique(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca %struct.timeval
%5 = alloca [128 x i8]
%6 = alloca [16 x i8]
%7 = alloca i8*
store i8* %0, i8** %2
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%10 = load i64, i64* %9
store i64 %10, i64* %3
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%12 = call i32 (...) @getpid()
%13 = call i32 (...) @rand()
%14 = call i64 @time(i32* null)
%15 = load i64, i64* %3
%16 = load i8*, i8** %2
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = load i8*, i8** %2
br label %21
20: ; preds = %1
br label %21
21: ; preds = %20, %18
%22 = phi i8* [ %19, %18 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %20 ]
%23 = call i32 @snprintf(i8* %11, i32 128, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13, i64 %14, i64 %15, i8* %22)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%28 = call i32 @qhashmd5(i8* %24, i32 %26, i8* %27)
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%30 = call i8* @qhex_encode(i8* %29, i32 16)
store i8* %30, i8** %7
%31 = load i8*, i8** %7
ret i8* %31
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@.str = [13 x i8] c"%u%d%lu%ld%s\00"
@.str.1 = [1 x i8] zeroinitializer
define i8* @qstrunique(i8* %0) {
%2 = alloca %struct.timeval
%3 = alloca [128 x i8]
%4 = alloca [16 x i8]
%5 = bitcast %struct.timeval* %2 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%8 = load i64, i64* %7
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 (...) @rand()
%12 = tail call i64 @time(i32* null)
%13 = icmp eq i8* %0, null
%14 = select i1 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %0
%15 = call i32 @snprintf(i8* %9, i32 128, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11, i64 %12, i64 %8, i8* %14)
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%17 = call i32 @strlen(i8* %9)
%18 = call i32 @qhashmd5(i8* %9, i32 %17, i8* %16)
%19 = call i8* @qhex_encode(i8* %16, i32 16)
ret i8* %19
}