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

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
scalar_t__ __setitimer(int /*<<< orphan*/, struct itimerval *,
                       struct itimerval *);
useconds_t ualarm(useconds_t value, useconds_t interval) {
  struct itimerval timer, otimer;
  timer.it_value.tv_sec = 0;
  timer.it_value.tv_usec = value;
  timer.it_interval.tv_sec = 0;
  timer.it_interval.tv_usec = interval;
  if (__setitimer(ITIMER_REAL, &timer, &otimer) < 0)
    return -1;
  return (otimer.it_value.tv_sec * 1000000) + otimer.it_value.tv_usec;
}


x86 assembly (clang, -O0):
<ualarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1030 <__setitimer@plt>
cmp    $0x0,%rax
jge    1165 <ualarm+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    1172 <ualarm+0x62>
imul   $0xf4240,-0x40(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ualarm>:
sub    $0x38,%rsp
movl   $0x0,0x8(%rsp)
mov    %edi,0xc(%rsp)
movq   $0x0,0x18(%rsp)
mov    %esi,0x10(%rsp)
mov    0x2eac(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
lea    0x20(%rsp),%rdx
call   1030 <__setitimer@plt>
imul   $0xf4240,0x20(%rsp),%ecx
add    0x24(%rsp),%ecx
test   %rax,%rax
mov    $0xffffffff,%eax
cmovns %ecx,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
%struct.itimerval = type { %struct.TYPE_3__, %struct.TYPE_4__ }
%struct.TYPE_3__ = type { i32, i32 }
%struct.TYPE_4__ = type { i32, i64 }
@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 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %6, i32 0, i32 0
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
store i32 0, i32* %9
%10 = load i32, i32* %4
%11 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %6, i32 0, i32 0
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 1
store i32 %10, i32* %12
%13 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %6, i32 0, i32 1
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %13, i32 0, i32 1
store i64 0, i64* %14
%15 = load i32, i32* %5
%16 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %6, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = load i32, i32* @ITIMER_REAL
%19 = call i64 @__setitimer(i32 %18, %struct.itimerval* %6, %struct.itimerval* %7)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %2
store i32 -1, i32* %3
br label %31
22: ; preds = %2
%23 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %7, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = mul nsw i32 %25, 1000000
%27 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %7, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = add nsw i32 %26, %29
store i32 %30, i32* %3
br label %31
31: ; preds = %22, %21
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.itimerval = type { %struct.TYPE_3__, %struct.TYPE_4__ }
%struct.TYPE_3__ = type { i32, i32 }
%struct.TYPE_4__ = type { i32, i64 }
@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 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 0
store i32 0, i32* %7
%8 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 1
store i32 %0, i32* %8
%9 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 1, i32 1
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 1, i32 0
store i32 %1, i32* %10
%11 = load i32, i32* @ITIMER_REAL
%12 = call i64 @__setitimer(i32 %11, %struct.itimerval* %3, %struct.itimerval* %4)
%13 = icmp slt i64 %12, 0
%14 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %4, i64 0, i32 0, i32 0
%15 = load i32, i32* %14
%16 = mul nsw i32 %15, 1000000
%17 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %4, i64 0, i32 0, i32 1
%18 = load i32, i32* %17
%19 = add nsw i32 %16, %18
%20 = select i1 %13, i32 -1, i32 %19
ret i32 %20
}