#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;
scalar_t__ configure_thread(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ interval_wait(int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, long);
int main() {
  if (configure_thread(0, 5, 10)) {
    return 1;
  }
  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)
xor    %edi,%edi
mov    $0x5,%esi
mov    $0xa,%edx
call   1030 <configure_thread@plt>
cmp    $0x0,%rax
je     1175 <main+0x35>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    117a <main+0x3a>
mov    $0x3e8,%edi
call   1060 <interval_wait@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <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    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe36(%rip),%rsi
call   1050 <syslog@plt>
jmp    117a <main+0x3a>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
mov    $0x5,%esi
mov    $0xa,%edx
call   1030 <configure_thread@plt>
test   %rax,%rax
je     116e <main+0x2e>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0x8(%rsp),%r14
mov    0x2e5e(%rip),%r15
lea    0xe7f(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x3e8,%edi
call   1060 <interval_wait@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <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   1050 <syslog@plt>
jmp    1190 <main+0x50>

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
%4 = call i64 @configure_thread(i32 0, i32 5, i32 10)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
ret i32 1
7: ; preds = %0
br label %8
8: ; preds = %7, %8
%9 = call i32 @interval_wait(i32 1000)
%10 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%12 = load i32, i32* %11
%13 = mul nsw i32 %12, 1000
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%15 = load i32, i32* %14
%16 = sdiv i32 %15, 1000
%17 = add nsw i32 %13, %16
%18 = sext i32 %17 to i64
store i64 %18, i64* %3
%19 = load i32, i32* @LOG_ERR
%20 = load i64, i64* %3
%21 = call i32 @syslog(i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %20)
br label %8
}

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 = tail call i64 @configure_thread(i32 0, i32 5, i32 10)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = bitcast %struct.timeval* %1 to i8*
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
br label %9
8: ; preds = %0
ret i32 1
9: ; preds = %4, %9
%10 = tail call i32 @interval_wait(i32 1000)
%11 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%12 = load i32, i32* %6
%13 = mul nsw i32 %12, 1000
%14 = load i32, i32* %7
%15 = sdiv i32 %14, 1000
%16 = add nsw i32 %15, %13
%17 = sext i32 %16 to i64
%18 = load i32, i32* @LOG_ERR
%19 = tail call i32 @syslog(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %17)
br label %9
}