#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 dummy;
};

/* Variables and functions */
long long LLONG_MAX;
scalar_t__ MAX(long long, long long);
int /*<<< orphan*/ nsectospec(long long, struct timespec *);
long long spectonsec(struct timespec *);
void tsadd(struct timespec *augend, struct timespec *addend,
           struct timespec *sum) {
  long long aug, add;
  aug = spectonsec(augend);
  add = spectonsec(addend);
  if (aug < 0 || add < 0)
    nsectospec(-1, sum);
  else if (LLONG_MAX - MAX(add, aug) < MAX(add, aug))
    nsectospec(LLONG_MAX, sum);
  else
    nsectospec(aug + add, sum);
  return;
}


x86 assembly (clang, -O0):
<tsadd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <spectonsec@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <spectonsec@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jl     1174 <tsadd+0x44>
cmpq   $0x0,-0x28(%rbp)
jge    1189 <tsadd+0x59>
mov    -0x18(%rbp),%rsi
mov    $0xffffffffffffffff,%rdi
call   1050 <nsectospec@plt>
jmp    11fd <tsadd+0xcd>
mov    0x2e58(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <MAX@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <MAX@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jge    11e7 <tsadd+0xb7>
mov    0x2e12(%rip),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <nsectospec@plt>
jmp    11f8 <tsadd+0xc8>
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <nsectospec@plt>
jmp    11fd <tsadd+0xcd>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tsadd>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
call   1030 <spectonsec@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <spectonsec@plt>
mov    $0xffffffffffffffff,%rdi
test   %r15,%r15
js     1198 <tsadd+0x68>
mov    %rax,%rbx
test   %rax,%rax
js     1198 <tsadd+0x68>
mov    0x2e7e(%rip),%r12
mov    (%r12),%r13
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <MAX@plt>
sub    %rax,%r13
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <MAX@plt>
cmp    %rax,%r13
jge    1192 <tsadd+0x62>
mov    (%r12),%rdi
jmp    1198 <tsadd+0x68>
add    %r15,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <nsectospec@plt>

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

LLVM IR (-O2):
%struct.timespec = type { i32 }
@LLONG_MAX = global i64 0
define void @tsadd(%struct.timespec* %0, %struct.timespec* %1, %struct.timespec* %2) {
%4 = tail call i64 @spectonsec(%struct.timespec* %0)
%5 = tail call i64 @spectonsec(%struct.timespec* %1)
%6 = icmp slt i64 %4, 0
%7 = icmp slt i64 %5, 0
%8 = select i1 %6, i1 true, i1 %7
br i1 %8, label %19, label %9
9: ; preds = %3
%10 = load i64, i64* @LLONG_MAX
%11 = tail call i64 @MAX(i64 %5, i64 %4)
%12 = sub nsw i64 %10, %11
%13 = tail call i64 @MAX(i64 %5, i64 %4)
%14 = icmp slt i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = load i64, i64* @LLONG_MAX
br label %19
17: ; preds = %9
%18 = add nuw nsw i64 %5, %4
br label %19
19: ; preds = %3, %15, %17
%20 = phi i64 [ %16, %15 ], [ %18, %17 ], [ -1, %3 ]
%21 = tail call i32 @nsectospec(i64 %20, %struct.timespec* %2)
ret void
}