#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 */
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, double);
scalar_t__ strcmp(char *, char *);
void rdz_duration_to_s(double duration, char *ca) {
  *ca = 0;
  if (duration < 0.0)
    return;
  char *e = getenv("RDZ_NO_DURATION");
  if (e && (strcmp(e, "1") == 0 || strcmp(e, "true")))
    return;
  if (duration < 1000.0) {
    sprintf(ca, "%fms ", duration);
    return;
  }
  double s = duration / 1000.0;
  sprintf(ca, "%.6f ", s);
  for (size_t i = 0;; ++i) {
    if (ca[i] == '.') {
      ca[i] = 's';
      break;
    }
  }
}


x86 assembly (clang, -O0):
<rdz_duration_to_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    115b <rdz_duration_to_s+0x2b>
jmp    124b <rdz_duration_to_s+0x11b>
lea    0xea6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11af <rdz_duration_to_s+0x7f>
mov    -0x18(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11aa <rdz_duration_to_s+0x7a>
mov    -0x18(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11af <rdz_duration_to_s+0x7f>
jmp    124b <rdz_duration_to_s+0x11b>
movsd  0xe49(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11dc <rdz_duration_to_s+0xac>
mov    -0x10(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
lea    0xe4d(%rip),%rsi
call   1050 <sprintf@plt>
jmp    124b <rdz_duration_to_s+0x11b>
movsd  -0x8(%rbp),%xmm0
movsd  0xe17(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
lea    0xe23(%rip),%rsi
call   1050 <sprintf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1235 <rdz_duration_to_s+0x105>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x73,(%rax,%rcx,1)
jmp    124b <rdz_duration_to_s+0x11b>
jmp    123a <rdz_duration_to_s+0x10a>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    120f <rdz_duration_to_s+0xdf>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rdz_duration_to_s>:
push   %r14
push   %rbx
push   %rax
movb   $0x0,(%rdi)
xorpd  %xmm1,%xmm1
movsd  %xmm0,(%rsp)
ucomisd %xmm0,%xmm1
ja     11dd <rdz_duration_to_s+0xad>
mov    %rdi,%rbx
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1189 <rdz_duration_to_s+0x59>
mov    %rax,%r14
lea    0xeb0(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11dd <rdz_duration_to_s+0xad>
lea    0xe9e(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11dd <rdz_duration_to_s+0xad>
movsd  0xe6f(%rip),%xmm1
movsd  (%rsp),%xmm0
ucomisd %xmm0,%xmm1
jbe    11b2 <rdz_duration_to_s+0x82>
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <sprintf@plt>
divsd  0xe46(%rip),%xmm0
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
nopl   0x0(%rax)
cmpb   $0x2e,(%rbx)
lea    0x1(%rbx),%rbx
jne    11d0 <rdz_duration_to_s+0xa0>
movb   $0x73,-0x1(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"RDZ_NO_DURATION\00"
@.str.1 = [2 x i8] c"1\00"
@.str.2 = [5 x i8] c"true\00"
@.str.3 = [6 x i8] c"%fms \00"
@.str.4 = [6 x i8] c"%.6f \00"
define void @rdz_duration_to_s(double %0, i8* %1) {
%3 = alloca double
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca double
%7 = alloca i64
store double %0, double* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
store i8 0, i8* %8
%9 = load double, double* %3
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %2
br label %53
12: ; preds = %2
%13 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i8*, i8** %5
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20, %16
br label %53
25: ; preds = %20, %12
%26 = load double, double* %3
%27 = fcmp olt double %26, 1.000000e+03
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i8*, i8** %4
%30 = load double, double* %3
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %30)
br label %53
32: ; preds = %25
%33 = load double, double* %3
%34 = fdiv double %33, 1.000000e+03
store double %34, double* %6
%35 = load i8*, i8** %4
%36 = load double, double* %6
%37 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %36)
store i64 0, i64* %7
br label %38
38: ; preds = %50, %32
%39 = load i8*, i8** %4
%40 = load i64, i64* %7
%41 = getelementptr inbounds i8, i8* %39, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 46
br i1 %44, label %45, label %49
45: ; preds = %38
%46 = load i8*, i8** %4
%47 = load i64, i64* %7
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8 115, i8* %48
br label %53
49: ; preds = %38
br label %50
50: ; preds = %49
%51 = load i64, i64* %7
%52 = add i64 %51, 1
store i64 %52, i64* %7
br label %38
53: ; preds = %11, %24, %28, %45
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"RDZ_NO_DURATION\00"
@.str.1 = [2 x i8] c"1\00"
@.str.2 = [5 x i8] c"true\00"
@.str.3 = [6 x i8] c"%fms \00"
@.str.4 = [6 x i8] c"%.6f \00"
define void @rdz_duration_to_s(double %0, i8* nocapture %1) {
store i8 0, i8* %1
%3 = fcmp olt double %0, 0.000000e+00
br i1 %3, label %28, label %4
4: ; preds = %2
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %28, label %10
10: ; preds = %7
%11 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %10, %4
%14 = fcmp olt double %0, 1.000000e+03
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = tail call i32 @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %0)
br label %28
17: ; preds = %13
%18 = fdiv double %0, 1.000000e+03
%19 = tail call i32 @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %18)
br label %20
20: ; preds = %20, %17
%21 = phi i64 [ 0, %17 ], [ %25, %20 ]
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 46
%25 = add i64 %21, 1
br i1 %24, label %26, label %20
26: ; preds = %20
%27 = getelementptr inbounds i8, i8* %1, i64 %21
store i8 115, i8* %27
br label %28
28: ; preds = %15, %26, %10, %7, %2
ret void
}