#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 */
struct tq_elem {
  int dummy;
};
struct timespec {
  int tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int add_task_abs(struct timespec *, struct tq_elem *,
                 void (*)(struct tq_elem *));
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int add_task_rel(const struct timespec *expires_in, struct tq_elem *tqi,
                 void (*task)(struct tq_elem *)) {
  struct timespec expire;
  clock_gettime(CLOCK_REALTIME, &expire);
  do {
    (expire).tv_sec = (expire).tv_sec + (*expires_in).tv_sec;
    (expire).tv_nsec = (expire).tv_nsec + (*expires_in).tv_nsec;
    if ((expire).tv_nsec >= 1000000000) {
      ++(expire).tv_sec;
      (expire).tv_nsec -= 1000000000;
    }
  } while (0);
  return add_task_abs(&expire, tqi, task);
}


x86 assembly (clang, -O0):
<add_task_rel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    0x8(%rcx),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x8(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x3b9aca00,-0x28(%rbp)
jl     1186 <add_task_rel+0x66>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
sub    $0x3b9aca00,%eax
mov    %eax,-0x28(%rbp)
jmp    118b <add_task_rel+0x6b>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%rdi
call   1040 <add_task_abs@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_task_rel>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2ea7(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
mov    0x8(%rbx),%rax
add    0x8(%rsp),%rax
mov    %rax,0x8(%rsp)
mov    (%rbx),%ecx
add    (%rsp),%ecx
mov    %ecx,(%rsp)
cmp    $0x3b9aca00,%ecx
jl     1173 <add_task_rel+0x53>
add    $0x1,%rax
mov    %rax,0x8(%rsp)
add    $0xc4653600,%ecx
mov    %ecx,(%rsp)
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <add_task_abs@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
%struct.tq_elem = type { i32 }
@CLOCK_REALTIME = global i32 0
define i32 @add_task_rel(%struct.timespec* %0, %struct.tq_elem* %1, void (%struct.tq_elem*)* %2) {
%4 = alloca %struct.timespec*
%5 = alloca %struct.tq_elem*
%6 = alloca void (%struct.tq_elem*)*
%7 = alloca %struct.timespec
store %struct.timespec* %0, %struct.timespec** %4
store %struct.tq_elem* %1, %struct.tq_elem** %5
store void (%struct.tq_elem*)* %2, void (%struct.tq_elem*)** %6
%8 = load i32, i32* @CLOCK_REALTIME
%9 = call i32 @clock_gettime(i32 %8, %struct.timespec* %7)
br label %10
10: ; preds = %3
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%12 = load i64, i64* %11
%13 = load %struct.timespec*, %struct.timespec** %4
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 1
%15 = load i64, i64* %14
%16 = add nsw i64 %12, %15
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
store i64 %16, i64* %17
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%19 = load i32, i32* %18
%20 = load %struct.timespec*, %struct.timespec** %4
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = add nsw i32 %19, %22
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%26 = load i32, i32* %25
%27 = icmp sge i32 %26, 1000000000
br i1 %27, label %28, label %35
28: ; preds = %10
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%30 = load i64, i64* %29
%31 = add nsw i64 %30, 1
store i64 %31, i64* %29
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%33 = load i32, i32* %32
%34 = sub nsw i32 %33, 1000000000
store i32 %34, i32* %32
br label %35
35: ; preds = %28, %10
br label %36
36: ; preds = %35
%37 = load %struct.tq_elem*, %struct.tq_elem** %5
%38 = load void (%struct.tq_elem*)*, void (%struct.tq_elem*)** %6
%39 = call i32 @add_task_abs(%struct.timespec* %7, %struct.tq_elem* %37, void (%struct.tq_elem*)* %38)
ret i32 %39
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
%struct.tq_elem = type { i32 }
@CLOCK_REALTIME = global i32 0
define i32 @add_task_rel(%struct.timespec* nocapture %0, %struct.tq_elem* %1, void (%struct.tq_elem*)* %2) {
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %4 to i8*
%6 = load i32, i32* @CLOCK_REALTIME
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %4)
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%11 = load i64, i64* %10
%12 = add nsw i64 %11, %9
store i64 %12, i64* %8
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, %14
store i32 %17, i32* %13
%18 = icmp sgt i32 %17, 999999999
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = add nsw i64 %12, 1
store i64 %20, i64* %8
%21 = add nsw i32 %17, -1000000000
store i32 %21, i32* %13
br label %22
22: ; preds = %19, %3
%23 = call i32 @add_task_abs(%struct.timespec* %4, %struct.tq_elem* %1, void (%struct.tq_elem*)* %2)
ret i32 %23
}