#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 long uint64_t;
typedef long uint32_t;
struct timespec {
  long tv_sec;
  long tv_nsec;
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
struct timespec cycles64_to_timespec(uint32_t hz, uint64_t cycles) {
  struct timespec ts = {0, 0};
  assert(hz != 0);
  ts.tv_sec = cycles / hz;
  ts.tv_nsec = ((cycles % hz) * 1000000000L) / hz;
  return ts;
}


x86 assembly (clang, -O0):
<cycles64_to_timespec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x20(%rbp)
mov    %rdi,%rax
mov    %rax,-0x18(%rbp)
mov    %rsi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
cqto
idivq  -0x8(%rbp)
mov    %rax,(%rdi)
mov    -0x10(%rbp),%rax
cqto
idivq  -0x8(%rbp)
imul   $0x3b9aca00,%rdx,%rax
cqto
idivq  -0x8(%rbp)
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rdi)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cycles64_to_timespec>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
movq   $0x0,0x10(%rdi)
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1030 <assert@plt>
mov    %r15,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     114a <cycles64_to_timespec+0x3a>
mov    %r15,%rax
cqto
idiv   %rbx
jmp    1151 <cycles64_to_timespec+0x41>
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
mov    %rax,(%r14)
imul   $0x3b9aca00,%rdx,%rax
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
je     116e <cycles64_to_timespec+0x5e>
cqto
idiv   %rbx
jmp    1172 <cycles64_to_timespec+0x62>
xor    %edx,%edx
div    %ebx
mov    %rax,0x8(%r14)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64, i32, i32 }
define void @cycles64_to_timespec(%struct.timespec* noalias sret(%struct.timespec) align 8 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
store i64 %1, i64* %4
store i64 %2, i64* %5
%6 = bitcast %struct.timespec* %0 to i8*
%7 = load i64, i64* %4
%8 = icmp ne i64 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i64, i64* %5
%12 = load i64, i64* %4
%13 = sdiv i64 %11, %12
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 0
store i64 %13, i64* %14
%15 = load i64, i64* %5
%16 = load i64, i64* %4
%17 = srem i64 %15, %16
%18 = mul nsw i64 %17, 1000000000
%19 = load i64, i64* %4
%20 = sdiv i64 %18, %19
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 1
store i64 %20, i64* %21
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64, i32, i32 }
define void @cycles64_to_timespec(%struct.timespec* noalias nocapture writeonly sret(%struct.timespec) align 8 %0, i64 %1, i64 %2) {
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 2
%5 = bitcast i32* %4 to i64*
store i64 0, i64* %5
%6 = icmp ne i64 %1, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = sdiv i64 %2, %1
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
store i64 %9, i64* %10
%11 = srem i64 %2, %1
%12 = mul nsw i64 %11, 1000000000
%13 = sdiv i64 %12, %1
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
store i64 %13, i64* %14
ret void
}