#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_3__ {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct TYPE_4__ {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct itimerval {
  TYPE_1__ it_interval;
  TYPE_2__ it_value;
};

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
int /*<<< orphan*/ setitimer(int /*<<< orphan*/, struct itimerval *,
                             int /*<<< orphan*/ *);
void set_itimer(int ints_per_sec) {
  struct itimerval itv;
  int freq = 1000 / ints_per_sec;
  itv.it_interval.tv_sec = 0;
  itv.it_interval.tv_usec = (freq % 1000) * 1000;
  itv.it_value.tv_sec = itv.it_interval.tv_sec;
  itv.it_value.tv_usec = itv.it_interval.tv_usec;
  setitimer(ITIMER_REAL, &itv, NULL);
}


x86 assembly (clang, -O0):
<set_itimer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x3e8,%eax
cltd
idivl  -0x4(%rbp)
mov    %eax,-0x2c(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <setitimer@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_itimer>:
sub    $0x28,%rsp
mov    $0x3e8,%eax
xor    %edx,%edx
idiv   %edi
movq   $0x0,0x10(%rsp)
movswl %ax,%ecx
imul   $0xffff8313,%ecx,%ecx
shr    $0x10,%ecx
add    %eax,%ecx
movzwl %cx,%ecx
movswl %cx,%edx
shr    $0xf,%ecx
sar    $0x9,%edx
add    %ecx,%edx
imul   $0x3e8,%edx,%ecx
sub    %ecx,%eax
cwtl
imul   $0x3e8,%eax,%eax
mov    %eax,0x8(%rsp)
movq   $0x0,0x20(%rsp)
mov    %eax,0x18(%rsp)
mov    0x2e77(%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_3__, %struct.TYPE_4__ }
%struct.TYPE_3__ = type { i32, i64 }
%struct.TYPE_4__ = type { i32, i64 }
@ITIMER_REAL = global i32 0
define void @set_itimer(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.itimerval
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = sdiv i32 1000, %5
store i32 %6, i32* %4
%7 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 0
%8 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %7, i32 0, i32 1
store i64 0, i64* %8
%9 = load i32, i32* %4
%10 = srem i32 %9, 1000
%11 = mul nsw i32 %10, 1000
%12 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 1
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %17, i32 0, i32 1
store i64 %16, i64* %18
%19 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 1
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* @ITIMER_REAL
%25 = call i32 @setitimer(i32 %24, %struct.itimerval* %3, i32* null)
ret void
}

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