#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 */
typedef int uint64_t;
typedef scalar_t__ time_t;
struct timespec {
  scalar_t__ tv_sec;
  long tv_nsec;
};

/* Variables and functions */
int UINT64_C(int);
int UINT64_MAX;
uint64_t timespec_to_nsec(struct timespec t) {
  if (t.tv_sec == (time_t)-1 && t.tv_nsec == (long)-1)
    return UINT64_MAX;
  return (uint64_t)t.tv_sec * UINT64_C(1000000000) + (uint64_t)t.tv_nsec;
}


x86 assembly (clang, -O0):
<timespec_to_nsec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    1147 <timespec_to_nsec+0x37>
cmpq   $0xffffffffffffffff,-0x10(%rbp)
jne    1147 <timespec_to_nsec+0x37>
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1169 <timespec_to_nsec+0x59>
mov    -0x18(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    $0x3b9aca00,%edi
call   1030 <UINT64_C@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   %ecx,%eax
mov    -0x10(%rbp),%rcx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_to_nsec>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
cmp    $0xffffffffffffffff,%rdi
jne    1131 <timespec_to_nsec+0x21>
cmp    $0xffffffffffffffff,%rbx
jne    1131 <timespec_to_nsec+0x21>
mov    0x2eab(%rip),%rax
mov    (%rax),%ebx
jmp    1141 <timespec_to_nsec+0x31>
mov    $0x3b9aca00,%edi
call   1030 <UINT64_C@plt>
imul   %r14d,%eax
add    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@UINT64_MAX = global i32 0
define i32 @timespec_to_nsec(i64 %0, i64 %1) {
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %4 to { i64, i64 }*
%6 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %5, i32 0, i32 0
store i64 %0, i64* %6
%7 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %5, i32 0, i32 1
store i64 %1, i64* %7
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%9 = load i64, i64* %8
%10 = icmp eq i64 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%13 = load i64, i64* %12
%14 = icmp eq i64 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load i32, i32* @UINT64_MAX
store i32 %16, i32* %3
br label %27
17: ; preds = %11, %2
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%19 = load i64, i64* %18
%20 = trunc i64 %19 to i32
%21 = call i32 @UINT64_C(i32 1000000000)
%22 = mul nsw i32 %20, %21
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%24 = load i64, i64* %23
%25 = trunc i64 %24 to i32
%26 = add nsw i32 %22, %25
store i32 %26, i32* %3
br label %27
27: ; preds = %17, %15
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@UINT64_MAX = global i32 0
define i32 @timespec_to_nsec(i64 %0, i64 %1) {
%3 = icmp eq i64 %0, -1
%4 = icmp eq i64 %1, -1
%5 = select i1 %3, i1 %4, i1 false
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i32, i32* @UINT64_MAX
br label %14
8: ; preds = %2
%9 = trunc i64 %0 to i32
%10 = tail call i32 @UINT64_C(i32 1000000000)
%11 = mul nsw i32 %10, %9
%12 = trunc i64 %1 to i32
%13 = add nsw i32 %11, %12
br label %14
14: ; preds = %8, %6
%15 = phi i32 [ %7, %6 ], [ %13, %8 ]
ret i32 %15
}