#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;
};
struct katcp_dispatch {
  int dummy;
};

/* Variables and functions */
int register_every_tv_katcp(struct katcp_dispatch *, struct timeval *,
                            int (*)(struct katcp_dispatch *, void *), void *);
int register_every_ms_katcp(struct katcp_dispatch *d, unsigned int milli,
                            int (*call)(struct katcp_dispatch *d, void *data),
                            void *data) {
  struct timeval tv;
  tv.tv_sec = milli / 1000;
  tv.tv_usec = (milli % 1000) * 1000;
  return register_every_tv_katcp(d, &tv, call, data);
}


x86 assembly (clang, -O0):
<register_every_ms_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%rsi
call   1030 <register_every_tv_katcp@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<register_every_ms_katcp>:
push   %rax
mov    %esi,%eax
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
mov    %eax,(%rsp)
imul   $0x3e8,%eax,%eax
sub    %eax,%esi
imul   $0x3e8,%esi,%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rsi
call   1030 <register_every_tv_katcp@plt>
pop    %rcx
ret

LLVM IR (-O0):
%struct.katcp_dispatch = type { i32 }
%struct.timeval = type { i32, i32 }
define i32 @register_every_ms_katcp(%struct.katcp_dispatch* %0, i32 %1, i32 (%struct.katcp_dispatch*, i8*)* %2, i8* %3) {
%5 = alloca %struct.katcp_dispatch*
%6 = alloca i32
%7 = alloca i32 (%struct.katcp_dispatch*, i8*)*
%8 = alloca i8*
%9 = alloca %struct.timeval
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %5
store i32 %1, i32* %6
store i32 (%struct.katcp_dispatch*, i8*)* %2, i32 (%struct.katcp_dispatch*, i8*)** %7
store i8* %3, i8** %8
%10 = load i32, i32* %6
%11 = udiv i32 %10, 1000
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
store i32 %11, i32* %12
%13 = load i32, i32* %6
%14 = urem i32 %13, 1000
%15 = mul i32 %14, 1000
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
store i32 %15, i32* %16
%17 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%18 = load i32 (%struct.katcp_dispatch*, i8*)*, i32 (%struct.katcp_dispatch*, i8*)** %7
%19 = load i8*, i8** %8
%20 = call i32 @register_every_tv_katcp(%struct.katcp_dispatch* %17, %struct.timeval* %9, i32 (%struct.katcp_dispatch*, i8*)* %18, i8* %19)
ret i32 %20
}

LLVM IR (-O2):
%struct.katcp_dispatch = type { i32 }
%struct.timeval = type { i32, i32 }
define i32 @register_every_ms_katcp(%struct.katcp_dispatch* %0, i32 %1, i32 (%struct.katcp_dispatch*, i8*)* %2, i8* %3) {
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %5 to i8*
%7 = udiv i32 %1, 1000
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i32 %7, i32* %8
%9 = urem i32 %1, 1000
%10 = mul nuw nsw i32 %9, 1000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i32 %10, i32* %11
%12 = call i32 @register_every_tv_katcp(%struct.katcp_dispatch* %0, %struct.timeval* %5, i32 (%struct.katcp_dispatch*, i8*)* %2, i8* %3)
ret i32 %12
}