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

/* Variables and functions */
void mstotvround(struct timeval *res, long x) {
  if (x < 0)
    x = -((-x + 3) / 5);
  else
    x = (x + 3) / 5;
  x *= 5;
  res->tv_sec = x / 1000;
  res->tv_usec = (x - res->tv_sec * 1000) * 1000;
  if (res->tv_usec < 0) {
    res->tv_usec += 1000000;
    res->tv_sec--;
  }
}


x86 assembly (clang, -O0):
<mstotvround>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    113c <mstotvround+0x3c>
xor    %eax,%eax
sub    -0x10(%rbp),%rax
add    $0x3,%rax
mov    $0x5,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
xor    %eax,%eax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1152 <mstotvround+0x52>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    $0x5,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
imul   $0x5,-0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
imul   $0x3e8,(%rcx),%rcx
sub    %rcx,%rax
imul   $0x3e8,%rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jge    11c4 <mstotvround+0xc4>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<mstotvround>:
test   %rsi,%rsi
js     1122 <mstotvround+0x22>
add    $0x3,%rsi
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mov    %rsi,%rax
mul    %rcx
mov    %rdx,%rcx
shr    $0x2,%rcx
jmp    1147 <mstotvround+0x47>
mov    $0x3,%eax
sub    %rsi,%rax
movabs $0x9999999999999999,%rcx
99 99 99
imul   %rcx
mov    %rdx,%rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    %rcx
add    %rax,%rcx
lea    (%rcx,%rcx,4),%rsi
movabs $0xa3d70a3d70a3d70b,%rdx
0a d7 a3
mov    %rcx,%rax
imul   %rdx
add    %rcx,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x7,%rdx
add    %rax,%rdx
mov    %rdx,(%rdi)
imul   $0xfffffffffffffc18,%rdx,%rcx
add    %rsi,%rcx
imul   $0x3e8,%rcx,%rax
mov    %rax,0x8(%rdi)
test   %rcx,%rcx
js     118a <mstotvround+0x8a>
ret
add    $0xf4240,%rax
mov    %rax,0x8(%rdi)
add    $0xffffffffffffffff,%rdx
mov    %rdx,(%rdi)
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define void @mstotvround(%struct.timeval* %0, i64 %1) {
%3 = alloca %struct.timeval*
%4 = alloca i64
store %struct.timeval* %0, %struct.timeval** %3
store i64 %1, i64* %4
%5 = load i64, i64* %4
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i64, i64* %4
%9 = sub nsw i64 0, %8
%10 = add nsw i64 %9, 3
%11 = sdiv i64 %10, 5
%12 = sub nsw i64 0, %11
store i64 %12, i64* %4
br label %17
13: ; preds = %2
%14 = load i64, i64* %4
%15 = add nsw i64 %14, 3
%16 = sdiv i64 %15, 5
store i64 %16, i64* %4
br label %17
17: ; preds = %13, %7
%18 = load i64, i64* %4
%19 = mul nsw i64 %18, 5
store i64 %19, i64* %4
%20 = load i64, i64* %4
%21 = sdiv i64 %20, 1000
%22 = load %struct.timeval*, %struct.timeval** %3
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
store i64 %21, i64* %23
%24 = load i64, i64* %4
%25 = load %struct.timeval*, %struct.timeval** %3
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 0
%27 = load i64, i64* %26
%28 = mul nsw i64 %27, 1000
%29 = sub nsw i64 %24, %28
%30 = mul nsw i64 %29, 1000
%31 = load %struct.timeval*, %struct.timeval** %3
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %31, i32 0, i32 1
store i64 %30, i64* %32
%33 = load %struct.timeval*, %struct.timeval** %3
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %33, i32 0, i32 1
%35 = load i64, i64* %34
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %17
%38 = load %struct.timeval*, %struct.timeval** %3
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %38, i32 0, i32 1
%40 = load i64, i64* %39
%41 = add nsw i64 %40, 1000000
store i64 %41, i64* %39
%42 = load %struct.timeval*, %struct.timeval** %3
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %42, i32 0, i32 0
%44 = load i64, i64* %43
%45 = add nsw i64 %44, -1
store i64 %45, i64* %43
br label %46
46: ; preds = %37, %17
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @mstotvround(%struct.timeval* nocapture %0, i64 %1) {
%3 = icmp slt i64 %1, 0
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = sub i64 3, %1
%6 = sdiv i64 %5, -5
br label %10
7: ; preds = %2
%8 = add nuw nsw i64 %1, 3
%9 = udiv i64 %8, 5
br label %10
10: ; preds = %7, %4
%11 = phi i64 [ %6, %4 ], [ %9, %7 ]
%12 = mul nsw i64 %11, 5
%13 = sdiv i64 %11, 200
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
store i64 %13, i64* %14
%15 = mul nsw i64 %13, -1000
%16 = add i64 %15, %12
%17 = mul nsw i64 %16, 1000
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
store i64 %17, i64* %18
%19 = icmp slt i64 %16, 0
br i1 %19, label %20, label %23
20: ; preds = %10
%21 = add nsw i64 %17, 1000000
store i64 %21, i64* %18
%22 = add nsw i64 %13, -1
store i64 %22, i64* %14
br label %23
23: ; preds = %20, %10
ret void
}