#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 time_add(struct timespec time1, struct timespec time2) {
  struct timespec time = {0, 0};
  if ((time1.tv_nsec + time2.tv_nsec) >= 1000000000) {
    time.tv_sec = time1.tv_sec + time2.tv_sec + 1;
    time.tv_nsec = time1.tv_nsec + time2.tv_nsec - 1000000000;
  } else {
    time.tv_sec = time1.tv_sec + time2.tv_sec;
    time.tv_nsec = time1.tv_nsec + time2.tv_nsec;
  }
  return time;
}


x86 assembly (clang, -O0):
<time_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x20(%rbp)
mov    %rdi,%rax
mov    %rax,-0x18(%rbp)
lea    0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
lea    0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rax),%eax
add    (%rcx),%eax
cmp    $0x3b9aca00,%eax
jl     1183 <time_add+0x73>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rsi
add    0x8(%rdx),%rsi
add    $0x1,%rsi
mov    %rsi,0x8(%rax)
mov    (%rcx),%ecx
add    (%rdx),%ecx
sub    $0x3b9aca00,%ecx
mov    %ecx,(%rax)
jmp    11a1 <time_add+0x91>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rsi
add    0x8(%rdx),%rsi
mov    %rsi,0x8(%rax)
mov    (%rcx),%ecx
add    (%rdx),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_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    $0x3b9aca00,%esi
setge  %dil
lea    -0x3b9aca00(%rdx,%rcx,1),%ecx
cmovl  %esi,%ecx
add    0x10(%rsp),%rdi
add    0x28(%rsp),%rdi
mov    %rdi,0x8(%rax)
mov    %ecx,(%rax)
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64, i32, i32 }
define void @time_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 = icmp sge i32 %9, 1000000000
br i1 %10, label %11, label %26
11: ; preds = %3
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%15 = load i64, i64* %14
%16 = add nsw i64 %13, %15
%17 = add nsw i64 %16, 1
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 1
store i64 %17, i64* %18
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%22 = load i32, i32* %21
%23 = add nsw i32 %20, %22
%24 = sub nsw i32 %23, 1000000000
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 0
store i32 %24, i32* %25
br label %39
26: ; preds = %3
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%28 = load i64, i64* %27
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%30 = load i64, i64* %29
%31 = add nsw i64 %28, %30
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 1
store i64 %31, i64* %32
%33 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%36 = load i32, i32* %35
%37 = add nsw i32 %34, %36
%38 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 0
store i32 %37, i32* %38
br label %39
39: ; preds = %26, %11
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64, i32, i32 }
define void @time_add(%struct.timespec* noalias nocapture writeonly 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, 999999999
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%12 = load i64, i64* %11
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%14 = load i64, i64* %13
%15 = add nsw i32 %9, -1000000000
%16 = zext i1 %10 to i64
%17 = add i64 %12, %16
%18 = add i64 %14, %17
%19 = select i1 %10, i32 %15, i32 %9
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
store i64 %18, i64* %20
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
store i32 %19, i32* %21
ret void
}