#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;
  int /*<<< orphan*/ tv_usec;
};
struct itimerval {
  TYPE_1__ it_value;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
int /*<<< orphan*/ setitimer(int /*<<< orphan*/, struct itimerval *,
                             struct itimerval *);
unsigned alarm(unsigned seconds) {
  struct itimerval it = {.it_value.tv_sec = seconds}, old = {0};
  setitimer(ITIMER_REAL, &it, &old);
  return old.it_value.tv_sec + !!old.it_value.tv_usec;
}


x86 assembly (clang, -O0):
<alarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <setitimer@plt>
mov    -0x20(%rbp),%eax
cmpl   $0x0,-0x1c(%rbp)
setne  %cl
xor    $0xff,%cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alarm>:
sub    $0x28,%rsp
mov    %edi,0x18(%rsp)
movq   $0x0,0x1c(%rsp)
movl   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2ea7(%rip),%rax
mov    (%rax),%edi
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1030 <setitimer@plt>
mov    0x8(%rsp),%eax
cmpl   $0x1,0xc(%rsp)
sbb    $0xffffffff,%eax
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
%struct.itimerval = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i32 }
@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 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 0
store i32 %0, i32* %5
%6 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 1
store i32 0, i32* %6
%7 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 1
store i32 0, i32* %7
%8 = bitcast %struct.itimerval* %3 to i8*
%9 = load i32, i32* @ITIMER_REAL
%10 = call i32 @setitimer(i32 %9, %struct.itimerval* %2, %struct.itimerval* %3)
%11 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 1
%14 = load i32, i32* %13
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i32
%17 = add i32 %12, %16
ret i32 %17
}