#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__ {
  long tv_sec;
  scalar_t__ tv_usec;
};
struct TYPE_3__ {
  scalar_t__ tv_usec;
  scalar_t__ 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 *);
unsigned int alarm(unsigned int seconds) {
  struct itimerval old, new;
  unsigned int retval;
  new.it_value.tv_usec = 0;
  new.it_interval.tv_sec = 0;
  new.it_interval.tv_usec = 0;
  new.it_value.tv_sec = (long int)seconds;
  if (setitimer(ITIMER_REAL, &new, &old) < 0) {
    return 0;
  }
  retval = old.it_value.tv_sec;
  if (old.it_value.tv_usec) {
    ++retval;
  }
  return retval;
}


x86 assembly (clang, -O0):
<alarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x48(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <setitimer@plt>
cmp    $0x0,%rax
jge    1166 <alarm+0x56>
movl   $0x0,-0x4(%rbp)
jmp    1187 <alarm+0x77>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1181 <alarm+0x71>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alarm>:
sub    $0x48,%rsp
mov    %edi,%eax
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
mov    %rax,0x8(%rsp)
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
lea    0x28(%rsp),%rdx
call   1030 <setitimer@plt>
test   %rax,%rax
js     115b <alarm+0x4b>
mov    0x28(%rsp),%eax
cmpq   $0x1,0x30(%rsp)
sbb    $0xffffffff,%eax
add    $0x48,%rsp
ret
xor    %eax,%eax
add    $0x48,%rsp
ret

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

LLVM IR (-O2):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i64, 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* %3, i64 0, i32 0, i32 1
%7 = zext i32 %0 to i64
%8 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 0
%9 = bitcast i64* %6 to i8*
store i64 %7, i64* %8
%10 = load i32, i32* @ITIMER_REAL
%11 = call i64 @setitimer(i32 %10, %struct.itimerval* %3, %struct.itimerval* %2)
%12 = icmp slt i64 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %1
%14 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 0
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
%17 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 1
%18 = load i64, i64* %17
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i32
%21 = add i32 %20, %16
br label %22
22: ; preds = %1, %13
%23 = phi i32 [ %21, %13 ], [ 0, %1 ]
ret i32 %23
}