#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 {
  long long tv_sec;
  long long tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
void ptimer_start(int FEAT_TIME, int counter, long long *start) {
  struct timespec begin;
  if ((FEAT_TIME) && (counter > 1)) {
    if (clock_gettime(CLOCK_MONOTONIC, &begin)) {
      exit(EXIT_FAILURE);
    }
    *start = begin.tv_sec * 1000000000LL + begin.tv_nsec;
  }
}


x86 assembly (clang, -O0):
<ptimer_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1183 <ptimer_start+0x63>
cmpl   $0x1,-0x8(%rbp)
jle    1183 <ptimer_start+0x63>
mov    0x2e9b(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     1170 <ptimer_start+0x50>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
imul   $0x3b9aca00,-0x20(%rbp),%rcx
3b
add    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptimer_start>:
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
je     1157 <ptimer_start+0x37>
cmp    $0x2,%esi
jl     1157 <ptimer_start+0x37>
mov    %rdx,%rbx
mov    0x2eb0(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
jne    115d <ptimer_start+0x3d>
imul   $0x3b9aca00,(%rsp),%rax
3b
add    0x8(%rsp),%rax
mov    %rax,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

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

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
@EXIT_FAILURE = global i32 0
define void @ptimer_start(i32 %0, i32 %1, i64* nocapture writeonly %2) {
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %4 to i8*
%6 = icmp ne i32 %0, 0
%7 = icmp sgt i32 %1, 1
%8 = and i1 %6, %7
br i1 %8, label %9, label %23
9: ; preds = %3
%10 = load i32, i32* @CLOCK_MONOTONIC
%11 = call i64 @clock_gettime(i32 %10, %struct.timespec* %4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %9
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%18 = load i64, i64* %17
%19 = mul nsw i64 %18, 1000000000
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%21 = load i64, i64* %20
%22 = add nsw i64 %19, %21
store i64 %22, i64* %2
br label %23
23: ; preds = %16, %3
ret void
}