#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, scalar_t__,
                           scalar_t__, scalar_t__, scalar_t__);
int /*<<< orphan*/ stderr;
scalar_t__ timespec_cmp(struct timespec, struct timespec);
void timespec_sub(struct timespec a, struct timespec b, struct timespec *res) {
  if (timespec_cmp(a, b) < 0) {
    res->tv_sec = 0;
    res->tv_nsec = 0;
    fprintf(
        stderr, "%s:%d error: %lu.%09ld - %lu.%09ld\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/cunha/dstructs/refs/heads/master/timespec.c",
        59, a.tv_sec, a.tv_nsec, b.tv_sec, b.tv_nsec);
  } else {
    res->tv_nsec = a.tv_nsec - b.tv_nsec;
    res->tv_sec = a.tv_sec - b.tv_sec;
    if (res->tv_nsec < 0) {
      res->tv_nsec += 1000000000;
      res->tv_sec--;
    }
  }
}


x86 assembly (clang, -O0):
<timespec_sub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <timespec_cmp@plt>
cmp    $0x0,%rax
jge    11b1 <timespec_sub+0x91>
mov    -0x28(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%r8
mov    -0x10(%rbp),%r9
mov    -0x18(%rbp),%r10
mov    -0x20(%rbp),%rax
lea    0xe6e(%rip),%rsi
lea    0xe8b(%rip),%rdx
mov    $0x3b,%ecx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <fprintf@plt>
jmp    1204 <timespec_sub+0xe4>
mov    -0x10(%rbp),%rcx
sub    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rcx
sub    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jge    11ff <timespec_sub+0xdf>
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
add    $0x3b9aca00,%rcx
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
jmp    1204 <timespec_sub+0xe4>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_sub>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r13
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <timespec_cmp@plt>
test   %rax,%rax
js     1167 <timespec_sub+0x47>
sub    %r15,%r14
sub    %r12,%rbx
mov    %rbx,0x0(%r13)
mov    %r14,0x8(%r13)
jns    119e <timespec_sub+0x7e>
add    $0x3b9aca00,%rbx
mov    %rbx,0x0(%r13)
add    $0xffffffffffffffff,%r14
mov    %r14,0x8(%r13)
jmp    119e <timespec_sub+0x7e>
xorps  %xmm0,%xmm0
movups %xmm0,0x0(%r13)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
lea    0xe9e(%rip),%rdx
mov    $0x3b,%ecx
mov    %r14,%r8
mov    %rbx,%r9
push   %r12
push   %r15
call   1040 <fprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@stderr = global i32 0
@.str = [36 x i8] c"%s:%d error: %lu.%09ld - %lu.%09ld\0A\00"
@.str.1 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cunha/dstructs/refs/heads/master/timespec.c\00"
define void @timespec_sub(i64 %0, i64 %1, i64 %2, i64 %3, %struct.timespec* %4) {
%6 = alloca %struct.timespec
%7 = alloca %struct.timespec
%8 = alloca %struct.timespec*
%9 = bitcast %struct.timespec* %6 to { i64, i64 }*
%10 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %9, i32 0, i32 0
store i64 %0, i64* %10
%11 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %9, i32 0, i32 1
store i64 %1, i64* %11
%12 = bitcast %struct.timespec* %7 to { i64, i64 }*
%13 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %12, i32 0, i32 0
store i64 %2, i64* %13
%14 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %12, i32 0, i32 1
store i64 %3, i64* %14
store %struct.timespec* %4, %struct.timespec** %8
%15 = bitcast %struct.timespec* %6 to { i64, i64 }*
%16 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %15, i32 0, i32 1
%19 = load i64, i64* %18
%20 = bitcast %struct.timespec* %7 to { i64, i64 }*
%21 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %20, i32 0, i32 0
%22 = load i64, i64* %21
%23 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %20, i32 0, i32 1
%24 = load i64, i64* %23
%25 = call i64 @timespec_cmp(i64 %17, i64 %19, i64 %22, i64 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %42
27: ; preds = %5
%28 = load %struct.timespec*, %struct.timespec** %8
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %28, i32 0, i32 1
store i64 0, i64* %29
%30 = load %struct.timespec*, %struct.timespec** %8
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %30, i32 0, i32 0
store i64 0, i64* %31
%32 = load i32, i32* @stderr
%33 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%34 = load i64, i64* %33
%35 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%36 = load i64, i64* %35
%37 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%38 = load i64, i64* %37
%39 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%40 = load i64, i64* %39
%41 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 59, i64 %34, i64 %36, i64 %38, i64 %40)
br label %71
42: ; preds = %5
%43 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%44 = load i64, i64* %43
%45 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%46 = load i64, i64* %45
%47 = sub nsw i64 %44, %46
%48 = load %struct.timespec*, %struct.timespec** %8
%49 = getelementptr inbounds %struct.timespec, %struct.timespec* %48, i32 0, i32 0
store i64 %47, i64* %49
%50 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%51 = load i64, i64* %50
%52 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%53 = load i64, i64* %52
%54 = sub nsw i64 %51, %53
%55 = load %struct.timespec*, %struct.timespec** %8
%56 = getelementptr inbounds %struct.timespec, %struct.timespec* %55, i32 0, i32 1
store i64 %54, i64* %56
%57 = load %struct.timespec*, %struct.timespec** %8
%58 = getelementptr inbounds %struct.timespec, %struct.timespec* %57, i32 0, i32 0
%59 = load i64, i64* %58
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %70
61: ; preds = %42
%62 = load %struct.timespec*, %struct.timespec** %8
%63 = getelementptr inbounds %struct.timespec, %struct.timespec* %62, i32 0, i32 0
%64 = load i64, i64* %63
%65 = add nsw i64 %64, 1000000000
store i64 %65, i64* %63
%66 = load %struct.timespec*, %struct.timespec** %8
%67 = getelementptr inbounds %struct.timespec, %struct.timespec* %66, i32 0, i32 1
%68 = load i64, i64* %67
%69 = add nsw i64 %68, -1
store i64 %69, i64* %67
br label %70
70: ; preds = %61, %42
br label %71
71: ; preds = %70, %27
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@stderr = global i32 0
@.str = [36 x i8] c"%s:%d error: %lu.%09ld - %lu.%09ld\0A\00"
@.str.1 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cunha/dstructs/refs/heads/master/timespec.c\00"
define void @timespec_sub(i64 %0, i64 %1, i64 %2, i64 %3, %struct.timespec* nocapture %4) {
%6 = tail call i64 @timespec_cmp(i64 %0, i64 %1, i64 %2, i64 %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = bitcast %struct.timespec* %4 to i8*
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 59, i64 %1, i64 %0, i64 %3, i64 %2)
br label %21
12: ; preds = %5
%13 = sub nsw i64 %0, %2
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
store i64 %13, i64* %14
%15 = sub nsw i64 %1, %3
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
store i64 %15, i64* %16
%17 = icmp slt i64 %13, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = add nsw i64 %13, 1000000000
store i64 %19, i64* %14
%20 = add nsw i64 %15, -1
store i64 %20, i64* %16
br label %21
21: ; preds = %12, %18, %8
ret void
}