#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 */
typedef int useconds_t;
struct TYPE_4__ {
  int tv_usec;
  int tv_sec;
};
struct TYPE_3__ {
  int tv_usec;
  int tv_sec;
};
struct itimerval {
  TYPE_2__ it_value;
  TYPE_1__ it_interval;
};

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
scalar_t__ setitimer(int /*<<< orphan*/, struct itimerval *,
                     struct itimerval *);
useconds_t ualarm(useconds_t usecs, useconds_t reload) {
  struct itimerval new, old;
  new.it_interval.tv_usec = reload % 1000000;
  new.it_interval.tv_sec = reload / 1000000;
  new.it_value.tv_usec = usecs % 1000000;
  new.it_value.tv_sec = usecs / 1000000;
  if (setitimer(ITIMER_REAL, &new, &old) == 0)
    return (old.it_value.tv_sec * 1000000 + old.it_value.tv_usec);
  return (-1);
}


x86 assembly (clang, -O0):
<ualarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <setitimer@plt>
cmp    $0x0,%rax
jne    1188 <ualarm+0x78>
imul   $0xf4240,-0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <ualarm+0x7f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ualarm>:
sub    $0x28,%rsp
movslq %esi,%rax
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xf4240,%ecx,%edx
sub    %edx,%eax
mov    %eax,0x10(%rsp)
mov    %ecx,0x14(%rsp)
movslq %edi,%rax
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xf4240,%ecx,%edx
sub    %edx,%eax
mov    %eax,0x8(%rsp)
mov    %ecx,0xc(%rsp)
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
lea    0x18(%rsp),%rdx
call   1030 <setitimer@plt>
imul   $0xf4240,0x1c(%rsp),%ecx
add    0x18(%rsp),%ecx
neg    %rax
sbb    %eax,%eax
or     %ecx,%eax
add    $0x28,%rsp
ret

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
define i32 @ualarm(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.itimerval
%7 = alloca %struct.itimerval
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = srem i32 %8, 1000000
%10 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %6, i32 0, i32 1
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %10, i32 0, i32 0
store i32 %9, i32* %11
%12 = load i32, i32* %5
%13 = sdiv i32 %12, 1000000
%14 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %6, i32 0, i32 1
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 1
store i32 %13, i32* %15
%16 = load i32, i32* %4
%17 = srem i32 %16, 1000000
%18 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %6, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %18, i32 0, i32 0
store i32 %17, i32* %19
%20 = load i32, i32* %4
%21 = sdiv i32 %20, 1000000
%22 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %6, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %22, i32 0, i32 1
store i32 %21, i32* %23
%24 = load i32, i32* @ITIMER_REAL
%25 = call i64 @setitimer(i32 %24, %struct.itimerval* %6, %struct.itimerval* %7)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %2
%28 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %7, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = mul nsw i32 %30, 1000000
%32 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %7, i32 0, i32 0
%33 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = add nsw i32 %31, %34
store i32 %35, i32* %3
br label %37
36: ; preds = %2
store i32 -1, i32* %3
br label %37
37: ; preds = %36, %27
%38 = load i32, i32* %3
ret i32 %38
}

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
define i32 @ualarm(i32 %0, i32 %1) {
%3 = alloca %struct.itimerval
%4 = alloca %struct.itimerval
%5 = bitcast %struct.itimerval* %3 to i8*
%6 = bitcast %struct.itimerval* %4 to i8*
%7 = srem i32 %1, 1000000
%8 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 1, i32 0
store i32 %7, i32* %8
%9 = sdiv i32 %1, 1000000
%10 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 1, i32 1
store i32 %9, i32* %10
%11 = srem i32 %0, 1000000
%12 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 0
store i32 %11, i32* %12
%13 = sdiv i32 %0, 1000000
%14 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 1
store i32 %13, i32* %14
%15 = load i32, i32* @ITIMER_REAL
%16 = call i64 @setitimer(i32 %15, %struct.itimerval* %3, %struct.itimerval* %4)
%17 = icmp eq i64 %16, 0
%18 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %4, i64 0, i32 0, i32 1
%19 = load i32, i32* %18
%20 = mul nsw i32 %19, 1000000
%21 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %4, i64 0, i32 0, i32 0
%22 = load i32, i32* %21
%23 = add nsw i32 %20, %22
%24 = select i1 %17, i32 %23, i32 -1
ret i32 %24
}