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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ dosum(long);
int /*<<< orphan*/ printf(char *, ...);
long int get_times(int base, int usec) {
  struct timespec tv1, tv2;
  int n = 1;
  printf("get times of %d usec. 1 usec = 0.001 second.\n", usec);
  while (1) {
    clock_gettime(CLOCK_REALTIME, &tv1);
    dosum((long int)base * n);
    clock_gettime(CLOCK_REALTIME, &tv2);
    long long cosume = (tv2.tv_sec - tv1.tv_sec) * 1000000000;
    cosume += tv2.tv_nsec - tv1.tv_nsec;
    cosume /= 1000000;
    if (cosume >= usec) {
      break;
    }
    n++;
  }
  long long int time =
      (tv2.tv_sec - tv1.tv_sec) * 1000000000 + (tv2.tv_nsec - tv1.tv_nsec);
  printf("Done, %d usec is %lld times.\n", usec, base * n);
  printf("its acturally time is %ld nanoseconds.\n", time);
  int a_usec = time / 1000000;
  long int times = base * n / a_usec;
  printf("actural usec: %d, times: %ld\n", a_usec, times);
  printf("----------------------------\n");
  return times;
}


x86 assembly (clang, -O0):
<get_times>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
movslq -0x4(%rbp),%rdi
movslq -0x2c(%rbp),%rax
imul   %rax,%rdi
call   1050 <dosum@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x28(%rbp),%eax
sub    -0x18(%rbp),%eax
imul   $0x3b9aca00,%eax,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x10(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
jl     11d5 <get_times+0xa5>
jmp    11e3 <get_times+0xb3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1156 <get_times+0x26>
mov    -0x28(%rbp),%eax
sub    -0x18(%rbp),%eax
imul   $0x3b9aca00,%eax,%eax
cltq
mov    -0x20(%rbp),%rcx
sub    -0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
imul   -0x2c(%rbp),%edx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %eax,-0x44(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x2c(%rbp),%eax
cltd
idivl  -0x44(%rbp)
cltq
mov    %rax,-0x50(%rbp)
mov    -0x44(%rbp),%esi
mov    -0x50(%rbp),%rdx
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_times>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebp
mov    %edi,%r14d
lea    0xea6(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,0x4(%rsp)
movslq %r14d,%r12
mov    %ebp,(%rsp)
movslq %ebp,%r13
mov    %r12,%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2e59(%rip),%r14
mov    (%r14),%edi
lea    0x18(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    %rbp,%rdi
call   1060 <dosum@plt>
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
call   1040 <clock_gettime@plt>
movslq 0x8(%rsp),%rax
movslq 0x18(%rsp),%rcx
sub    %rcx,%rax
imul   $0x3b9aca00,%rax,%rax
mov    0x10(%rsp),%r15
sub    0x20(%rsp),%r15
add    %rax,%r15
mov    %r15,%rax
movabs $0x431bde82d7b634db,%rcx
de 1b 43
imul   %rcx
mov    %rdx,%r14
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%r14
add    %rax,%r14
add    0x4(%rsp),%ebx
add    %r12,%rbp
cmp    %r13,%r14
jl     1180 <get_times+0x40>
lea    0xe30(%rip),%rdi
mov    (%rsp),%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe3b(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
cltd
idiv   %r14d
movslq %eax,%rbx
lea    0xe49(%rip),%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@.str = [46 x i8] c"get times of %d usec. 1 usec = 0.001 second.\0A\00"
@CLOCK_REALTIME = global i32 0
@.str.1 = [30 x i8] c"Done, %d usec is %lld times.\0A\00"
@.str.2 = [40 x i8] c"its acturally time is %ld nanoseconds.\0A\00"
@.str.3 = [30 x i8] c"actural usec: %d, times: %ld\0A\00"
@.str.4 = [30 x i8] c"----------------------------\0A\00"
define i64 @get_times(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timespec
%6 = alloca %struct.timespec
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 1, i32* %7
%12 = load i32, i32* %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %2, %46
%15 = load i32, i32* @CLOCK_REALTIME
%16 = call i32 @clock_gettime(i32 %15, %struct.timespec* %5)
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = mul nsw i64 %18, %20
%22 = call i32 @dosum(i64 %21)
%23 = load i32, i32* @CLOCK_REALTIME
%24 = call i32 @clock_gettime(i32 %23, %struct.timespec* %6)
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%28 = load i32, i32* %27
%29 = sub nsw i32 %26, %28
%30 = mul nsw i32 %29, 1000000000
%31 = sext i32 %30 to i64
store i64 %31, i64* %8
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%33 = load i64, i64* %32
%34 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%35 = load i64, i64* %34
%36 = sub nsw i64 %33, %35
%37 = load i64, i64* %8
%38 = add nsw i64 %37, %36
store i64 %38, i64* %8
%39 = load i64, i64* %8
%40 = sdiv i64 %39, 1000000
store i64 %40, i64* %8
%41 = load i64, i64* %8
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = icmp sge i64 %41, %43
br i1 %44, label %45, label %46
45: ; preds = %14
br label %49
46: ; preds = %14
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %14
49: ; preds = %45
%50 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%53 = load i32, i32* %52
%54 = sub nsw i32 %51, %53
%55 = mul nsw i32 %54, 1000000000
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%58 = load i64, i64* %57
%59 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%60 = load i64, i64* %59
%61 = sub nsw i64 %58, %60
%62 = add nsw i64 %56, %61
store i64 %62, i64* %9
%63 = load i32, i32* %4
%64 = load i32, i32* %3
%65 = load i32, i32* %7
%66 = mul nsw i32 %64, %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %63, i32 %66)
%68 = load i64, i64* %9
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i64 %68)
%70 = load i64, i64* %9
%71 = sdiv i64 %70, 1000000
%72 = trunc i64 %71 to i32
store i32 %72, i32* %10
%73 = load i32, i32* %3
%74 = load i32, i32* %7
%75 = mul nsw i32 %73, %74
%76 = load i32, i32* %10
%77 = sdiv i32 %75, %76
%78 = sext i32 %77 to i64
store i64 %78, i64* %11
%79 = load i32, i32* %10
%80 = load i64, i64* %11
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %79, i64 %80)
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%83 = load i64, i64* %11
ret i64 %83
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@.str = [46 x i8] c"get times of %d usec. 1 usec = 0.001 second.\0A\00"
@CLOCK_REALTIME = global i32 0
@.str.1 = [30 x i8] c"Done, %d usec is %lld times.\0A\00"
@.str.2 = [40 x i8] c"its acturally time is %ld nanoseconds.\0A\00"
@.str.3 = [30 x i8] c"actural usec: %d, times: %ld\0A\00"
@str = [29 x i8] c"----------------------------\00"
define i64 @get_times(i32 %0, i32 %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %3 to i8*
%6 = bitcast %struct.timespec* %4 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %1)
%8 = sext i32 %0 to i64
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%13 = sext i32 %1 to i64
br label %14
14: ; preds = %14, %2
%15 = phi i64 [ %33, %14 ], [ 1, %2 ]
%16 = load i32, i32* @CLOCK_REALTIME
%17 = call i32 @clock_gettime(i32 %16, %struct.timespec* %3)
%18 = mul nsw i64 %15, %8
%19 = call i32 @dosum(i64 %18)
%20 = load i32, i32* @CLOCK_REALTIME
%21 = call i32 @clock_gettime(i32 %20, %struct.timespec* %4)
%22 = load i32, i32* %9
%23 = load i32, i32* %10
%24 = sub nsw i32 %22, %23
%25 = mul nsw i32 %24, 1000000000
%26 = sext i32 %25 to i64
%27 = load i64, i64* %11
%28 = load i64, i64* %12
%29 = sub nsw i64 %27, %28
%30 = add nsw i64 %29, %26
%31 = sdiv i64 %30, 1000000
%32 = icmp slt i64 %31, %13
%33 = add nuw i64 %15, 1
br i1 %32, label %14, label %34
34: ; preds = %14
%35 = trunc i64 %15 to i32
%36 = mul nsw i32 %35, %0
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i64 %30)
%39 = trunc i64 %31 to i32
%40 = sdiv i32 %36, %39
%41 = sext i32 %40 to i64
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %39, i64 %41)
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
ret i64 %41
}