#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 FRGL_TimeMS() {
  struct timeval tp;
  static int secbase;
  gettimeofday(&tp, NULL);
  if (!secbase)
    secbase = tp.tv_sec;
  return (((tp.tv_sec - secbase) * 1000) + tp.tv_usec / 1000);
}


x86 assembly (clang, -O0):
<FRGL_TimeMS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmpl   $0x0,0x2f00(%rip)
jne    113b <FRGL_TimeMS+0x2b>
mov    -0x8(%rbp),%eax
mov    %eax,0x2ef1(%rip)
mov    -0x8(%rbp),%eax
sub    0x2ee8(%rip),%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FRGL_TimeMS>:
push   %rax
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2f0b(%rip),%ecx
mov    (%rsp),%eax
test   %ecx,%ecx
jne    1130 <FRGL_TimeMS+0x20>
mov    %eax,0x2efe(%rip)
mov    %eax,%ecx
sub    %ecx,%eax
imul   $0x3e8,%eax,%ecx
movslq 0x4(%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rax
add    %edx,%eax
add    %ecx,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@FRGL_TimeMS.secbase = internal unnamed_addr global i32 0
define i32 @FRGL_TimeMS() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = load i32, i32* @FRGL_TimeMS.secbase
%5 = icmp eq i32 %4, 0
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%7 = load i32, i32* %6
br i1 %5, label %8, label %9
8: ; preds = %0
store i32 %7, i32* @FRGL_TimeMS.secbase
br label %9
9: ; preds = %0, %8
%10 = phi i32 [ %7, %8 ], [ %4, %0 ]
%11 = sub nsw i32 %7, %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 = sdiv i32 %14, 1000
%16 = add nsw i32 %12, %15
ret i32 %16
}