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

/* Variables and functions */
int /*<<< orphan*/ asprintf(char **, char *, int /*<<< orphan*/,
                            int /*<<< orphan*/, char const *);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
char *generate_bundle_name(const char *origin) {
  struct timeval t_now = {0};
  char *name = NULL;
  if (gettimeofday(&t_now, NULL) < 0)
    goto end;
  asprintf(&name, "%ld-%ld-%s", t_now.tv_sec, t_now.tv_usec, origin);
end:
  return name;
}


x86 assembly (clang, -O0):
<generate_bundle_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
movq   $0x0,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
jge    1170 <generate_bundle_name+0x40>
jmp    118a <generate_bundle_name+0x5a>
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%r8
lea    -0x20(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <asprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_bundle_name>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
movl   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
movq   $0x0,0x10(%rsp)
xor    %ebx,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
js     1174 <generate_bundle_name+0x54>
mov    (%rsp),%ecx
mov    0x4(%rsp),%edx
lea    0xe9e(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %r14,%r8
call   1040 <asprintf@plt>
mov    0x10(%rsp),%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32, i32 }
@.str = [11 x i8] c"%ld-%ld-%s\00"
define i8* @generate_bundle_name(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.timeval
%4 = alloca i8*
store i8* %0, i8** %2
%5 = bitcast %struct.timeval* %3 to i8*
store i8* null, i8** %4
%6 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
br label %16
9: ; preds = %1
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = load i8*, i8** %2
%15 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %13, i8* %14)
br label %16
16: ; preds = %9, %8
%17 = load i8*, i8** %4
ret i8* %17
}

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