#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 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 jiffies_to_timespec(uint32_t hz, uint32_t jiffies) {
  struct timespec ts = {0, 0};
  assert(hz != 0);
  ts.tv_sec = jiffies / hz;
  ts.tv_nsec = (1000000000L / hz) * (jiffies % hz);
  return ts;
}


x86 assembly (clang, -O0):
<jiffies_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    $0x3b9aca00,%eax
cqto
idivq  -0x8(%rbp)
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
cqto
idivq  -0x8(%rbp)
mov    -0x18(%rbp),%rax
imul   %rdx,%rcx
mov    %rcx,0x8(%rdi)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jiffies_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     114d <jiffies_to_timespec+0x3d>
mov    %r15,%rax
cqto
idiv   %rbx
mov    %rdx,%rcx
jmp    1156 <jiffies_to_timespec+0x46>
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
mov    %edx,%ecx
mov    %rax,(%r14)
mov    %rbx,%rax
shr    $0x20,%rax
je     116e <jiffies_to_timespec+0x5e>
mov    $0x3b9aca00,%eax
xor    %edx,%edx
idiv   %rbx
jmp    1177 <jiffies_to_timespec+0x67>
mov    $0x3b9aca00,%eax
xor    %edx,%edx
div    %ebx
imul   %rax,%rcx
mov    %rcx,0x8(%r14)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64, i32, i32 }
define void @jiffies_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* %4
%16 = sdiv i64 1000000000, %15
%17 = load i64, i64* %5
%18 = load i64, i64* %4
%19 = srem i64 %17, %18
%20 = mul nsw i64 %16, %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 @jiffies_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 = sdiv i64 1000000000, %1
%12 = srem i64 %2, %1
%13 = mul nsw i64 %12, %11
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
store i64 %13, i64* %14
ret void
}