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

/* Variables and functions */
struct timespec timespec_add(struct timespec x, struct timespec y) {
  struct timespec ret = {0, 0};
  ret.tv_nsec = x.tv_nsec + y.tv_nsec;
  if (ret.tv_nsec > 1000000000) {
    ret.tv_sec++;
    ret.tv_nsec -= 1000000000;
  }
  ret.tv_sec += x.tv_sec + y.tv_sec;
  return ret;
}


x86 assembly (clang, -O0):
<timespec_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rdi,%rax
mov    %rax,-0x20(%rbp)
lea    0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdi
mov    (%rax),%eax
add    (%rcx),%eax
mov    %eax,(%rdi)
cmpl   $0x3b9aca00,(%rdi)
jle    1177 <timespec_add+0x67>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    (%rax),%ecx
sub    $0x3b9aca00,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    0x8(%rdx),%rdx
add    0x8(%rsi),%rdx
add    0x8(%rcx),%rdx
mov    %rdx,0x8(%rcx)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_add>:
mov    %rdi,%rax
xorps  %xmm0,%xmm0
movups %xmm0,(%rdi)
movq   $0x0,0x10(%rdi)
mov    0x8(%rsp),%ecx
mov    0x20(%rsp),%edx
lea    (%rdx,%rcx,1),%esi
xor    %edi,%edi
cmp    $0x3b9aca01,%esi
setge  %dil
lea    -0x3b9aca00(%rdx,%rcx,1),%ecx
cmovl  %esi,%ecx
mov    %ecx,(%rax)
mov    0x28(%rsp),%rcx
add    0x10(%rsp),%rcx
add    %rdi,%rcx
mov    %rcx,0x8(%rax)
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64, i32, i32 }
define void @timespec_add(%struct.timespec* noalias sret(%struct.timespec) align 8 %0, %struct.timespec* byval(%struct.timespec) align 8 %1, %struct.timespec* byval(%struct.timespec) align 8 %2) {
%4 = bitcast %struct.timespec* %0 to i8*
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%8 = load i32, i32* %7
%9 = add nsw i32 %6, %8
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 0
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 0
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 1000000000
br i1 %13, label %14, label %21
14: ; preds = %3
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 1
%16 = load i64, i64* %15
%17 = add nsw i64 %16, 1
store i64 %17, i64* %15
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 0
%19 = load i32, i32* %18
%20 = sub nsw i32 %19, 1000000000
store i32 %20, i32* %18
br label %21
21: ; preds = %14, %3
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%25 = load i64, i64* %24
%26 = add nsw i64 %23, %25
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 1
%28 = load i64, i64* %27
%29 = add nsw i64 %28, %26
store i64 %29, i64* %27
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64, i32, i32 }
define void @timespec_add(%struct.timespec* noalias nocapture sret(%struct.timespec) align 8 %0, %struct.timespec* nocapture byval(%struct.timespec) align 8 %1, %struct.timespec* nocapture byval(%struct.timespec) align 8 %2) {
%4 = bitcast %struct.timespec* %0 to i8*
tail call void @llvm.memset.p0i8.i64(i8* align 8 dereferenceable(24) %4, i8 0, i64 24, i1 false)
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = add nsw i32 %8, %6
%10 = icmp sgt i32 %9, 1000000000
%11 = add nsw i32 %9, -1000000000
%12 = select i1 %10, i32 %11, i32 %9
%13 = zext i1 %10 to i64
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
store i32 %12, i32* %14
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%18 = load i64, i64* %17
%19 = add nsw i64 %18, %16
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%21 = add nsw i64 %19, %13
store i64 %21, i64* %20
ret void
}