#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*/);
long proc_ms(void) {
  struct timeval t;
  static int init = 0;
  static struct timeval s;
  if (!init) {
    gettimeofday(&s, 0);
    init = 1;
  }
  gettimeofday(&t, 0);
  return (t.tv_sec - s.tv_sec) * 1000 + (t.tv_usec - s.tv_usec) / 1000;
}


x86 assembly (clang, -O0):
<proc_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x0,0x2f0d(%rip)
jne    113d <proc_ms+0x2d>
lea    0x2f04(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movl   $0x1,0x2eef(%rip)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%eax
sub    0x2edf(%rip),%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sub    0x2ed1(%rip),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
cltq
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_ms>:
push   %rax
cmpb   $0x0,0x2f14(%rip)
jne    112f <proc_ms+0x1f>
lea    0x2f0f(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movb   $0x1,0x2efd(%rip)
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
sub    0x2eea(%rip),%eax
sub    0x2ee8(%rip),%ecx
imul   $0x3e8,%eax,%eax
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
add    %eax,%ecx
movslq %ecx,%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@proc_ms.init = internal global i32 0
@proc_ms.s = internal global %struct.timeval zeroinitializer
define i64 @proc_ms() {
%1 = alloca %struct.timeval
%2 = load i32, i32* @proc_ms.init
%3 = icmp ne i32 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = call i32 @gettimeofday(%struct.timeval* @proc_ms.s, i32 0)
store i32 1, i32* @proc_ms.init
br label %6
6: ; preds = %4, %0
%7 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%9 = load i32, i32* %8
%10 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @proc_ms.s, i32 0, i32 0)
%11 = sub nsw i32 %9, %10
%12 = mul nsw i32 %11, 1000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%14 = load i32, i32* %13
%15 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @proc_ms.s, i32 0, i32 1)
%16 = sub nsw i32 %14, %15
%17 = sdiv i32 %16, 1000
%18 = add nsw i32 %12, %17
%19 = sext i32 %18 to i64
ret i64 %19
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@proc_ms.init = internal unnamed_addr global i1 false
@proc_ms.s = internal global %struct.timeval zeroinitializer
define i64 @proc_ms() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = load i1, i1* @proc_ms.init
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = tail call i32 @gettimeofday(%struct.timeval* @proc_ms.s, i32 0)
store i1 true, i1* @proc_ms.init
br label %6
6: ; preds = %4, %0
%7 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @proc_ms.s, i64 0, i32 0)
%11 = sub nsw i32 %9, %10
%12 = mul nsw i32 %11, 1000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%14 = load i32, i32* %13
%15 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @proc_ms.s, i64 0, i32 1)
%16 = sub nsw i32 %14, %15
%17 = sdiv i32 %16, 1000
%18 = add nsw i32 %17, %12
%19 = sext i32 %18 to i64
ret i64 %19
}