#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, double, char *);
void printtime(char *msg, double time) {
  char *units;
  if (time < 1e-06) {
    units = "ns";
    time *= 1e9;
  } else if (time < 1e-03) {
    units = "us";
    time *= 1e6;
  } else if (time < 1) {
    units = "ms";
    time *= 1e3;
  } else {
    units = "s";
  }
  printf("%s: %.1f %s\n", msg, time, units);
}


x86 assembly (clang, -O0):
<printtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  0xed7(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1156 <printtime+0x46>
lea    0xef5(%rip),%rax
mov    %rax,-0x18(%rbp)
movsd  0xee1(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11d5 <printtime+0xc5>
movsd  0xeaa(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    118b <printtime+0x7b>
lea    0xec3(%rip),%rax
mov    %rax,-0x18(%rbp)
movsd  0xea4(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11d0 <printtime+0xc0>
movsd  0xe7d(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11c0 <printtime+0xb0>
lea    0xe91(%rip),%rax
mov    %rax,-0x18(%rbp)
movsd  0xe67(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11cb <printtime+0xbb>
lea    0xe70(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11d0 <printtime+0xc0>
jmp    11d5 <printtime+0xc5>
mov    -0x8(%rbp),%rsi
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rdx
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printtime>:
mov    %rdi,%rsi
movsd  0xee5(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    113c <printtime+0x2c>
mulsd  0xeff(%rip),%xmm0
lea    0xf00(%rip),%rdx
lea    0xf02(%rip),%rdi
jmp    1030 <printf@plt>
movsd  0xec4(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1165 <printtime+0x55>
mulsd  0xece(%rip),%xmm0
lea    0xeda(%rip),%rdx
lea    0xed9(%rip),%rdi
jmp    1030 <printf@plt>
movsd  0xea3(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    118e <printtime+0x7e>
mulsd  0xe9d(%rip),%xmm0
lea    0xeb4(%rip),%rdx
lea    0xeb0(%rip),%rdi
jmp    1030 <printf@plt>
lea    0xea2(%rip),%rdx
lea    0xe9d(%rip),%rdi
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"ns\00"
@.str.1 = [3 x i8] c"us\00"
@.str.2 = [3 x i8] c"ms\00"
@.str.3 = [2 x i8] c"s\00"
@.str.4 = [13 x i8] c"%s: %.1f %s\0A\00"
define void @printtime(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
%5 = alloca i8*
store i8* %0, i8** %3
store double %1, double* %4
%6 = load double, double* %4
%7 = fcmp olt double %6, 0x3EB0C6F7A0B5ED8D
br i1 %7, label %8, label %11
8: ; preds = %2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5
%9 = load double, double* %4
%10 = fmul double %9, 1.000000e+09
store double %10, double* %4
br label %26
11: ; preds = %2
%12 = load double, double* %4
%13 = fcmp olt double %12, 1.000000e-03
br i1 %13, label %14, label %17
14: ; preds = %11
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %5
%15 = load double, double* %4
%16 = fmul double %15, 1.000000e+06
store double %16, double* %4
br label %25
17: ; preds = %11
%18 = load double, double* %4
%19 = fcmp olt double %18, 1.000000e+00
br i1 %19, label %20, label %23
20: ; preds = %17
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %5
%21 = load double, double* %4
%22 = fmul double %21, 1.000000e+03
store double %22, double* %4
br label %24
23: ; preds = %17
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %5
br label %24
24: ; preds = %23, %20
br label %25
25: ; preds = %24, %14
br label %26
26: ; preds = %25, %8
%27 = load i8*, i8** %3
%28 = load double, double* %4
%29 = load i8*, i8** %5
%30 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %27, double %28, i8* %29)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"ns\00"
@.str.1 = [3 x i8] c"us\00"
@.str.2 = [3 x i8] c"ms\00"
@.str.3 = [2 x i8] c"s\00"
@.str.4 = [13 x i8] c"%s: %.1f %s\0A\00"
define void @printtime(i8* %0, double %1) {
%3 = fcmp olt double %1, 0x3EB0C6F7A0B5ED8D
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = fmul double %1, 1.000000e+09
br label %14
6: ; preds = %2
%7 = fcmp olt double %1, 1.000000e-03
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = fmul double %1, 1.000000e+06
br label %14
10: ; preds = %6
%11 = fcmp olt double %1, 1.000000e+00
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = fmul double %1, 1.000000e+03
br label %14
14: ; preds = %10, %8, %12, %4
%15 = phi double [ %5, %4 ], [ %9, %8 ], [ %13, %12 ], [ %1, %10 ]
%16 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %12 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %10 ]
%17 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %0, double %15, i8* %16)
ret void
}