#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__ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ gptm_set_timer_prescaler(int /*<<< orphan*/,
                                            int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ gptm_start_timer(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ gptm_stop_timer(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ gptm_write_timer(int /*<<< orphan*/, int /*<<< orphan*/,
                                    int /*<<< orphan*/);
void startTimer(uint8_t granularity) {
  gptm_stop_timer(0, 0);
  gptm_write_timer(0, 0, 0);
  if (granularity > 0) {
    gptm_set_timer_prescaler(0, 0, granularity - 1);
    gptm_start_timer(0, 0);
  } else {
    gptm_set_timer_prescaler(0, 0, 0);
  }
}


x86 assembly (clang, -O0):
<startTimer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
xor    %esi,%esi
mov    %esi,%edi
call   1050 <gptm_stop_timer@plt>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1030 <gptm_write_timer@plt>
cmpq   $0x0,-0x8(%rbp)
jle    118a <startTimer+0x4a>
mov    -0x8(%rbp),%rdx
sub    $0x1,%rdx
xor    %esi,%esi
mov    %esi,%edi
call   1040 <gptm_set_timer_prescaler@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1060 <gptm_start_timer@plt>
jmp    1197 <startTimer+0x57>
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
mov    %esi,%edi
call   1040 <gptm_set_timer_prescaler@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startTimer>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
xor    %esi,%esi
call   1050 <gptm_stop_timer@plt>
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <gptm_write_timer@plt>
test   %rbx,%rbx
jle    1177 <startTimer+0x37>
add    $0xffffffffffffffff,%rbx
xor    %edi,%edi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <gptm_set_timer_prescaler@plt>
xor    %edi,%edi
xor    %esi,%esi
pop    %rbx
jmp    1060 <gptm_start_timer@plt>
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
pop    %rbx
jmp    1040 <gptm_set_timer_prescaler@plt>

LLVM IR (-O0):
define void @startTimer(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = call i32 @gptm_stop_timer(i32 0, i32 0)
%4 = call i32 @gptm_write_timer(i32 0, i32 0, i32 0)
%5 = load i64, i64* %2
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i64, i64* %2
%9 = sub nsw i64 %8, 1
%10 = call i32 @gptm_set_timer_prescaler(i32 0, i32 0, i64 %9)
%11 = call i32 @gptm_start_timer(i32 0, i32 0)
br label %14
12: ; preds = %1
%13 = call i32 @gptm_set_timer_prescaler(i32 0, i32 0, i64 0)
br label %14
14: ; preds = %12, %7
ret void
}

LLVM IR (-O2):
define void @startTimer(i64 %0) {
%2 = tail call i32 @gptm_stop_timer(i32 0, i32 0)
%3 = tail call i32 @gptm_write_timer(i32 0, i32 0, i32 0)
%4 = icmp sgt i64 %0, 0
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = add nsw i64 %0, -1
%7 = tail call i32 @gptm_set_timer_prescaler(i32 0, i32 0, i64 %6)
%8 = tail call i32 @gptm_start_timer(i32 0, i32 0)
br label %11
9: ; preds = %1
%10 = tail call i32 @gptm_set_timer_prescaler(i32 0, i32 0, i64 0)
br label %11
11: ; preds = %9, %5
ret void
}