#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 scalar_t__ time_t;
struct tm {
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct timespec {
  int /*<<< orphan*/ tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ localtime_r(scalar_t__ *, struct tm *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int,
                            int /*<<< orphan*/);
void stringify_time(char *buff) {
  struct tm tm;
  struct timespec tp;
  time_t now;
  clock_gettime(CLOCK_REALTIME, &tp);
  now = (time_t)tp.tv_sec;
  localtime_r(&now, &tm);
  snprintf(buff, (1 << 5), "%02d:%02d:%02d.%09ld", tm.tm_hour, tm.tm_min,
           tm.tm_sec, tp.tv_nsec);
}


x86 assembly (clang, -O0):
<stringify_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x10(%rbp),%r9d
mov    -0x28(%rbp),%eax
mov    $0x20,%esi
lea    0xe7f(%rip),%rdx
mov    %eax,(%rsp)
call   1050 <snprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringify_time>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0x20(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    0x28(%rsp),%rax
mov    %rax,0x18(%rsp)
lea    0x18(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    0x10(%rsp),%r9d
mov    0x20(%rsp),%eax
mov    %eax,(%rsp)
lea    0xe80(%rip),%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <snprintf@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
@.str = [21 x i8] c"%02d:%02d:%02d.%09ld\00"
define void @stringify_time(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.tm
%4 = alloca %struct.timespec
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i32, i32* @CLOCK_REALTIME
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %4)
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%9 = load i64, i64* %8
store i64 %9, i64* %5
%10 = call i32 @localtime_r(i64* %5, %struct.tm* %3)
%11 = load i8*, i8** %2
%12 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @snprintf(i8* %11, i32 32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %15, i32 %17, i32 %19)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
@.str = [21 x i8] c"%02d:%02d:%02d.%09ld\00"
define void @stringify_time(i8* %0) {
%2 = alloca %struct.tm
%3 = alloca %struct.timespec
%4 = alloca i64
%5 = bitcast %struct.tm* %2 to i8*
%6 = bitcast %struct.timespec* %3 to i8*
%7 = bitcast i64* %4 to i8*
%8 = load i32, i32* @CLOCK_REALTIME
%9 = call i32 @clock_gettime(i32 %8, %struct.timespec* %3)
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%11 = load i64, i64* %10
store i64 %11, i64* %4
%12 = call i32 @localtime_r(i64* %4, %struct.tm* %2)
%13 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @snprintf(i8* %0, i32 32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %16, i32 %18, i32 %20)
ret void
}