#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 {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_PROCESS_CPUTIME_ID;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ printf(char *, double);
double timespec_to_ms(struct timespec *);
int main() {
  struct timespec start_time, end_time;
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time);
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time);
  printf("%f ms\n", timespec_to_ms(&end_time) - timespec_to_ms(&start_time));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
lea    -0x10(%rbp),%rdi
call   1050 <timespec_to_ms@plt>
movsd  %xmm0,-0x18(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <timespec_to_ms@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2eaa(%rip),%rbx
mov    (%rbx),%edi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
call   1030 <clock_gettime@plt>
mov    (%rbx),%edi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1030 <clock_gettime@plt>
mov    %rbx,%rdi
call   1050 <timespec_to_ms@plt>
movsd  %xmm0,(%rsp)
mov    %r14,%rdi
call   1050 <timespec_to_ms@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
lea    0xe7f(%rip),%rdi
movapd %xmm1,%xmm0
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@.str = [7 x i8] c"%f ms\0A\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timespec
%3 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%4 = call i32 @clock_gettime(i32 %3, %struct.timespec* %1)
%5 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %2)
%7 = call double @timespec_to_ms(%struct.timespec* %2)
%8 = call double @timespec_to_ms(%struct.timespec* %1)
%9 = fsub double %7, %8
%10 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %9)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@.str = [7 x i8] c"%f ms\0A\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %1 to i8*
%4 = bitcast %struct.timespec* %2 to i8*
%5 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %1)
%7 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%8 = call i32 @clock_gettime(i32 %7, %struct.timespec* %2)
%9 = call double @timespec_to_ms(%struct.timespec* %2)
%10 = call double @timespec_to_ms(%struct.timespec* %1)
%11 = fsub double %9, %10
%12 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %11)
ret i32 0
}