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

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int strftime(char *, int, char *, struct tm *);
void time_to_str(const struct timeval tv, char *time_str, int time_str_l) {
  int off = 0;
  struct tm *nowtm;
  nowtm = localtime(&tv.tv_sec);
  off = strftime(time_str, time_str_l, "%Y-%m-%d %H:%M:%S", nowtm);
  sprintf(time_str + off, ".%.6ld", tv.tv_usec);
}


x86 assembly (clang, -O0):
<time_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rcx
lea    0xe93(%rip),%rdx
call   1040 <strftime@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%edx
lea    0xe88(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_to_str>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xeb3(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %rax,%rcx
call   1040 <strftime@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    (%rsp),%edx
lea    0xea8(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [7 x i8] c".%.6ld\00"
define void @time_to_str(i64 %0, i8* %1, i32 %2) {
%4 = alloca %struct.timeval
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.tm*
%9 = bitcast %struct.timeval* %4 to i64*
store i64 %0, i64* %9
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%11 = call %struct.tm* @localtime(i32* %10)
store %struct.tm* %11, %struct.tm** %8
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = load %struct.tm*, %struct.tm** %8
%15 = call i32 @strftime(i8* %12, i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %14)
store i32 %15, i32* %7
%16 = load i8*, i8** %5
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %21)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [7 x i8] c".%.6ld\00"
define void @time_to_str(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to %struct.timeval*
store i64 %0, i64* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%7 = call %struct.tm* @localtime(i32* %6)
%8 = call i32 @strftime(i8* %1, i32 %2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %7)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = bitcast i64* %4 to i32*
%12 = load i32, i32* %11
%13 = call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %12)
ret void
}