#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 timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, double, ...);
const char *tv_to_str(const struct timeval *tv) {
  static char buf[sizeof("111.111 minutes")];
  if (tv->tv_sec >= 86400)
    return "> 1 day";
  else if (tv->tv_sec >= 3600)
    sprintf(buf, "%3.3f hours", (double)tv->tv_sec / 3600);
  else if (tv->tv_sec >= 60)
    sprintf(buf, "%3.3f minutes", (double)tv->tv_sec / 60);
  else if (tv->tv_sec > 0)
    sprintf(buf, "%ld.%03ld s", tv->tv_sec, tv->tv_usec / 1000);
  else if (tv->tv_usec > 1000)
    sprintf(buf, "%ld.%03ld ms", tv->tv_usec / 1000, tv->tv_usec % 1000);
  else
    sprintf(buf, "%ld us", tv->tv_usec);
  return buf;
}


x86 assembly (clang, -O0):
<tv_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x15180,(%rax)
jl     113c <tv_to_str+0x2c>
lea    0xedd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    127f <tv_to_str+0x16f>
mov    -0x10(%rbp),%rax
cmpl   $0xe10,(%rax)
jl     117a <tv_to_str+0x6a>
mov    -0x10(%rbp),%rax
cvtsi2sdl (%rax),%xmm0
movsd  0xeac(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2ed9(%rip),%rdi
lea    0xeaa(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    126f <tv_to_str+0x15f>
mov    -0x10(%rbp),%rax
cmpl   $0x3c,(%rax)
jl     11b5 <tv_to_str+0xa5>
mov    -0x10(%rbp),%rax
cvtsi2sdl (%rax),%xmm0
movsd  0xe69(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2e9e(%rip),%rdi
lea    0xe7b(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    126a <tv_to_str+0x15a>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11f5 <tv_to_str+0xe5>
mov    -0x10(%rbp),%rax
cvtsi2sdl (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0x2e5e(%rip),%rdi
lea    0xe49(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    1265 <tv_to_str+0x155>
mov    -0x10(%rbp),%rax
cmpl   $0x3e8,0x4(%rax)
jle    1242 <tv_to_str+0x132>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
lea    0x2e11(%rip),%rdi
lea    0xe08(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    1260 <tv_to_str+0x150>
mov    -0x10(%rbp),%rax
cvtsi2sdl 0x4(%rax),%xmm0
lea    0x2dee(%rip),%rdi
lea    0xdf2(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    1265 <tv_to_str+0x155>
jmp    126a <tv_to_str+0x15a>
jmp    126f <tv_to_str+0x15f>
jmp    1274 <tv_to_str+0x164>
lea    0x2dc5(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tv_to_str>:
push   %rbx
mov    (%rdi),%eax
cmp    $0x1517f,%eax
jle    1126 <tv_to_str+0x16>
lea    0xeef(%rip),%rbx
jmp    11e3 <tv_to_str+0xd3>
cmp    $0xe10,%eax
jl     1149 <tv_to_str+0x39>
cvtsi2sd %eax,%xmm0
divsd  0xecf(%rip),%xmm0
lea    0x2f00(%rip),%rbx
lea    0xed1(%rip),%rsi
jmp    1168 <tv_to_str+0x58>
cmp    $0x3c,%eax
jl     1174 <tv_to_str+0x64>
cvtsi2sd %eax,%xmm0
divsd  0xea6(%rip),%xmm0
lea    0x2edf(%rip),%rbx
lea    0xebc(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    11e3 <tv_to_str+0xd3>
test   %eax,%eax
jle    11a7 <tv_to_str+0x97>
cvtsi2sd %eax,%xmm0
movslq 0x4(%rdi),%rax
imul   $0x10624dd3,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x26,%rdx
add    %eax,%edx
lea    0x2ea5(%rip),%rbx
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
jmp    11dc <tv_to_str+0xcc>
mov    0x4(%rdi),%edx
cmp    $0x3e9,%edx
jl     11e8 <tv_to_str+0xd8>
mov    %edx,%eax
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
cvtsi2sd %eax,%xmm0
imul   $0x3e8,%eax,%eax
sub    %eax,%edx
lea    0x2e6e(%rip),%rbx
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%al
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret
cvtsi2sd %edx,%xmm0
lea    0x2e4d(%rip),%rbx
lea    0xe51(%rip),%rsi
jmp    1168 <tv_to_str+0x58>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@tv_to_str.buf = internal global [16 x i8] zeroinitializer
@.str = [8 x i8] c"> 1 day\00"
@.str.1 = [12 x i8] c"%3.3f hours\00"
@.str.2 = [14 x i8] c"%3.3f minutes\00"
@.str.3 = [12 x i8] c"%ld.%03ld s\00"
@.str.4 = [13 x i8] c"%ld.%03ld ms\00"
@.str.5 = [7 x i8] c"%ld us\00"
define i8* @tv_to_str(%struct.timeval* %0) {
%2 = alloca i8*
%3 = alloca %struct.timeval*
store %struct.timeval* %0, %struct.timeval** %3
%4 = load %struct.timeval*, %struct.timeval** %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%6 = load i32, i32* %5
%7 = icmp sge i32 %6, 86400
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %2
br label %75
9: ; preds = %1
%10 = load %struct.timeval*, %struct.timeval** %3
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = icmp sge i32 %12, 3600
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = load %struct.timeval*, %struct.timeval** %3
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = sitofp i32 %17 to double
%19 = fdiv double %18, 3.600000e+03
%20 = call i32 (i8*, i8*, double, ...) @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %19)
br label %73
21: ; preds = %9
%22 = load %struct.timeval*, %struct.timeval** %3
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = icmp sge i32 %24, 60
br i1 %25, label %26, label %33
26: ; preds = %21
%27 = load %struct.timeval*, %struct.timeval** %3
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = sitofp i32 %29 to double
%31 = fdiv double %30, 6.000000e+01
%32 = call i32 (i8*, i8*, double, ...) @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %31)
br label %72
33: ; preds = %21
%34 = load %struct.timeval*, %struct.timeval** %3
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %33
%39 = load %struct.timeval*, %struct.timeval** %3
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = sitofp i32 %41 to double
%43 = load %struct.timeval*, %struct.timeval** %3
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %43, i32 0, i32 1
%45 = load i32, i32* %44
%46 = sdiv i32 %45, 1000
%47 = call i32 (i8*, i8*, double, ...) @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), double %42, i32 %46)
br label %71
48: ; preds = %33
%49 = load %struct.timeval*, %struct.timeval** %3
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %49, i32 0, i32 1
%51 = load i32, i32* %50
%52 = icmp sgt i32 %51, 1000
br i1 %52, label %53, label %64
53: ; preds = %48
%54 = load %struct.timeval*, %struct.timeval** %3
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %54, i32 0, i32 1
%56 = load i32, i32* %55
%57 = sdiv i32 %56, 1000
%58 = sitofp i32 %57 to double
%59 = load %struct.timeval*, %struct.timeval** %3
%60 = getelementptr inbounds %struct.timeval, %struct.timeval* %59, i32 0, i32 1
%61 = load i32, i32* %60
%62 = srem i32 %61, 1000
%63 = call i32 (i8*, i8*, double, ...) @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), double %58, i32 %62)
br label %70
64: ; preds = %48
%65 = load %struct.timeval*, %struct.timeval** %3
%66 = getelementptr inbounds %struct.timeval, %struct.timeval* %65, i32 0, i32 1
%67 = load i32, i32* %66
%68 = sitofp i32 %67 to double
%69 = call i32 (i8*, i8*, double, ...) @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double %68)
br label %70
70: ; preds = %64, %53
br label %71
71: ; preds = %70, %38
br label %72
72: ; preds = %71, %26
br label %73
73: ; preds = %72, %14
br label %74
74: ; preds = %73
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), i8** %2
br label %75
75: ; preds = %74, %8
%76 = load i8*, i8** %2
ret i8* %76
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@tv_to_str.buf = internal global [16 x i8] zeroinitializer
@.str = [8 x i8] c"> 1 day\00"
@.str.1 = [12 x i8] c"%3.3f hours\00"
@.str.2 = [14 x i8] c"%3.3f minutes\00"
@.str.3 = [12 x i8] c"%ld.%03ld s\00"
@.str.4 = [13 x i8] c"%ld.%03ld ms\00"
@.str.5 = [7 x i8] c"%ld us\00"
define i8* @tv_to_str(%struct.timeval* nocapture %0) {
%2 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = icmp sgt i32 %3, 86399
br i1 %4, label %37, label %5
5: ; preds = %1
%6 = icmp sgt i32 %3, 3599
br i1 %6, label %7, label %11
7: ; preds = %5
%8 = sitofp i32 %3 to double
%9 = fdiv double %8, 3.600000e+03
%10 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %9)
br label %37
11: ; preds = %5
%12 = icmp sgt i32 %3, 59
br i1 %12, label %13, label %17
13: ; preds = %11
%14 = sitofp i32 %3 to double
%15 = fdiv double %14, 6.000000e+01
%16 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %15)
br label %37
17: ; preds = %11
%18 = icmp sgt i32 %3, 0
br i1 %18, label %19, label %25
19: ; preds = %17
%20 = sitofp i32 %3 to double
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%22 = load i32, i32* %21
%23 = sdiv i32 %22, 1000
%24 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), double %20, i32 %23)
br label %37
25: ; preds = %17
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%27 = load i32, i32* %26
%28 = icmp sgt i32 %27, 1000
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = udiv i32 %27, 1000
%31 = sitofp i32 %30 to double
%32 = urem i32 %27, 1000
%33 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), double %31, i32 %32)
br label %37
34: ; preds = %25
%35 = sitofp i32 %27 to double
%36 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double %35)
br label %37
37: ; preds = %13, %29, %34, %19, %7, %1
%38 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), %7 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), %19 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), %34 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), %29 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @tv_to_str.buf, i64 0, i64 0), %13 ]
ret i8* %38
}