#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*/ sprintf(char *, char *, ...);
void format_relative_time(char *buffer, double dt) {
  double hour = 60 * 60;
  double day = 24 * hour;
  if (dt <= 0) {
    sprintf(buffer, "soon");
  } else if (dt > 999 * day) {
    sprintf(buffer, " -- ");
  } else if (dt >= day) {
    sprintf(buffer, "%3dd", (int)(dt / day + 0.5));
  } else if (dt >= hour) {
    sprintf(buffer, "%3dh", (int)(dt / hour + 0.5));
  } else {
    sprintf(buffer, "%3dm", (int)(dt / 60 + 0.5));
  }
}


x86 assembly (clang, -O0):
<format_relative_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  0xedf(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeca(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1165 <format_relative_time+0x55>
mov    -0x8(%rbp),%rdi
lea    0xecf(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    125c <format_relative_time+0x14c>
movsd  -0x10(%rbp),%xmm0
movsd  0xe9e(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    1198 <format_relative_time+0x88>
mov    -0x8(%rbp),%rdi
lea    0xea1(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1257 <format_relative_time+0x147>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     11d9 <format_relative_time+0xc9>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  0xe5a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1252 <format_relative_time+0x142>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     121a <format_relative_time+0x10a>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xe19(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    124d <format_relative_time+0x13d>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  0xdf5(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xde1(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1252 <format_relative_time+0x142>
jmp    1257 <format_relative_time+0x147>
jmp    125c <format_relative_time+0x14c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_relative_time>:
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    112f <format_relative_time+0x1f>
ucomisd 0xede(%rip),%xmm0
jbe    113a <format_relative_time+0x2a>
movb   $0x0,0x4(%rdi)
movl   $0x202d2d20,(%rdi)
ret
movb   $0x0,0x4(%rdi)
movl   $0x6e6f6f73,(%rdi)
ret
ucomisd 0xec6(%rip),%xmm0
jae    1170 <format_relative_time+0x60>
ucomisd 0xecc(%rip),%xmm0
jae    1192 <format_relative_time+0x82>
divsd  0xeca(%rip),%xmm0
addsd  0xeb2(%rip),%xmm0
cvttsd2si %xmm0,%edx
lea    0xed3(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
divsd  0xe90(%rip),%xmm0
addsd  0xe90(%rip),%xmm0
cvttsd2si %xmm0,%edx
lea    0xea7(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
divsd  0xe7e(%rip),%xmm0
addsd  0xe6e(%rip),%xmm0
cvttsd2si %xmm0,%edx
lea    0xe8a(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"soon\00"
@.str.1 = [5 x i8] c" -- \00"
@.str.2 = [5 x i8] c"%3dd\00"
@.str.3 = [5 x i8] c"%3dh\00"
@.str.4 = [5 x i8] c"%3dm\00"
define void @format_relative_time(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
%5 = alloca double
%6 = alloca double
store i8* %0, i8** %3
store double %1, double* %4
store double 3.600000e+03, double* %5
%7 = load double, double* %5
%8 = fmul double 2.400000e+01, %7
store double %8, double* %6
%9 = load double, double* %4
%10 = fcmp ole double %9, 0.000000e+00
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %56
14: ; preds = %2
%15 = load double, double* %4
%16 = load double, double* %6
%17 = fmul double 9.990000e+02, %16
%18 = fcmp ogt double %15, %17
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %55
22: ; preds = %14
%23 = load double, double* %4
%24 = load double, double* %6
%25 = fcmp oge double %23, %24
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = load i8*, i8** %3
%28 = load double, double* %4
%29 = load double, double* %6
%30 = fdiv double %28, %29
%31 = fadd double %30, 5.000000e-01
%32 = fptosi double %31 to i32
%33 = call i32 (i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %54
34: ; preds = %22
%35 = load double, double* %4
%36 = load double, double* %5
%37 = fcmp oge double %35, %36
br i1 %37, label %38, label %46
38: ; preds = %34
%39 = load i8*, i8** %3
%40 = load double, double* %4
%41 = load double, double* %5
%42 = fdiv double %40, %41
%43 = fadd double %42, 5.000000e-01
%44 = fptosi double %43 to i32
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %44)
br label %53
46: ; preds = %34
%47 = load i8*, i8** %3
%48 = load double, double* %4
%49 = fdiv double %48, 6.000000e+01
%50 = fadd double %49, 5.000000e-01
%51 = fptosi double %50 to i32
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %46, %38
br label %54
54: ; preds = %53, %26
br label %55
55: ; preds = %54, %19
br label %56
56: ; preds = %55, %11
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"soon\00"
@.str.1 = [5 x i8] c" -- \00"
@.str.2 = [5 x i8] c"%3dd\00"
@.str.3 = [5 x i8] c"%3dh\00"
@.str.4 = [5 x i8] c"%3dm\00"
define void @format_relative_time(i8* nocapture writeonly %0, double %1) {
%3 = fcmp ugt double %1, 0.000000e+00
br i1 %3, label %5, label %4
4: ; preds = %2
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %0, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5, i1 false)
br label %27
5: ; preds = %2
%6 = fcmp ogt double %1, 8.631360e+07
br i1 %6, label %7, label %8
7: ; preds = %5
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %0, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 5, i1 false)
br label %27
8: ; preds = %5
%9 = fcmp ult double %1, 8.640000e+04
br i1 %9, label %15, label %10
10: ; preds = %8
%11 = fdiv double %1, 8.640000e+04
%12 = fadd double %11, 5.000000e-01
%13 = fptosi double %12 to i32
%14 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %27
15: ; preds = %8
%16 = fcmp ult double %1, 3.600000e+03
br i1 %16, label %22, label %17
17: ; preds = %15
%18 = fdiv double %1, 3.600000e+03
%19 = fadd double %18, 5.000000e-01
%20 = fptosi double %19 to i32
%21 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %27
22: ; preds = %15
%23 = fdiv double %1, 6.000000e+01
%24 = fadd double %23, 5.000000e-01
%25 = fptosi double %24 to i32
%26 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %7, %17, %22, %10, %4
ret void
}