#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;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int rand();
char *s_strdup(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, long);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *generate_clientid() {
  int r;
  struct timeval tv;
  long t;
  char buf[20] = {0};
  srand(time(NULL));
  r = rand() % 90 + 10;
  if (gettimeofday(&tv, NULL)) {
    return NULL;
  }
  t = tv.tv_usec % 1000000;
  snprintf(buf, sizeof(buf), "%d%ld", r, t);
  return s_strdup(buf);
}


x86 assembly (clang, -O0):
<generate_clientid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x5a,%ecx
cltd
idiv   %ecx
add    $0xa,%edx
mov    %edx,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
je     11d1 <generate_clientid+0x61>
movq   $0x0,-0x8(%rbp)
jmp    120c <generate_clientid+0x9c>
mov    -0x10(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    $0x14,%esi
lea    0xe06(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x30(%rbp),%rdi
call   1070 <s_strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_clientid>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
xor    %ebx,%ebx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %eax,%eax
call   1080 <rand@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rax,%rax
jne    120c <generate_clientid+0xac>
movslq %ebp,%rax
imul   $0xffffffffb60b60b7,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x5a,%ecx,%ecx
neg    %ecx
add    %eax,%ecx
add    $0xa,%ecx
movslq 0x8(%rsp),%rax
imul   $0x431bde83,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x32,%rdx
add    %esi,%edx
imul   $0xf4240,%edx,%edx
sub    %edx,%eax
movslq %eax,%r8
lea    0xe11(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <s_strdup@plt>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [6 x i8] c"%d%ld\00"
define i8* @generate_clientid() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca i64
%5 = alloca [20 x i8]
%6 = bitcast [20 x i8]* %5 to i8*
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 90
%11 = add nsw i32 %10, 10
store i32 %11, i32* %2
%12 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %0
store i8* null, i8** %1
br label %26
15: ; preds = %0
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%17 = load i32, i32* %16
%18 = srem i32 %17, 1000000
%19 = sext i32 %18 to i64
store i64 %19, i64* %4
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%21 = load i32, i32* %2
%22 = load i64, i64* %4
%23 = call i32 @snprintf(i8* %20, i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %21, i64 %22)
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%25 = call i8* @s_strdup(i8* %24)
store i8* %25, i8** %1
br label %26
26: ; preds = %15, %14
%27 = load i8*, i8** %1
ret i8* %27
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [6 x i8] c"%d%ld\00"
define i8* @generate_clientid() {
%1 = alloca %struct.timeval
%2 = alloca [20 x i8]
%3 = bitcast %struct.timeval* %1 to i8*
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = tail call i32 (...) @rand()
%8 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %0
%11 = srem i32 %7, 90
%12 = add nsw i32 %11, 10
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%14 = load i32, i32* %13
%15 = srem i32 %14, 1000000
%16 = sext i32 %15 to i64
%17 = call i32 @snprintf(i8* %4, i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %12, i64 %16)
%18 = call i8* @s_strdup(i8* %4)
br label %19
19: ; preds = %0, %10
%20 = phi i8* [ %18, %10 ], [ null, %0 ]
ret i8* %20
}