#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 time_t;
struct tm {
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
typedef int const int64_t;

/* Variables and functions */
int /*<<< orphan*/ *localtime_r(int const *, struct tm *);
scalar_t__ snprintf(char *, size_t, char *, int, int, int, int, int, int);
void audio_utils_ns_to_string(int64_t ns, char *buffer, size_t buffer_size) {
  if (buffer_size == 0)
    return;
  const int one_second = 1000000000;
  const time_t sec = ns / one_second;
  struct tm tm;
  if (localtime_r(&sec, &tm) == NULL) {
    buffer[0] = '\0';
    return;
  }
  if (snprintf(buffer, buffer_size, "%02d-%02d %02d:%02d:%02d.%03d",
               tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
               (int)(ns % one_second / 1000000)) < 0) {
    buffer[0] = '\0';
  }
}


x86 assembly (clang, -O0):
<audio_utils_ns_to_string>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x58,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1144 <audio_utils_ns_to_string+0x24>
jmp    11d9 <audio_utils_ns_to_string+0xb9>
movl   $0x3b9aca00,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <localtime_r@plt>
cmp    $0x0,%rax
jne    117c <audio_utils_ns_to_string+0x5c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11d9 <audio_utils_ns_to_string+0xb9>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x40(%rbp),%ecx
add    $0x1,%ecx
mov    -0x3c(%rbp),%r8d
mov    -0x38(%rbp),%r9d
mov    -0x34(%rbp),%r11d
mov    -0x30(%rbp),%r10d
mov    -0xc(%rbp),%eax
mov    $0x3b9aca00,%ebx
cltd
idiv   %ebx
mov    %edx,%eax
mov    $0xf4240,%ebx
cltd
idiv   %ebx
lea    0xe4a(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <snprintf@plt>
cmp    $0x0,%rax
jge    11d9 <audio_utils_ns_to_string+0xb9>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<audio_utils_ns_to_string>:
test   %rdx,%rdx
je     11d2 <audio_utils_ns_to_string+0xb2>
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebp
movslq %edi,%rax
imul   $0x44b82fa1,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x3c,%rbx
add    %eax,%ebx
mov    %ebx,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <localtime_r@plt>
test   %rax,%rax
je     11c4 <audio_utils_ns_to_string+0xa4>
imul   $0x3b9aca00,%ebx,%eax
sub    %eax,%ebp
mov    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
add    $0x1,%ecx
mov    0x18(%rsp),%r9d
mov    0x1c(%rsp),%eax
mov    0x20(%rsp),%ebx
movslq %ebp,%rdx
imul   $0x431bde83,%rdx,%rbp
mov    %rbp,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rbp
add    %edx,%ebp
sub    $0x8,%rsp
lea    0xe53(%rip),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
push   %rbp
push   %rbx
push   %rax
call   1040 <snprintf@plt>
add    $0x20,%rsp
test   %rax,%rax
jns    11c8 <audio_utils_ns_to_string+0xa8>
movb   $0x0,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32 }
@.str = [30 x i8] c"%02d-%02d %02d:%02d:%02d.%03d\00"
define void @audio_utils_ns_to_string(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.tm
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i64, i64* %6
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
br label %43
13: ; preds = %3
store i32 1000000000, i32* %7
%14 = load i32, i32* %4
%15 = sdiv i32 %14, 1000000000
store i32 %15, i32* %8
%16 = call i32* @localtime_r(i32* %8, %struct.tm* %9)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 0
store i8 0, i8* %20
br label %43
21: ; preds = %13
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 0
%25 = load i32, i32* %24
%26 = add nsw i32 %25, 1
%27 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 2
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 3
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 4
%34 = load i32, i32* %33
%35 = load i32, i32* %4
%36 = srem i32 %35, 1000000000
%37 = sdiv i32 %36, 1000000
%38 = call i64 @snprintf(i8* %22, i64 %23, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %28, i32 %30, i32 %32, i32 %34, i32 %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %21
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i64 0
store i8 0, i8* %42
br label %43
43: ; preds = %12, %18, %40, %21
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32 }
@.str = [30 x i8] c"%02d-%02d %02d:%02d:%02d.%03d\00"
define void @audio_utils_ns_to_string(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.tm
%6 = icmp eq i64 %2, 0
br i1 %6, label %31, label %7
7: ; preds = %3
%8 = bitcast i32* %4 to i8*
%9 = sdiv i32 %0, 1000000000
%10 = srem i32 %0, 1000000000
store i32 %9, i32* %4
%11 = bitcast %struct.tm* %5 to i8*
%12 = call i32* @localtime_r(i32* %4, %struct.tm* %5)
%13 = icmp eq i32* %12, null
br i1 %13, label %29, label %14
14: ; preds = %7
%15 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
%18 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 3
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 4
%25 = load i32, i32* %24
%26 = sdiv i32 %10, 1000000
%27 = call i64 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %19, i32 %21, i32 %23, i32 %25, i32 %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %14, %7
store i8 0, i8* %1
br label %30
30: ; preds = %29, %14
br label %31
31: ; preds = %3, %30
ret void
}