#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 /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
char *malloc(int);
int snprintf(char *, int, char *, char *, int /*<<< orphan*/,
             int /*<<< orphan*/);
char *gen_id_avltree(char *prefix) {
  struct timeval now;
  char *id;
  int len;
  id = NULL;
  len = 0;
  gettimeofday(&now, NULL);
  while (id == NULL) {
    if (id == NULL && len > 0) {
      id = malloc(sizeof(char) * len);
    }
    len = snprintf(id, len, "%s.%lu.%06lu", prefix, now.tv_sec, now.tv_usec);
  }
  return id;
}


x86 assembly (clang, -O0):
<gen_id_avltree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11b2 <gen_id_avltree+0x82>
cmpq   $0x0,-0x18(%rbp)
jne    118b <gen_id_avltree+0x5b>
cmpl   $0x0,-0x1c(%rbp)
jle    118b <gen_id_avltree+0x5b>
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
lea    0xe5b(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
jmp    1158 <gen_id_avltree+0x28>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_id_avltree>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    (%rsp),%r15d
mov    0x4(%rsp),%r13d
lea    0xea6(%rip),%r12
jmp    1187 <gen_id_avltree+0x57>
nopl   0x0(%rax)
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r13d,%r8d
mov    %r15d,%r9d
call   1030 <snprintf@plt>
mov    %eax,%ebx
test   %rbp,%rbp
jne    118f <gen_id_avltree+0x5f>
test   %ebx,%ebx
jg     1160 <gen_id_avltree+0x30>
xor    %ebp,%ebp
jmp    116a <gen_id_avltree+0x3a>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [13 x i8] c"%s.%lu.%06lu\00"
define i8* @gen_id_avltree(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.timeval
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %4
store i32 0, i32* %5
%6 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
br label %7
7: ; preds = %22, %1
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %31
10: ; preds = %7
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = mul i64 1, %18
%20 = trunc i64 %19 to i32
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %4
br label %22
22: ; preds = %16, %13, %10
%23 = load i8*, i8** %4
%24 = load i32, i32* %5
%25 = load i8*, i8** %2
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @snprintf(i8* %23, i32 %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %27, i32 %29)
store i32 %30, i32* %5
br label %7
31: ; preds = %7
%32 = load i8*, i8** %4
ret i8* %32
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [13 x i8] c"%s.%lu.%06lu\00"
define i8* @gen_id_avltree(i8* %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%8 = load i32, i32* %7
br label %9
9: ; preds = %1, %14
%10 = phi i32 [ 0, %1 ], [ %16, %14 ]
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i8* @malloc(i32 %10)
br label %14
14: ; preds = %12, %9
%15 = phi i8* [ %13, %12 ], [ null, %9 ]
%16 = tail call i32 @snprintf(i8* %15, i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %6, i32 %8)
%17 = icmp eq i8* %15, null
br i1 %17, label %9, label %18
18: ; preds = %14
ret i8* %15
}