#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 time_t;
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
time_t SARGetCurMilliTime(void) {
  struct timeval tv[1];
  if (gettimeofday(tv, NULL) < 0)
    return (-1);
  return (((tv->tv_sec % 86400) * 1000) + (tv->tv_usec / 1000));
}


x86 assembly (clang, -O0):
<SARGetCurMilliTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
jge    113b <SARGetCurMilliTime+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1164 <SARGetCurMilliTime+0x54>
mov    -0x10(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SARGetCurMilliTime>:
push   %rax
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
js     1166 <SARGetCurMilliTime+0x56>
movslq (%rsp),%rax
imul   $0xffffffffc22e4507,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x10,%ecx
add    %edx,%ecx
imul   $0x15180,%ecx,%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
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i32 @SARGetCurMilliTime() {
%1 = alloca i32
%2 = alloca [1 x %struct.timeval]
%3 = getelementptr inbounds [1 x %struct.timeval], [1 x %struct.timeval]* %2, i64 0, i64 0
%4 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 -1, i32* %1
br label %18
7: ; preds = %0
%8 = getelementptr inbounds [1 x %struct.timeval], [1 x %struct.timeval]* %2, i64 0, i64 0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = srem i32 %10, 86400
%12 = mul nsw i32 %11, 1000
%13 = getelementptr inbounds [1 x %struct.timeval], [1 x %struct.timeval]* %2, i64 0, i64 0
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = sdiv i32 %15, 1000
%17 = add nsw i32 %12, %16
store i32 %17, i32* %1
br label %18
18: ; preds = %7, %6
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i32 @SARGetCurMilliTime() {
%1 = alloca [1 x %struct.timeval]
%2 = bitcast [1 x %struct.timeval]* %1 to i8*
%3 = getelementptr inbounds [1 x %struct.timeval], [1 x %struct.timeval]* %1, i64 0, i64 0
%4 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%5 = icmp slt i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %0
%7 = getelementptr inbounds [1 x %struct.timeval], [1 x %struct.timeval]* %1, i64 0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = srem i32 %8, 86400
%10 = mul nsw i32 %9, 1000
%11 = getelementptr inbounds [1 x %struct.timeval], [1 x %struct.timeval]* %1, i64 0, i64 0, i32 1
%12 = load i32, i32* %11
%13 = sdiv i32 %12, 1000
%14 = add nsw i32 %10, %13
br label %15
15: ; preds = %0, %6
%16 = phi i32 [ %14, %6 ], [ -1, %0 ]
ret i32 %16
}