#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 */
void *atoi(char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strsep(char **, char *);
int /*<<< orphan*/ tvsub(struct timeval *, struct timeval *, struct timeval *);
long elapsed_ms(char *end, char *start) {
  struct timeval delta, end_time, start_time;
  long elapsed_time;
  char end_tmp[20];
  char start_tmp[20];
  char *cursor;
  char *cp;
  strcpy(end_tmp, end);
  cursor = end_tmp;
  cp = (char *)strsep(&cursor, ".");
  end_time.tv_sec = atoi(end_tmp);
  end_time.tv_usec = atoi(cursor);
  strcpy(start_tmp, start);
  cursor = start_tmp;
  cp = (char *)strsep(&cursor, ".");
  start_time.tv_sec = atoi(start_tmp);
  start_time.tv_usec = atoi(cursor);
  tvsub(&delta, &end_time, &start_time);
  elapsed_time = (delta.tv_sec * 1000) + (delta.tv_usec / 1000);
  return (elapsed_time);
}


x86 assembly (clang, -O0):
<elapsed_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x78(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x80(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x78(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x78(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x78(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <tvsub@plt>
imul   $0x3e8,-0x18(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elapsed_ms>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,(%rsp)
lea    0xe97(%rip),%r15
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strsep@plt>
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,0x10(%rsp)
mov    (%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,0x14(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strsep@plt>
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,0x8(%rsp)
mov    (%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,0xc(%rsp)
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1050 <tvsub@plt>
movslq 0x18(%rsp),%rax
imul   $0x3e8,%rax,%rcx
movslq 0x1c(%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rax
add    %edx,%eax
cltq
add    %rcx,%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [2 x i8] c".\00"
define i64 @elapsed_ms(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca i64
%9 = alloca [20 x i8]
%10 = alloca [20 x i8]
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
store i8* %16, i8** %11
%17 = call i64 @strsep(i8** %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %12
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%20 = call i8* @atoi(i8* %19)
%21 = ptrtoint i8* %20 to i32
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
store i32 %21, i32* %22
%23 = load i8*, i8** %11
%24 = call i8* @atoi(i8* %23)
%25 = ptrtoint i8* %24 to i32
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
store i32 %25, i32* %26
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%28 = load i8*, i8** %4
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
store i8* %30, i8** %11
%31 = call i64 @strsep(i8** %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %12
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%34 = call i8* @atoi(i8* %33)
%35 = ptrtoint i8* %34 to i32
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
store i32 %35, i32* %36
%37 = load i8*, i8** %11
%38 = call i8* @atoi(i8* %37)
%39 = ptrtoint i8* %38 to i32
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
store i32 %39, i32* %40
%41 = call i32 @tvsub(%struct.timeval* %5, %struct.timeval* %6, %struct.timeval* %7)
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%43 = load i32, i32* %42
%44 = mul nsw i32 %43, 1000
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%46 = load i32, i32* %45
%47 = sdiv i32 %46, 1000
%48 = add nsw i32 %44, %47
%49 = sext i32 %48 to i64
store i64 %49, i64* %8
%50 = load i64, i64* %8
ret i64 %50
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [2 x i8] c".\00"
define i64 @elapsed_ms(i8* %0, i8* %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca [20 x i8]
%7 = alloca [20 x i8]
%8 = alloca i8*
%9 = bitcast %struct.timeval* %3 to i8*
%10 = bitcast %struct.timeval* %4 to i8*
%11 = bitcast %struct.timeval* %5 to i8*
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%14 = bitcast i8** %8 to i8*
%15 = call i32 @strcpy(i8* %12, i8* %0)
store i8* %12, i8** %8
%16 = call i64 @strsep(i8** %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = call i8* @atoi(i8* %12)
%18 = ptrtoint i8* %17 to i64
%19 = trunc i64 %18 to i32
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 %19, i32* %20
%21 = load i8*, i8** %8
%22 = call i8* @atoi(i8* %21)
%23 = ptrtoint i8* %22 to i64
%24 = trunc i64 %23 to i32
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i32 %24, i32* %25
%26 = call i32 @strcpy(i8* %13, i8* %1)
store i8* %13, i8** %8
%27 = call i64 @strsep(i8** %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = call i8* @atoi(i8* %13)
%29 = ptrtoint i8* %28 to i64
%30 = trunc i64 %29 to i32
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i32 %30, i32* %31
%32 = load i8*, i8** %8
%33 = call i8* @atoi(i8* %32)
%34 = ptrtoint i8* %33 to i64
%35 = trunc i64 %34 to i32
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i32 %35, i32* %36
%37 = call i32 @tvsub(%struct.timeval* %3, %struct.timeval* %4, %struct.timeval* %5)
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%39 = load i32, i32* %38
%40 = mul nsw i32 %39, 1000
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%42 = load i32, i32* %41
%43 = sdiv i32 %42, 1000
%44 = add nsw i32 %43, %40
%45 = sext i32 %44 to i64
ret i64 %45
}