#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 */
typedef int /*<<< orphan*/ time_t;
struct timeval {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ delta_time_in_milliseconds(struct timeval *,
                                              struct timeval *);
int /*<<< orphan*/ sprintf(char *, char *, int, ...);
int time_day(int /*<<< orphan*/);
int time_hour(int /*<<< orphan*/);
int time_min(int /*<<< orphan*/);
int time_msec(int /*<<< orphan*/);
int time_sec(int /*<<< orphan*/);
int /*<<< orphan*/ time_usec(int /*<<< orphan*/);
char *elapsed_time(struct timeval *start, struct timeval *stop) {
  static char et[64];
  time_t elapsed = delta_time_in_milliseconds(stop, start);
  if (time_day(elapsed))
    sprintf(et, "%d days, %02d:%02d:%02d.%03ld", time_day(elapsed),
            time_hour(elapsed), time_min(elapsed), time_sec(elapsed),
            time_usec(elapsed));
  else if (time_hour(elapsed))
    sprintf(et, "%02d:%02d:%02d.%03ld", time_hour(elapsed), time_min(elapsed),
            time_sec(elapsed), time_usec(elapsed));
  else if (time_min(elapsed))
    sprintf(et, "%02d:%02d.%03ld", time_min(elapsed), time_sec(elapsed),
            time_usec(elapsed));
  else if (time_sec(elapsed))
    sprintf(et, "%d.%03d secs", time_sec(elapsed), time_msec(elapsed));
  else
    sprintf(et, "%3d msecs", time_msec(elapsed));
  return et;
}


x86 assembly (clang, -O0):
<elapsed_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <delta_time_in_milliseconds@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <time_day@plt>
cmp    $0x0,%eax
je     1210 <elapsed_time+0x90>
mov    -0x14(%rbp),%edi
call   1080 <time_day@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <time_hour@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <time_min@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <time_sec@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1090 <time_usec@plt>
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x18(%rbp),%r9d
lea    0x2e76(%rip),%rdi
lea    0xdff(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   10a0 <sprintf@plt>
jmp    1334 <elapsed_time+0x1b4>
mov    -0x14(%rbp),%edi
call   1030 <time_hour@plt>
cmp    $0x0,%eax
je     1271 <elapsed_time+0xf1>
mov    -0x14(%rbp),%edi
call   1030 <time_hour@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <time_min@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <time_sec@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1090 <time_usec@plt>
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    %eax,%r9d
lea    0x2e12(%rip),%rdi
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
jmp    132f <elapsed_time+0x1af>
mov    -0x14(%rbp),%edi
call   1070 <time_min@plt>
cmp    $0x0,%eax
je     12c3 <elapsed_time+0x143>
mov    -0x14(%rbp),%edi
call   1070 <time_min@plt>
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <time_sec@plt>
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%edi
call   1090 <time_usec@plt>
mov    -0x38(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    %eax,%r8d
lea    0x2dc0(%rip),%rdi
lea    0xd57(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
jmp    132a <elapsed_time+0x1aa>
mov    -0x14(%rbp),%edi
call   1040 <time_sec@plt>
cmp    $0x0,%eax
je     1306 <elapsed_time+0x186>
mov    -0x14(%rbp),%edi
call   1040 <time_sec@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <time_msec@plt>
mov    -0x3c(%rbp),%edx
mov    %eax,%ecx
lea    0x2d7d(%rip),%rdi
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
jmp    1325 <elapsed_time+0x1a5>
mov    -0x14(%rbp),%edi
call   1060 <time_msec@plt>
mov    %eax,%edx
lea    0x2d59(%rip),%rdi
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
jmp    132a <elapsed_time+0x1aa>
jmp    132f <elapsed_time+0x1af>
jmp    1334 <elapsed_time+0x1b4>
lea    0x2d35(%rip),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elapsed_time>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1050 <delta_time_in_milliseconds@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1080 <time_day@plt>
mov    %ebx,%edi
test   %eax,%eax
je     11f4 <elapsed_time+0x74>
call   1080 <time_day@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1030 <time_hour@plt>
mov    %eax,%r15d
mov    %ebx,%edi
call   1070 <time_min@plt>
mov    %eax,%r12d
mov    %ebx,%edi
call   1040 <time_sec@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1090 <time_usec@plt>
mov    %eax,(%rsp)
lea    0x2e91(%rip),%rdi
lea    0xe1a(%rip),%rsi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %ebp,%r9d
jmp    123b <elapsed_time+0xbb>
call   1030 <time_hour@plt>
mov    %ebx,%edi
test   %eax,%eax
je     1256 <elapsed_time+0xd6>
call   1030 <time_hour@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1070 <time_min@plt>
mov    %eax,%r15d
mov    %ebx,%edi
call   1040 <time_sec@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1090 <time_usec@plt>
lea    0x2e48(%rip),%rdi
lea    0xdda(%rip),%rsi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   10a0 <sprintf@plt>
lea    0x2e27(%rip),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
call   1070 <time_min@plt>
mov    %ebx,%edi
test   %eax,%eax
je     1298 <elapsed_time+0x118>
call   1070 <time_min@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1040 <time_sec@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1090 <time_usec@plt>
lea    0x2df0(%rip),%rdi
lea    0xd87(%rip),%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   10a0 <sprintf@plt>
jmp    1242 <elapsed_time+0xc2>
call   1040 <time_sec@plt>
test   %eax,%eax
je     12cf <elapsed_time+0x14f>
mov    %ebx,%edi
call   1040 <time_sec@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1060 <time_msec@plt>
lea    0x2db8(%rip),%rdi
lea    0xd5f(%rip),%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   10a0 <sprintf@plt>
jmp    1242 <elapsed_time+0xc2>
mov    %ebx,%edi
call   1060 <time_msec@plt>
lea    0x2d93(%rip),%rdi
lea    0xd47(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <sprintf@plt>
jmp    1242 <elapsed_time+0xc2>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@elapsed_time.et = internal global [64 x i8] zeroinitializer
@.str = [30 x i8] c"%d days, %02d:%02d:%02d.%03ld\00"
@.str.1 = [21 x i8] c"%02d:%02d:%02d.%03ld\00"
@.str.2 = [16 x i8] c"%02d:%02d.%03ld\00"
@.str.3 = [13 x i8] c"%d.%03d secs\00"
@.str.4 = [10 x i8] c"%3d msecs\00"
define i8* @elapsed_time(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca i32
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%6 = load %struct.timeval*, %struct.timeval** %4
%7 = load %struct.timeval*, %struct.timeval** %3
%8 = call i32 @delta_time_in_milliseconds(%struct.timeval* %6, %struct.timeval* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = call i32 @time_day(i32 %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %2
%13 = load i32, i32* %5
%14 = call i32 @time_day(i32 %13)
%15 = load i32, i32* %5
%16 = call i32 @time_hour(i32 %15)
%17 = load i32, i32* %5
%18 = call i32 @time_min(i32 %17)
%19 = load i32, i32* %5
%20 = call i32 @time_sec(i32 %19)
%21 = load i32, i32* %5
%22 = call i32 @time_usec(i32 %21)
%23 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @elapsed_time.et, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %16, i32 %18, i32 %20, i32 %22)
br label %67
24: ; preds = %2
%25 = load i32, i32* %5
%26 = call i32 @time_hour(i32 %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = load i32, i32* %5
%30 = call i32 @time_hour(i32 %29)
%31 = load i32, i32* %5
%32 = call i32 @time_min(i32 %31)
%33 = load i32, i32* %5
%34 = call i32 @time_sec(i32 %33)
%35 = load i32, i32* %5
%36 = call i32 @time_usec(i32 %35)
%37 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @elapsed_time.et, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %32, i32 %34, i32 %36)
br label %66
38: ; preds = %24
%39 = load i32, i32* %5
%40 = call i32 @time_min(i32 %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %50
42: ; preds = %38
%43 = load i32, i32* %5
%44 = call i32 @time_min(i32 %43)
%45 = load i32, i32* %5
%46 = call i32 @time_sec(i32 %45)
%47 = load i32, i32* %5
%48 = call i32 @time_usec(i32 %47)
%49 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @elapsed_time.et, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %44, i32 %46, i32 %48)
br label %65
50: ; preds = %38
%51 = load i32, i32* %5
%52 = call i32 @time_sec(i32 %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %50
%55 = load i32, i32* %5
%56 = call i32 @time_sec(i32 %55)
%57 = load i32, i32* %5
%58 = call i32 @time_msec(i32 %57)
%59 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @elapsed_time.et, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %56, i32 %58)
br label %64
60: ; preds = %50
%61 = load i32, i32* %5
%62 = call i32 @time_msec(i32 %61)
%63 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @elapsed_time.et, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %62)
br label %64
64: ; preds = %60, %54
br label %65
65: ; preds = %64, %42
br label %66
66: ; preds = %65, %28
br label %67
67: ; preds = %66, %12
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @elapsed_time.et, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@elapsed_time.et = internal global [64 x i8] zeroinitializer
@.str = [30 x i8] c"%d days, %02d:%02d:%02d.%03ld\00"
@.str.1 = [21 x i8] c"%02d:%02d:%02d.%03ld\00"
@.str.2 = [16 x i8] c"%02d:%02d.%03ld\00"
@.str.3 = [13 x i8] c"%d.%03d secs\00"
@.str.4 = [10 x i8] c"%3d msecs\00"
define i8* @elapsed_time(%struct.timeval* %0, %struct.timeval* %1) {
%3 = tail call i32 @delta_time_in_milliseconds(%struct.timeval* %1, %struct.timeval* %0)
%4 = tail call i32 @time_day(i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = tail call i32 @time_day(i32 %3)
%8 = tail call i32 @time_hour(i32 %3)
%9 = tail call i32 @time_min(i32 %3)
%10 = tail call i32 @time_sec(i32 %3)
%11 = tail call i32 @time_usec(i32 %3)
%12 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @elapsed_time.et, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8, i32 %9, i32 %10, i32 %11)
br label %40
13: ; preds = %2
%14 = tail call i32 @time_hour(i32 %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = tail call i32 @time_hour(i32 %3)
%18 = tail call i32 @time_min(i32 %3)
%19 = tail call i32 @time_sec(i32 %3)
%20 = tail call i32 @time_usec(i32 %3)
%21 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @elapsed_time.et, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18, i32 %19, i32 %20)
br label %40
22: ; preds = %13
%23 = tail call i32 @time_min(i32 %3)
%24 = icmp eq i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %22
%26 = tail call i32 @time_min(i32 %3)
%27 = tail call i32 @time_sec(i32 %3)
%28 = tail call i32 @time_usec(i32 %3)
%29 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @elapsed_time.et, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %27, i32 %28)
br label %40
30: ; preds = %22
%31 = tail call i32 @time_sec(i32 %3)
%32 = icmp eq i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = tail call i32 @time_sec(i32 %3)
%35 = tail call i32 @time_msec(i32 %3)
%36 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @elapsed_time.et, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %35)
br label %40
37: ; preds = %30
%38 = tail call i32 @time_msec(i32 %3)
%39 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @elapsed_time.et, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %16, %33, %37, %25, %6
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @elapsed_time.et, i64 0, i64 0)
}