#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;
};
typedef int /*<<< orphan*/ clock_t;

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ timeval_subtract(struct timeval *, struct timeval *,
                                    struct timeval *);
clock_t timerLap(struct timeval *ti) {
  struct timeval lap;
  struct timeval dif;
  gettimeofday(&lap, NULL);
  timeval_subtract(&dif, ti, &lap);
  return (clock_t)(dif.tv_sec * 1000 + (dif.tv_usec / 1000));
}


x86 assembly (clang, -O0):
<timerLap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%rsi
lea    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rdx
call   1040 <timeval_subtract@plt>
imul   $0x3e8,-0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timerLap>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <timeval_subtract@plt>
imul   $0x3e8,0x8(%rsp),%ecx
movslq 0xc(%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rax
add    %edx,%eax
add    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i32 @timerLap(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %2
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = load %struct.timeval*, %struct.timeval** %2
%7 = call i32 @timeval_subtract(%struct.timeval* %4, %struct.timeval* %6, %struct.timeval* %3)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%9 = load i32, i32* %8
%10 = mul nsw i32 %9, 1000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%12 = load i32, i32* %11
%13 = sdiv i32 %12, 1000
%14 = add nsw i32 %10, %13
ret i32 %14
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i32 @timerLap(%struct.timeval* %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timeval* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%7 = call i32 @timeval_subtract(%struct.timeval* %3, %struct.timeval* %0, %struct.timeval* %2)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = mul nsw i32 %9, 1000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%12 = load i32, i32* %11
%13 = sdiv i32 %12, 1000
%14 = add nsw i32 %13, %10
ret i32 %14
}