#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_6__ TYPE_3__;
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
typedef int useconds_t;
struct TYPE_6__ {
  int tv_sec;
  int tv_usec;
};
struct TYPE_5__ {
  int member_1;
  int /*<<< orphan*/ member_0;
};
struct TYPE_4__ {
  int member_1;
  int /*<<< orphan*/ member_0;
};
struct itimerval {
  TYPE_3__ it_value;
  TYPE_2__ member_1;
  TYPE_1__ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
scalar_t__ setitimer(int /*<<< orphan*/, struct itimerval const *,
                     struct itimerval *);
useconds_t ualarm(useconds_t value, useconds_t interval) {
  struct itimerval otimer;
  const struct itimerval itimer = {{0, interval}, {0, value}};
  if (setitimer(ITIMER_REAL, &itimer, &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,-0x40(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x40(%rbp),%rdi
add    $0x10,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <setitimer@plt>
cmp    $0x0,%rax
jge    1188 <ualarm+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <ualarm+0x75>
imul   $0xf4240,-0x28(%rbp),%eax
add    -0x24(%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    %esi,0xc(%rsp)
movl   $0x0,0x10(%rsp)
mov    %edi,0x14(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x2ea4(%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_6__, %struct.TYPE_5__, %struct.TYPE_4__ }
%struct.TYPE_6__ = type { i32, i32 }
%struct.TYPE_5__ = type { i32, i32 }
%struct.TYPE_4__ = 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 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %7, i32 0, i32 0
%9 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %8, i32 0, i32 0
store i32 0, i32* %9
%10 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %8, i32 0, i32 1
%11 = load i32, i32* %5
store i32 %11, i32* %10
%12 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %7, i32 0, i32 1
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 0
store i32 0, i32* %13
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
%15 = load i32, i32* %4
store i32 %15, i32* %14
%16 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %7, i32 0, i32 2
%17 = bitcast %struct.TYPE_4__* %16 to i8*
%18 = load i32, i32* @ITIMER_REAL
%19 = call i64 @setitimer(i32 %18, %struct.itimerval* %7, %struct.itimerval* %6)
%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* %6, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = mul nsw i32 %25, 1000000
%27 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %6, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %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_6__, %struct.TYPE_5__, %struct.TYPE_4__ }
%struct.TYPE_6__ = type { i32, i32 }
%struct.TYPE_5__ = type { i32, i32 }
%struct.TYPE_4__ = 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 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %4, i64 0, i32 0, i32 0
store i32 0, i32* %7
%8 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %4, i64 0, i32 0, i32 1
store i32 %1, i32* %8
%9 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %4, i64 0, i32 1, i32 0
store i32 0, i32* %9
%10 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %4, i64 0, i32 1, i32 1
store i32 %0, i32* %10
%11 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %4, i64 0, i32 2
%12 = bitcast %struct.TYPE_4__* %11 to i64*
store i64 0, i64* %12
%13 = load i32, i32* @ITIMER_REAL
%14 = call i64 @setitimer(i32 %13, %struct.itimerval* %4, %struct.itimerval* %3)
%15 = icmp slt i64 %14, 0
%16 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 0
%17 = load i32, i32* %16
%18 = mul nsw i32 %17, 1000000
%19 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 1
%20 = load i32, i32* %19
%21 = add nsw i32 %18, %20
%22 = select i1 %15, i32 -1, i32 %21
ret i32 %22
}