#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 scalar_t__ uint64_t;
struct timespec {
  unsigned long tv_sec;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_PROCESS_CPUTIME_ID;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
uint64_t empty_loop(uint64_t iterations) {
  uint64_t iter;
  uint64_t result = 0;
  struct timespec tv1, tv2;
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tv1);
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tv2);
  result = (tv2.tv_nsec + tv2.tv_sec * 1000000000ul) -
           (tv1.tv_nsec + tv1.tv_sec * 1000000000ul);
  return result;
}


x86 assembly (clang, -O0):
<empty_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x30(%rbp),%rax
imul   $0x3b9aca00,-0x38(%rbp),%rcx
3b
add    %rcx,%rax
mov    -0x20(%rbp),%rcx
imul   $0x3b9aca00,-0x28(%rbp),%rdx
3b
add    %rdx,%rcx
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<empty_loop>:
push   %rbx
sub    $0x20,%rsp
mov    0x2ecc(%rip),%rbx
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
call   1030 <clock_gettime@plt>
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
mov    (%rsp),%rcx
mov    0x8(%rsp),%rax
sub    0x10(%rsp),%rcx
imul   $0x3b9aca00,%rcx,%rcx
sub    0x18(%rsp),%rax
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbx
ret

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

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