#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 {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
struct timespec *calloc(int, int);
struct timespec *flu_now();
int /*<<< orphan*/ free(struct timespec *);
struct timespec *flu_tdiff(struct timespec *t1, struct timespec *t0) {
  short t1null = 0;
  struct timespec *t2 = calloc(1, sizeof(struct timespec));
  if (t1 == NULL) {
    t1null = 1;
    t1 = flu_now();
  }
  t2->tv_sec = t1->tv_sec - t0->tv_sec;
  t2->tv_nsec = t1->tv_nsec - t0->tv_nsec;
  if (t2->tv_nsec < 0) {
    --t2->tv_sec;
    t2->tv_nsec += 1000000000;
  }
  if (t1null)
    free(t1);
  return t2;
}


x86 assembly (clang, -O0):
<flu_tdiff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x0,-0x12(%rbp)
mov    $0x1,%edi
mov    $0x10,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1175 <flu_tdiff+0x45>
movw   $0x1,-0x12(%rbp)
mov    $0x0,%al
call   1040 <flu_now@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
sub    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jge    11d1 <flu_tdiff+0xa1>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0x3b9aca00,%rcx
mov    %rcx,(%rax)
cmpw   $0x0,-0x12(%rbp)
je     11e5 <flu_tdiff+0xb5>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flu_tdiff>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x1,%edi
mov    $0x10,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
mov    %rbx,%rax
test   %rbx,%rbx
jne    115c <flu_tdiff+0x2c>
xor    %eax,%eax
call   1040 <flu_now@plt>
movdqu (%rax),%xmm0
movdqu (%r15),%xmm1
psubq  %xmm1,%xmm0
movdqu %xmm0,(%r14)
movq   %xmm0,%rcx
test   %rcx,%rcx
js     1186 <flu_tdiff+0x56>
test   %rbx,%rbx
je     1198 <flu_tdiff+0x68>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
paddq  0xe72(%rip),%xmm0
movdqu %xmm0,(%r14)
test   %rbx,%rbx
jne    117d <flu_tdiff+0x4d>
mov    %rax,%rdi
call   1030 <free@plt>
jmp    117d <flu_tdiff+0x4d>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
define %struct.timespec* @flu_tdiff(%struct.timespec* %0, %struct.timespec* %1) {
%3 = alloca %struct.timespec*
%4 = alloca %struct.timespec*
%5 = alloca i16
%6 = alloca %struct.timespec*
store %struct.timespec* %0, %struct.timespec** %3
store %struct.timespec* %1, %struct.timespec** %4
store i16 0, i16* %5
%7 = call %struct.timespec* @calloc(i32 1, i32 16)
store %struct.timespec* %7, %struct.timespec** %6
%8 = load %struct.timespec*, %struct.timespec** %3
%9 = icmp eq %struct.timespec* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
store i16 1, i16* %5
%11 = call %struct.timespec* (...) @flu_now()
store %struct.timespec* %11, %struct.timespec** %3
br label %12
12: ; preds = %10, %2
%13 = load %struct.timespec*, %struct.timespec** %3
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 1
%15 = load i64, i64* %14
%16 = load %struct.timespec*, %struct.timespec** %4
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 1
%18 = load i64, i64* %17
%19 = sub nsw i64 %15, %18
%20 = load %struct.timespec*, %struct.timespec** %6
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 1
store i64 %19, i64* %21
%22 = load %struct.timespec*, %struct.timespec** %3
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %22, i32 0, i32 0
%24 = load i64, i64* %23
%25 = load %struct.timespec*, %struct.timespec** %4
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %25, i32 0, i32 0
%27 = load i64, i64* %26
%28 = sub nsw i64 %24, %27
%29 = load %struct.timespec*, %struct.timespec** %6
%30 = getelementptr inbounds %struct.timespec, %struct.timespec* %29, i32 0, i32 0
store i64 %28, i64* %30
%31 = load %struct.timespec*, %struct.timespec** %6
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %31, i32 0, i32 0
%33 = load i64, i64* %32
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %12
%36 = load %struct.timespec*, %struct.timespec** %6
%37 = getelementptr inbounds %struct.timespec, %struct.timespec* %36, i32 0, i32 1
%38 = load i64, i64* %37
%39 = add nsw i64 %38, -1
store i64 %39, i64* %37
%40 = load %struct.timespec*, %struct.timespec** %6
%41 = getelementptr inbounds %struct.timespec, %struct.timespec* %40, i32 0, i32 0
%42 = load i64, i64* %41
%43 = add nsw i64 %42, 1000000000
store i64 %43, i64* %41
br label %44
44: ; preds = %35, %12
%45 = load i16, i16* %5
%46 = icmp ne i16 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load %struct.timespec*, %struct.timespec** %3
%49 = call i32 @free(%struct.timespec* %48)
br label %50
50: ; preds = %47, %44
%51 = load %struct.timespec*, %struct.timespec** %6
ret %struct.timespec* %51
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
define noalias %struct.timespec* @flu_tdiff(%struct.timespec* %0, %struct.timespec* nocapture %1) {
%3 = tail call %struct.timespec* @calloc(i32 1, i32 16)
%4 = icmp eq %struct.timespec* %0, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call %struct.timespec* (...) @flu_now()
br label %7
7: ; preds = %5, %2
%8 = phi %struct.timespec* [ %6, %5 ], [ %0, %2 ]
%9 = bitcast %struct.timespec* %8 to <2 x i64>*
%10 = load <2 x i64>, <2 x i64>* %9
%11 = bitcast %struct.timespec* %1 to <2 x i64>*
%12 = load <2 x i64>, <2 x i64>* %11
%13 = sub nsw <2 x i64> %10, %12
%14 = bitcast %struct.timespec* %3 to <2 x i64>*
store <2 x i64> %13, <2 x i64>* %14
%15 = extractelement <2 x i64> %13, i64 0
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %7
%18 = add nsw <2 x i64> %13, <i64 1000000000, i64 -1>
%19 = bitcast %struct.timespec* %3 to <2 x i64>*
store <2 x i64> %18, <2 x i64>* %19
br label %20
20: ; preds = %17, %7
br i1 %4, label %21, label %23
21: ; preds = %20
%22 = tail call i32 @free(%struct.timespec* %8)
br label %23
23: ; preds = %21, %20
ret %struct.timespec* %3
}