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

/* Variables and functions */
struct timespec rte_ns_to_timespec(uint64_t nsec) {
  struct timespec ts = {0, 0};
  if (nsec == 0)
    return ts;
  ts.tv_sec = nsec / 1000000000L;
  ts.tv_nsec = nsec % 1000000000L;
  return ts;
}


x86 assembly (clang, -O0):
<rte_ns_to_timespec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x18(%rbp)
mov    %rdi,%rax
mov    %rax,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
cmpq   $0x0,-0x8(%rbp)
jne    1143 <rte_ns_to_timespec+0x33>
jmp    1171 <rte_ns_to_timespec+0x61>
mov    -0x8(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    -0x18(%rbp),%rax
mov    %rdx,0x8(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rte_ns_to_timespec>:
xorps  %xmm0,%xmm0
movups %xmm0,(%rdi)
movq   $0x0,0x10(%rdi)
test   %rsi,%rsi
je     1142 <rte_ns_to_timespec+0x42>
movabs $0x112e0be826d694b3,%rcx
0b 2e 11
mov    %rsi,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1a,%rdx
add    %rax,%rdx
mov    %rdx,(%rdi)
imul   $0x3b9aca00,%rdx,%rax
sub    %rax,%rsi
mov    %rsi,0x8(%rdi)
mov    %rdi,%rax
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64, i32, i32 }
define void @rte_ns_to_timespec(%struct.timespec* noalias sret(%struct.timespec) align 8 %0, i64 %1) {
%3 = alloca i64
store i64 %1, i64* %3
%4 = bitcast %struct.timespec* %0 to i8*
%5 = load i64, i64* %3
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %2
br label %15
8: ; preds = %2
%9 = load i64, i64* %3
%10 = sdiv i64 %9, 1000000000
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 0
store i64 %10, i64* %11
%12 = load i64, i64* %3
%13 = srem i64 %12, 1000000000
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 1
store i64 %13, i64* %14
br label %15
15: ; preds = %8, %7
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64, i32, i32 }
define void @rte_ns_to_timespec(%struct.timespec* noalias nocapture writeonly sret(%struct.timespec) align 8 %0, i64 %1) {
%3 = bitcast %struct.timespec* %0 to i8*
tail call void @llvm.memset.p0i8.i64(i8* align 8 dereferenceable(24) %3, i8 0, i64 24, i1 false)
%4 = icmp eq i64 %1, 0
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = sdiv i64 %1, 1000000000
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
store i64 %6, i64* %7
%8 = srem i64 %1, 1000000000
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
store i64 %8, i64* %9
br label %10
10: ; preds = %2, %5
ret void
}