#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  long tv_sec;
  long tv_usec;
};
struct TYPE_3__ {
  long tv_sec;
  long tv_usec;
};
struct itimerval {
  TYPE_2__ it_value;
  TYPE_1__ it_interval;
};

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
int setitimer(int /*<<< orphan*/, struct itimerval *, int /*<<< orphan*/ *);
int set_ticker(int n_msecs) {
  struct itimerval new_timeset;
  long n_sec, n_usecs;
  n_sec = n_msecs / 1000;
  n_usecs = (n_msecs % 1000) * 1000L;
  new_timeset.it_interval.tv_sec = n_sec;
  new_timeset.it_interval.tv_usec = n_usecs;
  new_timeset.it_value.tv_sec = n_sec;
  new_timeset.it_value.tv_usec = n_usecs;
  return setitimer(ITIMER_REAL, &new_timeset, NULL);
}


x86 assembly (clang, -O0):
<set_ticker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
imul   $0x3e8,%rax,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <setitimer@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_ticker>:
sub    $0x28,%rsp
movslq %edi,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
movslq %ecx,%rcx
imul   $0x3e8,%ecx,%edx
sub    %edx,%eax
imul   $0x3e8,%eax,%eax
cltq
mov    %rcx,0x18(%rsp)
mov    %rax,0x20(%rsp)
mov    %rcx,0x8(%rsp)
mov    %rax,0x10(%rsp)
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <setitimer@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i64, i64 }
@ITIMER_REAL = global i32 0
define i32 @set_ticker(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.itimerval
%4 = alloca i64
%5 = alloca i64
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = sdiv i32 %6, 1000
%8 = sext i32 %7 to i64
store i64 %8, i64* %4
%9 = load i32, i32* %2
%10 = srem i32 %9, 1000
%11 = sext i32 %10 to i64
%12 = mul nsw i64 %11, 1000
store i64 %12, i64* %5
%13 = load i64, i64* %4
%14 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 1
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 0
store i64 %13, i64* %15
%16 = load i64, i64* %5
%17 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %17, i32 0, i32 1
store i64 %16, i64* %18
%19 = load i64, i64* %4
%20 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 0
store i64 %19, i64* %21
%22 = load i64, i64* %5
%23 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i32 0, i32 1
store i64 %22, i64* %24
%25 = load i32, i32* @ITIMER_REAL
%26 = call i32 @setitimer(i32 %25, %struct.itimerval* %3, i32* null)
ret i32 %26
}

LLVM IR (-O2):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i64, i64 }
@ITIMER_REAL = global i32 0
define i32 @set_ticker(i32 %0) {
%2 = alloca %struct.itimerval
%3 = bitcast %struct.itimerval* %2 to i8*
%4 = sdiv i32 %0, 1000
%5 = sext i32 %4 to i64
%6 = srem i32 %0, 1000
%7 = mul nsw i32 %6, 1000
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 1, i32 0
store i64 %5, i64* %9
%10 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 1, i32 1
store i64 %8, i64* %10
%11 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 0
store i64 %5, i64* %11
%12 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 1
store i64 %8, i64* %12
%13 = load i32, i32* @ITIMER_REAL
%14 = call i32 @setitimer(i32 %13, %struct.itimerval* %2, i32* null)
ret i32 %14
}