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

/* Variables and functions */
void timeval_sub_msecs(struct timeval *tv, unsigned int msecs) {
  tv->tv_sec -= msecs / 1000;
  tv->tv_usec -= (msecs % 1000) * 1000;
  if (tv->tv_usec < 0) {
    tv->tv_sec--;
    tv->tv_usec += 1000000;
  }
}


x86 assembly (clang, -O0):
<timeval_sub_msecs>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%eax
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,0x8(%rax)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,%eax
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jge    117c <timeval_sub_msecs+0x7c>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_sub_msecs>:
mov    (%rdi),%rax
mov    0x8(%rdi),%rcx
mov    %esi,%edx
imul   $0x10624dd3,%rdx,%rdx
shr    $0x26,%rdx
sub    %rdx,%rcx
mov    %rcx,0x8(%rdi)
imul   $0x3e8,%edx,%edx
sub    %edx,%esi
imul   $0x3e8,%esi,%edx
sub    %rdx,%rax
mov    %rax,(%rdi)
js     1132 <timeval_sub_msecs+0x32>
ret
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rdi)
add    $0xf4240,%rax
mov    %rax,(%rdi)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @timeval_sub_msecs(%struct.timeval* nocapture %0, i32 %1) {
%3 = udiv i32 %1, 1000
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%6 = load i64, i64* %5
%7 = sub nsw i64 %6, %4
store i64 %7, i64* %5
%8 = urem i32 %1, 1000
%9 = mul nuw nsw i32 %8, 1000
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%12 = load i64, i64* %11
%13 = sub nsw i64 %12, %10
store i64 %13, i64* %11
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = add nsw i64 %7, -1
store i64 %16, i64* %5
%17 = add nsw i64 %13, 1000000
store i64 %17, i64* %11
br label %18
18: ; preds = %15, %2
ret void
}