#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct timespec {
  unsigned long tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
struct TYPE_3__ {
  unsigned long rem;
  scalar_t__ quot;
};
typedef TYPE_1__ ldiv_t;

/* Variables and functions */
TYPE_1__ ldiv(unsigned long, long);
void ts_adjust(struct timespec *ts) {
  if (ts->tv_nsec >= 1000000000UL) {
    ldiv_t q = ldiv(ts->tv_nsec, 1000000000L);
    ts->tv_sec += q.quot;
    ts->tv_nsec = q.rem;
  }
}


x86 assembly (clang, -O0):
<ts_adjust>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x3b9aca00,(%rax)
jb     1163 <ts_adjust+0x53>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0x3b9aca00,%esi
call   1030 <ldiv@plt>
mov    %rax,-0x18(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rax
movslq 0x8(%rax),%rcx
add    %rdx,%rcx
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_adjust>:
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rdi
cmp    $0x3b9aca00,%rdi
jb     1130 <ts_adjust+0x20>
mov    $0x3b9aca00,%esi
call   1030 <ldiv@plt>
add    %edx,0x8(%rbx)
mov    %rax,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i32 }
%struct.TYPE_3__ = type { i64, i64 }
define void @ts_adjust(%struct.timespec* %0) {
%2 = alloca %struct.timespec*
%3 = alloca %struct.TYPE_3__
store %struct.timespec* %0, %struct.timespec** %2
%4 = load %struct.timespec*, %struct.timespec** %2
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%6 = load i64, i64* %5
%7 = icmp uge i64 %6, 1000000000
br i1 %7, label %8, label %30
8: ; preds = %1
%9 = load %struct.timespec*, %struct.timespec** %2
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = call { i64, i64 } @ldiv(i64 %11, i64 1000000000)
%13 = bitcast %struct.TYPE_3__* %3 to { i64, i64 }*
%14 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %13, i32 0, i32 0
%15 = extractvalue { i64, i64 } %12, 0
store i64 %15, i64* %14
%16 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %13, i32 0, i32 1
%17 = extractvalue { i64, i64 } %12, 1
store i64 %17, i64* %16
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 1
%19 = load i64, i64* %18
%20 = load %struct.timespec*, %struct.timespec** %2
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = add nsw i64 %23, %19
%25 = trunc i64 %24 to i32
store i32 %25, i32* %21
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 0
%27 = load i64, i64* %26
%28 = load %struct.timespec*, %struct.timespec** %2
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %28, i32 0, i32 0
store i64 %27, i64* %29
br label %30
30: ; preds = %8, %1
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i32 }
define void @ts_adjust(%struct.timespec* nocapture %0) {
%2 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%3 = load i64, i64* %2
%4 = icmp ugt i64 %3, 999999999
br i1 %4, label %5, label %13
5: ; preds = %1
%6 = tail call { i64, i64 } @ldiv(i64 %3, i64 1000000000)
%7 = extractvalue { i64, i64 } %6, 0
%8 = extractvalue { i64, i64 } %6, 1
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%10 = load i32, i32* %9
%11 = trunc i64 %8 to i32
%12 = add i32 %10, %11
store i32 %12, i32* %9
store i64 %7, i64* %2
br label %13
13: ; preds = %5, %1
ret void
}