#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_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int tv_sec;
  int tv_usec;
};
struct itimerval {
  TYPE_1__ it_value;
  TYPE_1__ it_interval;
};

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
int /*<<< orphan*/ setitimer(int /*<<< orphan*/, struct itimerval *,
                             int /*<<< orphan*/ *);
void set_timer(int msec) {
  struct itimerval i;
  i.it_value.tv_sec = msec / 1000;
  i.it_value.tv_usec = (msec * 1000) % 1000000;
  i.it_interval = i.it_value;
  setitimer(ITIMER_REAL, &i, NULL);
}


x86 assembly (clang, -O0):
<set_timer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
imul   $0x3e8,-0x4(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <setitimer@plt>
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.itimerval = type { %struct.TYPE_2__, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i32 }
@ITIMER_REAL = global i32 0
define void @set_timer(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.itimerval
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = sdiv i32 %4, 1000
%6 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 0
%7 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %6, i32 0, i32 0
store i32 %5, i32* %7
%8 = load i32, i32* %2
%9 = mul nsw i32 %8, 1000
%10 = srem i32 %9, 1000000
%11 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 0
%12 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %11, i32 0, i32 1
store i32 %10, i32* %12
%13 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 1
%14 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 0
%15 = bitcast %struct.TYPE_2__* %13 to i8*
%16 = bitcast %struct.TYPE_2__* %14 to i8*
%17 = load i32, i32* @ITIMER_REAL
%18 = call i32 @setitimer(i32 %17, %struct.itimerval* %3, i32* null)
ret void
}

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