#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;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ format_time(struct timespec *);
void format_timediff(const struct timespec *now, const struct timespec *then) {
  struct timespec diff = {0};
  diff.tv_sec = now->tv_sec - then->tv_sec;
  if (now->tv_nsec < then->tv_nsec) {
    diff.tv_sec--;
    diff.tv_nsec = 1000000000 + now->tv_nsec - then->tv_nsec;
  } else {
    diff.tv_nsec = now->tv_nsec - then->tv_nsec;
  }
  format_time(&diff);
}


x86 assembly (clang, -O0):
<format_timediff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jge    1191 <format_timediff+0x71>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    $0x3b9aca00,%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x28(%rbp)
jmp    11a3 <format_timediff+0x83>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
call   1040 <format_time@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_timediff>:
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
mov    0x8(%rdi),%rdx
sub    0x8(%rsi),%rdx
mov    %rdx,0x8(%rsp)
mov    (%rdi),%rax
mov    (%rsi),%rcx
cmp    %rcx,%rax
jge    1144 <format_timediff+0x34>
add    $0xffffffffffffffff,%rdx
mov    %rdx,0x8(%rsp)
add    $0x3b9aca00,%rax
sub    %rcx,%rax
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1030 <format_time@plt>
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
%struct.timespec = type { i64, i64, i32 }
define void @format_timediff(%struct.timespec* nocapture %0, %struct.timespec* nocapture %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 2
%6 = bitcast i32* %5 to i64*
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%8 = load i64, i64* %7
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%10 = load i64, i64* %9
%11 = sub nsw i64 %8, %10
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
store i64 %11, i64* %12
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%14 = load i64, i64* %13
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%16 = load i64, i64* %15
%17 = icmp slt i64 %14, %16
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = add nsw i64 %11, -1
store i64 %19, i64* %12
%20 = add nsw i64 %14, 1000000000
br label %21
21: ; preds = %2, %18
%22 = phi i64 [ %20, %18 ], [ %14, %2 ]
%23 = sub i64 %22, %16
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
store i64 %23, i64* %24
%25 = call i32 @format_time(%struct.timespec* %3)
ret void
}