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

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int setitimer(int /*<<< orphan*/, struct itimerval *, int /*<<< orphan*/ *);
void setTimer(int quantum) {
  struct itimerval timer;
  timer.it_value.tv_sec = quantum / 1000;
  timer.it_value.tv_usec = (quantum % 1000) * 1000;
  timer.it_interval.tv_sec = quantum / 1000;
  timer.it_interval.tv_usec = (quantum % 1000) * 1000;
  if (setitimer(ITIMER_REAL, &timer, NULL) == -1) {
    perror("setitimer failed");
    exit(-1);
  }
  return;
}


x86 assembly (clang, -O0):
<setTimer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0x14(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <setitimer@plt>
cmp    $0xffffffff,%eax
jne    11b4 <setTimer+0x84>
lea    0xe5b(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setTimer>:
sub    $0x18,%rsp
movslq %edi,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,0x10(%rsp)
imul   $0x3e8,%ecx,%edx
sub    %edx,%eax
imul   $0x3e8,%eax,%eax
mov    %eax,0x14(%rsp)
mov    %ecx,0x8(%rsp)
mov    %eax,0xc(%rsp)
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <setitimer@plt>
cmp    $0xffffffff,%eax
je     1188 <setTimer+0x58>
add    $0x18,%rsp
ret
lea    0xe71(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
@ITIMER_REAL = global i32 0
@.str = [17 x i8] c"setitimer failed\00"
define void @setTimer(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 1
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
store i32 %5, i32* %7
%8 = load i32, i32* %2
%9 = srem i32 %8, 1000
%10 = mul nsw i32 %9, 1000
%11 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 1
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 1
store i32 %10, i32* %12
%13 = load i32, i32* %2
%14 = sdiv i32 %13, 1000
%15 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load i32, i32* %2
%18 = srem i32 %17, 1000
%19 = mul nsw i32 %18, 1000
%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 1
store i32 %19, i32* %21
%22 = load i32, i32* @ITIMER_REAL
%23 = call i32 @setitimer(i32 %22, %struct.itimerval* %3, i32* null)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %1
%26 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %1
ret void
}

LLVM IR (-O2):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
@ITIMER_REAL = global i32 0
@.str = [17 x i8] c"setitimer failed\00"
define void @setTimer(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 1, i32 0
store i32 %4, i32* %5
%6 = srem i32 %0, 1000
%7 = mul nsw i32 %6, 1000
%8 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 1, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 0
store i32 %4, i32* %9
%10 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 1
store i32 %7, i32* %10
%11 = load i32, i32* @ITIMER_REAL
%12 = call i32 @setitimer(i32 %11, %struct.itimerval* %2, i32* null)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 -1)
unreachable
17: ; preds = %1
ret void
}