#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_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  unsigned int tv_sec;
  scalar_t__ tv_usec;
};
struct itimerval {
  TYPE_1__ it_value;
  int /*<<< orphan*/ it_interval;
};

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
scalar_t__ setitimer(int /*<<< orphan*/, struct itimerval *,
                     struct itimerval *);
int /*<<< orphan*/ timerclear(int /*<<< orphan*/ *);
unsigned int alarm(unsigned int secs) {
  struct itimerval it, oitv;
  struct itimerval *itp = &it;
  timerclear(&itp->it_interval);
  itp->it_value.tv_sec = secs;
  itp->it_value.tv_usec = 0;
  if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
    return ((unsigned int)-1);
  if (oitv.it_value.tv_usec)
    oitv.it_value.tv_sec++;
  return (oitv.it_value.tv_sec);
}


x86 assembly (clang, -O0):
<alarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
add    $0x10,%rdi
call   1030 <timerclear@plt>
mov    -0x8(%rbp),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1040 <setitimer@plt>
cmp    $0x0,%rax
jge    1181 <alarm+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <alarm+0x7b>
cmpq   $0x0,-0x30(%rbp)
je     1195 <alarm+0x75>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alarm>:
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebx
lea    0x10(%rsp),%rdi
call   1030 <timerclear@plt>
mov    %ebx,(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
lea    0x18(%rsp),%rdx
call   1040 <setitimer@plt>
test   %rax,%rax
js     1167 <alarm+0x47>
mov    0x18(%rsp),%eax
cmpq   $0x1,0x20(%rsp)
sbb    $0xffffffff,%eax
jmp    116c <alarm+0x4c>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.itimerval = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i64 }
@ITIMER_REAL = global i32 0
define i32 @alarm(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.itimerval
%5 = alloca %struct.itimerval
%6 = alloca %struct.itimerval*
store i32 %0, i32* %3
store %struct.itimerval* %4, %struct.itimerval** %6
%7 = load %struct.itimerval*, %struct.itimerval** %6
%8 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %7, i32 0, i32 1
%9 = call i32 @timerclear(i32* %8)
%10 = load i32, i32* %3
%11 = load %struct.itimerval*, %struct.itimerval** %6
%12 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %11, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
store i32 %10, i32* %13
%14 = load %struct.itimerval*, %struct.itimerval** %6
%15 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %14, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 1
store i64 0, i64* %16
%17 = load i32, i32* @ITIMER_REAL
%18 = load %struct.itimerval*, %struct.itimerval** %6
%19 = call i64 @setitimer(i32 %17, %struct.itimerval* %18, %struct.itimerval* %5)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %1
store i32 -1, i32* %2
br label %36
22: ; preds = %1
%23 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %5, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 1
%25 = load i64, i64* %24
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %5, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = add i32 %30, 1
store i32 %31, i32* %29
br label %32
32: ; preds = %27, %22
%33 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %5, i32 0, i32 0
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
%35 = load i32, i32* %34
store i32 %35, i32* %2
br label %36
36: ; preds = %32, %21
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
%struct.itimerval = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i64 }
@ITIMER_REAL = global i32 0
define i32 @alarm(i32 %0) {
%2 = alloca %struct.itimerval
%3 = alloca %struct.itimerval
%4 = bitcast %struct.itimerval* %2 to i8*
%5 = bitcast %struct.itimerval* %3 to i8*
%6 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 1
%7 = call i32 @timerclear(i32* %6)
%8 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 0
store i32 %0, i32* %8
%9 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 1
store i64 0, i64* %9
%10 = load i32, i32* @ITIMER_REAL
%11 = call i64 @setitimer(i32 %10, %struct.itimerval* %2, %struct.itimerval* %3)
%12 = icmp slt i64 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %1
%14 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 1
%15 = load i64, i64* %14
%16 = icmp ne i64 %15, 0
%17 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 0
%18 = load i32, i32* %17
%19 = zext i1 %16 to i32
%20 = add i32 %18, %19
br label %21
21: ; preds = %13, %1
%22 = phi i32 [ -1, %1 ], [ %20, %13 ]
ret i32 %22
}