#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*/ time_t;
struct tm {
  int dummy;
};
struct timespec {
  long tv_nsec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, long);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
void convert_time_to_string(struct timespec tv, char *time_buf) {
  time_t sec;
  long nsec;
  struct tm *timeinfo;
  char tmp_buf[15];
  sec = tv.tv_sec;
  timeinfo = localtime(&sec);
  nsec = tv.tv_nsec;
  strftime(tmp_buf, 15, "%H:%M:%S", timeinfo);
  sprintf(time_buf, "%s:%9ld", tmp_buf, nsec);
}


x86 assembly (clang, -O0):
<convert_time_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x3f(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0xf,%esi
lea    0xe8e(%rip),%rdx
call   1040 <strftime@plt>
mov    -0x18(%rbp),%rdi
lea    -0x3f(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe7f(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_time_to_string>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%rbx
mov    %rdi,%r14
mov    %esi,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xeac(%rip),%rdx
lea    0x11(%rsp),%r15
mov    %r15,%rdi
mov    $0xf,%esi
mov    %rax,%rcx
call   1040 <strftime@plt>
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <sprintf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [9 x i8] c"%H:%M:%S\00"
@.str.1 = [8 x i8] c"%s:%9ld\00"
define void @convert_time_to_string(i64 %0, i32 %1, i8* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca [15 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
store i32 %1, i32* %4
%8 = call %struct.tm* @localtime(i32* %4)
%9 = call i32 @strftime(i8* %7, i32 15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.tm* %8)
%10 = call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %7, i64 %0)
ret void
}