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

/* Variables and functions */
void round_dec(struct timeval *tv, int decimals) {
  static const unsigned divisors[] = {1000000, 100000, 10000, 1000, 100, 10, 1};
  unsigned div = divisors[((decimals) < (6) ? (decimals) : (6))];
  tv->tv_usec += div / 2;
  tv->tv_sec += tv->tv_usec / 1000000;
  tv->tv_usec = tv->tv_usec % 1000000 / div;
}


x86 assembly (clang, -O0):
<round_dec>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x6,-0xc(%rbp)
jge    1120 <round_dec+0x20>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    112d <round_dec+0x2d>
mov    $0x6,%eax
mov    %eax,-0x14(%rbp)
jmp    112d <round_dec+0x2d>
mov    -0x14(%rbp),%eax
movslq %eax,%rcx
lea    0xec6(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
shr    $0x1,%ecx
mov    -0x8(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
add    0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<round_dec>:
cmp    $0x6,%esi
mov    $0x6,%eax
cmovl  %esi,%eax
cltq
lea    0xeec(%rip),%rcx
mov    (%rcx,%rax,4),%ecx
mov    %ecx,%eax
shr    %eax
add    (%rdi),%eax
imul   $0x431bde83,%rax,%rdx
shr    $0x32,%rdx
add    %edx,0x4(%rdi)
imul   $0xf4240,%edx,%edx
sub    %edx,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,(%rdi)
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@round_dec.divisors = internal constant [7 x i32] [i32 1000000, i32 100000, i32 10000, i32 1000, i32 100, i32 10, i32 1]
define void @round_dec(%struct.timeval* %0, i32 %1) {
%3 = alloca %struct.timeval*
%4 = alloca i32
%5 = alloca i32
store %struct.timeval* %0, %struct.timeval** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 6
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i32, i32* %4
br label %11
10: ; preds = %2
br label %11
11: ; preds = %10, %8
%12 = phi i32 [ %9, %8 ], [ 6, %10 ]
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [7 x i32], [7 x i32]* @round_dec.divisors, i64 0, i64 %13
%15 = load i32, i32* %14
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = udiv i32 %16, 2
%18 = load %struct.timeval*, %struct.timeval** %3
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = add i32 %20, %17
store i32 %21, i32* %19
%22 = load %struct.timeval*, %struct.timeval** %3
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = udiv i32 %24, 1000000
%26 = load %struct.timeval*, %struct.timeval** %3
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %26, i32 0, i32 1
%28 = load i32, i32* %27
%29 = add i32 %28, %25
store i32 %29, i32* %27
%30 = load %struct.timeval*, %struct.timeval** %3
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = urem i32 %32, 1000000
%34 = load i32, i32* %5
%35 = udiv i32 %33, %34
%36 = load %struct.timeval*, %struct.timeval** %3
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %36, i32 0, i32 0
store i32 %35, i32* %37
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@round_dec.divisors = internal unnamed_addr constant [7 x i32] [i32 1000000, i32 100000, i32 10000, i32 1000, i32 100, i32 10, i32 1]
define void @round_dec(%struct.timeval* nocapture %0, i32 %1) {
%3 = icmp slt i32 %1, 6
%4 = select i1 %3, i32 %1, i32 6
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds [7 x i32], [7 x i32]* @round_dec.divisors, i64 0, i64 %5
%7 = load i32, i32* %6
%8 = lshr i32 %7, 1
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%10 = load i32, i32* %9
%11 = add i32 %10, %8
%12 = udiv i32 %11, 1000000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%14 = load i32, i32* %13
%15 = add i32 %14, %12
store i32 %15, i32* %13
%16 = urem i32 %11, 1000000
%17 = udiv i32 %16, %7
store i32 %17, i32* %9
ret void
}