#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*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
long MQTTClient_elapsed(struct timeval start) {
  struct timeval now, res;
  gettimeofday(&now, NULL);
  timersub(&now, &start, &res);
  return (res.tv_sec) * 1000 + (res.tv_usec) / 1000;
}


x86 assembly (clang, -O0):
<MQTTClient_elapsed>:
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>
lea    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <timersub@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
cltq
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i64 @MQTTClient_elapsed(i64 %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %2 to i64*
store i64 %0, i64* %5
%6 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%7 = call i32 @timersub(%struct.timeval* %3, %struct.timeval* %2, %struct.timeval* %4)
%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
%15 = sext i32 %14 to i64
ret i64 %15
}

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