#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 /*<<< orphan*/ t;
struct timespec {
  int tv_sec;
  scalar_t__ tv_nsec;
};
typedef int /*<<< orphan*/ clockid_t;

/* Variables and functions */
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ memcpy(struct timespec *, struct timespec *, int);
int clk_upd(struct timespec *q, clockid_t ty) {
  struct timespec t;
  memcpy(&t, q, sizeof(t));
  clock_gettime(ty, q);
  return ((int)(1000000000 * ((q)->tv_sec - (&t)->tv_sec) + (q)->tv_nsec -
                (&t)->tv_nsec));
}


x86 assembly (clang, -O0):
<clk_upd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x20(%rbp),%rdi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
sub    -0x20(%rbp),%eax
imul   $0x3b9aca00,%eax,%eax
cltq
mov    -0x8(%rbp),%rcx
add    0x8(%rcx),%rax
sub    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clk_upd>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <clock_gettime@plt>
mov    (%rbx),%ecx
mov    0x8(%rbx),%eax
sub    0x8(%rsp),%ecx
imul   $0x3b9aca00,%ecx,%ecx
sub    0x10(%rsp),%eax
add    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
define i32 @clk_upd(%struct.timespec* %0, i32 %1) {
%3 = alloca %struct.timespec*
%4 = alloca i32
%5 = alloca %struct.timespec
store %struct.timespec* %0, %struct.timespec** %3
store i32 %1, i32* %4
%6 = load %struct.timespec*, %struct.timespec** %3
%7 = call i32 @memcpy(%struct.timespec* %5, %struct.timespec* %6, i32 16)
%8 = load i32, i32* %4
%9 = load %struct.timespec*, %struct.timespec** %3
%10 = call i32 @clock_gettime(i32 %8, %struct.timespec* %9)
%11 = load %struct.timespec*, %struct.timespec** %3
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = sub nsw i32 %13, %15
%17 = mul nsw i32 1000000000, %16
%18 = sext i32 %17 to i64
%19 = load %struct.timespec*, %struct.timespec** %3
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 1
%21 = load i64, i64* %20
%22 = add nsw i64 %18, %21
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%24 = load i64, i64* %23
%25 = sub nsw i64 %22, %24
%26 = trunc i64 %25 to i32
ret i32 %26
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
define i32 @clk_upd(%struct.timespec* %0, i32 %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = call i32 @memcpy(%struct.timespec* %3, %struct.timespec* %0, i32 16)
%6 = call i32 @clock_gettime(i32 %1, %struct.timespec* %0)
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%10 = load i32, i32* %9
%11 = sub nsw i32 %8, %10
%12 = mul nsw i32 %11, 1000000000
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%14 = load i64, i64* %13
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%16 = load i64, i64* %15
%17 = sub i64 %14, %16
%18 = trunc i64 %17 to i32
%19 = add i32 %12, %18
ret i32 %19
}