#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 {
  scalar_t__ tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
unsigned int get_msec(void) {
  struct timeval tv;
  static struct timeval tv0;
  gettimeofday(&tv, 0);
  if (tv0.tv_sec == 0 && tv0.tv_usec == 0) {
    tv0 = tv;
    return 0;
  }
  return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000;
}


x86 assembly (clang, -O0):
<get_msec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
cmpq   $0x0,0x2f05(%rip)
jne    1161 <get_msec+0x51>
cmpq   $0x0,0x2eff(%rip)
jne    1161 <get_msec+0x51>
mov    -0x18(%rbp),%rax
mov    %rax,0x2ee6(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,0x2ee3(%rip)
movl   $0x0,-0x4(%rbp)
jmp    1199 <get_msec+0x89>
mov    -0x18(%rbp),%rax
sub    0x2ec4(%rip),%rax
imul   $0x3e8,%rax,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
sub    0x2eb6(%rip),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_msec>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2f08(%rip),%rax
mov    0x2f09(%rip),%rcx
mov    %rax,%rdx
or     %rcx,%rdx
jne    1144 <get_msec+0x34>
movups (%rsp),%xmm0
movups %xmm0,0x2eee(%rip)
jmp    1176 <get_msec+0x66>
mov    (%rsp),%edx
sub    %eax,%edx
imul   $0x3e8,%edx,%esi
mov    0x8(%rsp),%rax
sub    %rcx,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
imul   %rcx
mov    %rdx,%rbx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x7,%rbx
add    %eax,%ebx
add    %esi,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@get_msec.tv0 = internal global %struct.timeval zeroinitializer
define i32 @get_msec() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%4 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @get_msec.tv0, i32 0, i32 0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @get_msec.tv0, i32 0, i32 1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = bitcast %struct.timeval* %2 to i8*
store i32 0, i32* %1
br label %24
11: ; preds = %6, %0
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%13 = load i64, i64* %12
%14 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @get_msec.tv0, i32 0, i32 0)
%15 = sub nsw i64 %13, %14
%16 = mul nsw i64 %15, 1000
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%18 = load i64, i64* %17
%19 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @get_msec.tv0, i32 0, i32 1)
%20 = sub nsw i64 %18, %19
%21 = sdiv i64 %20, 1000
%22 = add nsw i64 %16, %21
%23 = trunc i64 %22 to i32
store i32 %23, i32* %1
br label %24
24: ; preds = %11, %9
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@get_msec.tv0 = internal unnamed_addr global %struct.timeval zeroinitializer
define i32 @get_msec() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%4 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @get_msec.tv0, i64 0, i32 0)
%5 = icmp eq i64 %4, 0
%6 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @get_msec.tv0, i64 0, i32 1)
%7 = icmp eq i64 %6, 0
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %10
9: ; preds = %0
br label %21
10: ; preds = %0
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%12 = load i64, i64* %11
%13 = sub nsw i64 %12, %4
%14 = mul nsw i64 %13, 1000
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%16 = load i64, i64* %15
%17 = sub nsw i64 %16, %6
%18 = sdiv i64 %17, 1000
%19 = add nsw i64 %18, %14
%20 = trunc i64 %19 to i32
br label %21
21: ; preds = %10, %9
%22 = phi i32 [ 0, %9 ], [ %20, %10 ]
ret i32 %22
}