#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 unsigned long long uint64_t;
typedef unsigned long long time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
struct tm *gmtime_r(unsigned long long *, struct tm *);
void hazer_format_nanoseconds2timestamp(uint64_t nanoseconds, int *yearp,
                                        int *monthp, int *dayp, int *hourp,
                                        int *minutep, int *secondp,
                                        uint64_t *nanosecondsp) {
  struct tm datetime = {0};
  struct tm *dtp = (struct tm *)0;
  time_t zulu = 0;
  zulu = nanoseconds / 1000000000ULL;
  dtp = gmtime_r(&zulu, &datetime);
  *yearp = dtp->tm_year + 1900;
  *monthp = dtp->tm_mon + 1;
  *dayp = dtp->tm_mday;
  *hourp = dtp->tm_hour;
  *minutep = dtp->tm_min;
  *secondp = dtp->tm_sec;
  *nanosecondsp = nanoseconds % 1000000000ULL;
}


x86 assembly (clang, -O0):
<hazer_format_nanoseconds2timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x1c,%edx
call   1040 <memset@plt>
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3b9aca00,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x60(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1030 <gmtime_r@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rax
mov    0x14(%rax),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    $0x3b9aca00,%ecx
xor    %edx,%edx
div    %rcx
mov    0x18(%rbp),%rax
mov    %rdx,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hazer_format_nanoseconds2timestamp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,(%rsp)
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,0x1c(%rsp)
movaps %xmm0,0x10(%rsp)
mov    %rdi,%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rcx
mul    %rcx
mov    %rdx,%r14
shr    $0xb,%r14
mov    %r14,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <gmtime_r@plt>
mov    $0x76c,%ecx
add    (%rax),%ecx
mov    %ecx,0x0(%rbp)
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x0(%r13)
mov    0x8(%rax),%ecx
mov    %ecx,(%r12)
mov    0xc(%rax),%ecx
mov    %ecx,(%r15)
mov    0x10(%rax),%ecx
mov    (%rsp),%rdx
mov    %ecx,(%rdx)
mov    0x14(%rax),%eax
mov    0x70(%rsp),%rcx
mov    %eax,(%rcx)
imul   $0x3b9aca00,%r14,%rax
sub    %rax,%rbx
mov    0x78(%rsp),%rax
mov    %rbx,(%rax)
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32 }
define void @hazer_format_nanoseconds2timestamp(i64 %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i64* %7) {
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i64*
%17 = alloca %struct.tm
%18 = alloca %struct.tm*
%19 = alloca i64
store i64 %0, i64* %9
store i32* %1, i32** %10
store i32* %2, i32** %11
store i32* %3, i32** %12
store i32* %4, i32** %13
store i32* %5, i32** %14
store i32* %6, i32** %15
store i64* %7, i64** %16
%20 = bitcast %struct.tm* %17 to i8*
store %struct.tm* null, %struct.tm** %18
store i64 0, i64* %19
%21 = load i64, i64* %9
%22 = udiv i64 %21, 1000000000
store i64 %22, i64* %19
%23 = call %struct.tm* @gmtime_r(i64* %19, %struct.tm* %17)
store %struct.tm* %23, %struct.tm** %18
%24 = load %struct.tm*, %struct.tm** %18
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1900
%28 = load i32*, i32** %10
store i32 %27, i32* %28
%29 = load %struct.tm*, %struct.tm** %18
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 1
%31 = load i32, i32* %30
%32 = add nsw i32 %31, 1
%33 = load i32*, i32** %11
store i32 %32, i32* %33
%34 = load %struct.tm*, %struct.tm** %18
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 2
%36 = load i32, i32* %35
%37 = load i32*, i32** %12
store i32 %36, i32* %37
%38 = load %struct.tm*, %struct.tm** %18
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 3
%40 = load i32, i32* %39
%41 = load i32*, i32** %13
store i32 %40, i32* %41
%42 = load %struct.tm*, %struct.tm** %18
%43 = getelementptr inbounds %struct.tm, %struct.tm* %42, i32 0, i32 4
%44 = load i32, i32* %43
%45 = load i32*, i32** %14
store i32 %44, i32* %45
%46 = load %struct.tm*, %struct.tm** %18
%47 = getelementptr inbounds %struct.tm, %struct.tm* %46, i32 0, i32 5
%48 = load i32, i32* %47
%49 = load i32*, i32** %15
store i32 %48, i32* %49
%50 = load i64, i64* %9
%51 = urem i64 %50, 1000000000
%52 = load i64*, i64** %16
store i64 %51, i64* %52
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32 }
define void @hazer_format_nanoseconds2timestamp(i64 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5, i32* nocapture writeonly %6, i64* nocapture writeonly %7) {
%9 = alloca %struct.tm
%10 = alloca i64
%11 = bitcast %struct.tm* %9 to i8*
%12 = bitcast i64* %10 to i8*
%13 = udiv i64 %0, 1000000000
store i64 %13, i64* %10
%14 = call %struct.tm* @gmtime_r(i64* %10, %struct.tm* %9)
%15 = getelementptr inbounds %struct.tm, %struct.tm* %14, i64 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1900
store i32 %17, i32* %1
%18 = getelementptr inbounds %struct.tm, %struct.tm* %14, i64 0, i32 1
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
%21 = getelementptr inbounds %struct.tm, %struct.tm* %14, i64 0, i32 2
%22 = load i32, i32* %21
store i32 %22, i32* %3
%23 = getelementptr inbounds %struct.tm, %struct.tm* %14, i64 0, i32 3
%24 = load i32, i32* %23
store i32 %24, i32* %4
%25 = getelementptr inbounds %struct.tm, %struct.tm* %14, i64 0, i32 4
%26 = load i32, i32* %25
store i32 %26, i32* %5
%27 = getelementptr inbounds %struct.tm, %struct.tm* %14, i64 0, i32 5
%28 = load i32, i32* %27
store i32 %28, i32* %6
%29 = urem i64 %0, 1000000000
store i64 %29, i64* %7
ret void
}