#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*/ *);
int /*<<< orphan*/ printf(char *, int, ...);
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;
  printf("TIMESTAMP-END\t  %d:%02d:%02d:%d (~%d ms) \n", tm->tm_hour,
         tm->tm_min, tm->tm_sec, tv.tv_usec,
         tm->tm_hour * 3600 * 1000 + tm->tm_min * 60 * 1000 +
             tm->tm_sec * 1000 + tv.tv_usec / 1000);
  printf("ELAPSED\t  %d ms\n", stop - start);
  return (stop);
}


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   1050 <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,-0x2c(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x10(%rbp),%r8d
mov    -0x20(%rbp),%rax
imul   $0xe10,(%rax),%eax
imul   $0x3e8,%eax,%r9d
mov    -0x20(%rbp),%rax
imul   $0x3c,0x4(%rax),%eax
imul   $0x3e8,%eax,%eax
add    %eax,%r9d
mov    -0x20(%rbp),%rax
imul   $0x3e8,0x8(%rax),%eax
add    %eax,%r9d
mov    -0x10(%rbp),%eax
mov    $0x3e8,%edi
cltd
idiv   %edi
mov    -0x28(%rbp),%edx
add    %eax,%r9d
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
sub    -0x4(%rbp),%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
%struct.tm = type { i32, i32, i32 }
@.str = [43 x i8] c"TIMESTAMP-END\09 %d:%02d:%02d:%d (~%d ms) \0A\00"
@.str.1 = [17 x i8] c"ELAPSED\09 %d ms\0A\00"
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 %struct.tm*, %struct.tm** %5
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = load %struct.tm*, %struct.tm** %5
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = load %struct.tm*, %struct.tm** %5
%37 = getelementptr inbounds %struct.tm, %struct.tm* %36, i32 0, i32 2
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%40 = load i32, i32* %39
%41 = load %struct.tm*, %struct.tm** %5
%42 = getelementptr inbounds %struct.tm, %struct.tm* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = mul nsw i32 %43, 3600
%45 = mul nsw i32 %44, 1000
%46 = load %struct.tm*, %struct.tm** %5
%47 = getelementptr inbounds %struct.tm, %struct.tm* %46, i32 0, i32 1
%48 = load i32, i32* %47
%49 = mul nsw i32 %48, 60
%50 = mul nsw i32 %49, 1000
%51 = add nsw i32 %45, %50
%52 = load %struct.tm*, %struct.tm** %5
%53 = getelementptr inbounds %struct.tm, %struct.tm* %52, i32 0, i32 2
%54 = load i32, i32* %53
%55 = mul nsw i32 %54, 1000
%56 = add nsw i32 %51, %55
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%58 = load i32, i32* %57
%59 = sdiv i32 %58, 1000
%60 = add nsw i32 %56, %59
%61 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %32, i32 %35, i32 %38, i32 %40, i32 %60)
%62 = load i32, i32* %6
%63 = load i32, i32* %2
%64 = sub nsw i32 %62, %63
%65 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %64)
%66 = load i32, i32* %6
ret i32 %66
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
%struct.tm = type { i32, i32, i32 }
@.str = [43 x i8] c"TIMESTAMP-END\09 %d:%02d:%02d:%d (~%d ms) \0A\00"
@.str.1 = [17 x i8] c"ELAPSED\09 %d ms\0A\00"
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 = add nsw i32 %14, %11
%16 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 2
%17 = load i32, i32* %16
%18 = mul nsw i32 %17, 1000
%19 = add nsw i32 %15, %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%21 = load i32, i32* %20
%22 = sdiv i32 %21, 1000
%23 = add nsw i32 %19, %22
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %13, i32 %17, i32 %21, i32 %23)
%25 = sub nsw i32 %23, %0
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %25)
ret i32 %23
}