#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*/ LOG_ERR;
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ interval_wait(int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, long);
int main() {
  while (1) {
    interval_wait(1000);
    struct timeval tp;
    gettimeofday(&tp, NULL);
    long int ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
    syslog(LOG_ERR, "%lu", ms);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3e8,%edi
call   1050 <interval_wait@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
imul   $0x3e8,-0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cltq
mov    %rax,-0x18(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe71(%rip),%rsi
call   1040 <syslog@plt>
jmp    113f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%r14
mov    0x2e93(%rip),%r15
lea    0xeb4(%rip),%rbx
nopl   0x0(%rax)
mov    $0x3e8,%edi
call   1050 <interval_wait@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movslq 0x8(%rsp),%rax
imul   $0x3e8,%rax,%rax
movslq 0xc(%rsp),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
movslq %ecx,%rdx
add    %rax,%rdx
mov    (%r15),%edi
mov    %rbx,%rsi
call   1040 <syslog@plt>
jmp    1150 <main+0x20>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@LOG_ERR = global i32 0
@.str = [4 x i8] c"%lu\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca i64
store i32 0, i32* %1
br label %4
4: ; preds = %0, %4
%5 = call i32 @interval_wait(i32 1000)
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%8 = load i32, i32* %7
%9 = mul nsw i32 %8, 1000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%11 = load i32, i32* %10
%12 = sdiv i32 %11, 1000
%13 = add nsw i32 %9, %12
%14 = sext i32 %13 to i64
store i64 %14, i64* %3
%15 = load i32, i32* @LOG_ERR
%16 = load i64, i64* %3
%17 = call i32 @syslog(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %16)
br label %4
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@LOG_ERR = global i32 0
@.str = [4 x i8] c"%lu\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
br label %5
5: ; preds = %0, %5
%6 = tail call i32 @interval_wait(i32 1000)
%7 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%8 = load i32, i32* %3
%9 = mul nsw i32 %8, 1000
%10 = load i32, i32* %4
%11 = sdiv i32 %10, 1000
%12 = add nsw i32 %11, %9
%13 = sext i32 %12 to i64
%14 = load i32, i32* @LOG_ERR
%15 = tail call i32 @syslog(i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %13)
br label %5
}