#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 */
void timeval_align(struct timeval *x) {
  x->tv_sec += x->tv_usec / 1000000;
  x->tv_usec = x->tv_usec % 1000000;
  if (x->tv_usec < 0) {
    x->tv_usec = 1000000 + x->tv_usec;
    x->tv_sec -= 1;
  }
}


x86 assembly (clang, -O0):
<timeval_align>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    -0x8(%rbp),%rax
mov    %edx,0x4(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x0,0x4(%rax)
jge    1164 <timeval_align+0x64>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0xf4240,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_align>:
movslq 0x4(%rdi),%rcx
imul   $0x431bde83,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rax
add    %edx,%eax
imul   $0xf4240,%eax,%edx
add    (%rdi),%eax
mov    %eax,(%rdi)
sub    %edx,%ecx
mov    %ecx,0x4(%rdi)
js     112a <timeval_align+0x2a>
ret
add    $0xf4240,%ecx
mov    %ecx,0x4(%rdi)
add    $0xffffffff,%eax
mov    %eax,(%rdi)
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @timeval_align(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
store %struct.timeval* %0, %struct.timeval** %2
%3 = load %struct.timeval*, %struct.timeval** %2
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%5 = load i32, i32* %4
%6 = sdiv i32 %5, 1000000
%7 = load %struct.timeval*, %struct.timeval** %2
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = add nsw i32 %9, %6
store i32 %10, i32* %8
%11 = load %struct.timeval*, %struct.timeval** %2
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%13 = load i32, i32* %12
%14 = srem i32 %13, 1000000
%15 = load %struct.timeval*, %struct.timeval** %2
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
store i32 %14, i32* %16
%17 = load %struct.timeval*, %struct.timeval** %2
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %1
%22 = load %struct.timeval*, %struct.timeval** %2
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = add nsw i32 1000000, %24
%26 = load %struct.timeval*, %struct.timeval** %2
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %26, i32 0, i32 1
store i32 %25, i32* %27
%28 = load %struct.timeval*, %struct.timeval** %2
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = sub nsw i32 %30, 1
store i32 %31, i32* %29
br label %32
32: ; preds = %21, %1
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @timeval_align(%struct.timeval* nocapture %0) {
%2 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%3 = load i32, i32* %2
%4 = sdiv i32 %3, 1000000
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = add nsw i32 %6, %4
store i32 %7, i32* %5
%8 = srem i32 %3, 1000000
store i32 %8, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = add nsw i32 %8, 1000000
store i32 %11, i32* %2
%12 = add nsw i32 %7, -1
store i32 %12, i32* %5
br label %13
13: ; preds = %10, %1
ret void
}