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

/* Variables and functions */
int /*<<< orphan*/ assert(struct timeval *);
int /*<<< orphan*/ timeval_clear(struct timeval *);
void timeval_millisecond_init(struct timeval *a, unsigned int ms) {
  assert(a);
  timeval_clear(a);
  a->tv_sec = ms / 1000;
  ms -= (a->tv_sec * 1000);
  a->tv_usec = ms * 1000;
}


x86 assembly (clang, -O0):
<timeval_millisecond_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <timeval_clear@plt>
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
imul   $0x3e8,(%rax),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
imul   $0x3e8,-0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_millisecond_init>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <assert@plt>
mov    %rbx,%rdi
call   1040 <timeval_clear@plt>
mov    %ebp,%eax
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
mov    %eax,(%rbx)
imul   $0xfffffc18,%eax,%eax
add    %ebp,%eax
imul   $0x3e8,%eax,%eax
mov    %eax,0x4(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @timeval_millisecond_init(%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 %struct.timeval*, %struct.timeval** %3
%6 = call i32 @assert(%struct.timeval* %5)
%7 = load %struct.timeval*, %struct.timeval** %3
%8 = call i32 @timeval_clear(%struct.timeval* %7)
%9 = load i32, i32* %4
%10 = udiv i32 %9, 1000
%11 = load %struct.timeval*, %struct.timeval** %3
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = load %struct.timeval*, %struct.timeval** %3
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = mul i32 %15, 1000
%17 = load i32, i32* %4
%18 = sub i32 %17, %16
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = mul i32 %19, 1000
%21 = load %struct.timeval*, %struct.timeval** %3
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 1
store i32 %20, i32* %22
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @timeval_millisecond_init(%struct.timeval* %0, i32 %1) {
%3 = tail call i32 @assert(%struct.timeval* %0)
%4 = tail call i32 @timeval_clear(%struct.timeval* %0)
%5 = udiv i32 %1, 1000
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
store i32 %5, i32* %6
%7 = mul i32 %5, -1000
%8 = add i32 %7, %1
%9 = mul i32 %8, 1000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
store i32 %9, i32* %10
ret void
}