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

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
int setitimer(int /*<<< orphan*/, struct itimerval *, struct itimerval *);
unsigned int alarm(unsigned int seconds) {
  struct itimerval old, new;
  unsigned int ret;
  new.it_interval.tv_usec = 0;
  new.it_interval.tv_sec = 0;
  new.it_value.tv_usec = 0;
  new.it_value.tv_sec = (long)seconds;
  if (setitimer(ITIMER_REAL, &new, &old) == -1)
    return 0;
  return old.it_value.tv_sec + (old.it_value.tv_usec ? 1 : 0);
}


x86 assembly (clang, -O0):
<alarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%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    $0xffffffff,%eax
jne    1165 <alarm+0x55>
movl   $0x0,-0x4(%rbp)
jmp    1184 <alarm+0x74>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rsi
xor    %ecx,%ecx
mov    $0x1,%edx
cmp    $0x0,%rsi
cmovne %edx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
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>
cmp    $0xffffffff,%eax
je     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 1
%8 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %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 0
store i64 0, i64* %10
%11 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %5, i32 0, i32 0
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %11, i32 0, i32 1
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 i32 @setitimer(i32 %17, %struct.itimerval* %5, %struct.itimerval* %4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %1
store i32 0, i32* %2
br label %34
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 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %4, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %25, i32 0, i32 1
%27 = load i64, i64* %26
%28 = icmp ne i64 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 1, i32 0
%31 = sext i32 %30 to i64
%32 = add nsw i64 %24, %31
%33 = trunc i64 %32 to i32
store i32 %33, i32* %2
br label %34
34: ; preds = %21, %20
%35 = load i32, i32* %2
ret i32 %35
}

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 i32 @setitimer(i32 %10, %struct.itimerval* %3, %struct.itimerval* %2)
%12 = icmp eq i32 %11, -1
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 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 1
%17 = load i64, i64* %16
%18 = icmp ne i64 %17, 0
%19 = zext i1 %18 to i64
%20 = add nsw i64 %15, %19
%21 = trunc i64 %20 to i32
br label %22
22: ; preds = %1, %13
%23 = phi i32 [ %21, %13 ], [ 0, %1 ]
ret i32 %23
}