#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 uint32_t;
struct tm {
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct timezone {
  int dummy;
};
struct timeval {
  int tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
struct tm *localtime(int /*<<< orphan*/ *);
uint32_t stampstop(uint32_t start) {
  struct timeval tv;
  struct timezone tz;
  struct tm *tm;
  uint32_t stop;
  gettimeofday(&tv, &tz);
  tm = localtime(&tv.tv_sec);
  stop = tm->tm_hour * 3600 * 1000 + tm->tm_min * 60 * 1000 +
         tm->tm_sec * 1000 + tv.tv_usec / 1000;
  return (stop - start);
}


x86 assembly (clang, -O0):
<stampstop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <gettimeofday@plt>
lea    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
imul   $0xe10,(%rax),%eax
imul   $0x3e8,%eax,%eax
mov    -0x20(%rbp),%rcx
imul   $0x3c,0x4(%rcx),%ecx
imul   $0x3e8,%ecx,%ecx
add    %ecx,%eax
mov    -0x20(%rbp),%rcx
imul   $0x3e8,0x8(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
sub    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stampstop>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1040 <gettimeofday@plt>
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
imul   $0x36ee80,(%rax),%ecx
imul   $0xea60,0x4(%rax),%edx
imul   $0x3e8,0x8(%rax),%eax
movslq (%rsp),%rsi
imul   $0x10624dd3,%rsi,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x26,%rsi
add    %edi,%esi
sub    %ebx,%ecx
add    %edx,%ecx
add    %eax,%ecx
add    %esi,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
%struct.tm = type { i32, i32, i32 }
define i32 @stampstop(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.timezone
%5 = alloca %struct.tm*
%6 = alloca i32
store i32 %0, i32* %2
%7 = call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* %4)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%9 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %9, %struct.tm** %5
%10 = load %struct.tm*, %struct.tm** %5
%11 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = mul nsw i32 %12, 3600
%14 = mul nsw i32 %13, 1000
%15 = load %struct.tm*, %struct.tm** %5
%16 = getelementptr inbounds %struct.tm, %struct.tm* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = mul nsw i32 %17, 60
%19 = mul nsw i32 %18, 1000
%20 = add nsw i32 %14, %19
%21 = load %struct.tm*, %struct.tm** %5
%22 = getelementptr inbounds %struct.tm, %struct.tm* %21, i32 0, i32 2
%23 = load i32, i32* %22
%24 = mul nsw i32 %23, 1000
%25 = add nsw i32 %20, %24
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%27 = load i32, i32* %26
%28 = sdiv i32 %27, 1000
%29 = add nsw i32 %25, %28
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = load i32, i32* %2
%32 = sub nsw i32 %30, %31
ret i32 %32
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
%struct.tm = type { i32, i32, i32 }
define i32 @stampstop(i32 %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timezone
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timezone* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%8 = call %struct.tm* @localtime(i32* %7)
%9 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = mul i32 %10, 3600000
%12 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 1
%13 = load i32, i32* %12
%14 = mul i32 %13, 60000
%15 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 2
%16 = load i32, i32* %15
%17 = mul nsw i32 %16, 1000
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%19 = load i32, i32* %18
%20 = sdiv i32 %19, 1000
%21 = sub i32 %11, %0
%22 = add i32 %21, %14
%23 = add i32 %22, %17
%24 = add i32 %23, %20
ret i32 %24
}