#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_3__ {
  int tv_usec;
  long tv_sec;
};
struct TYPE_4__ {
  scalar_t__ tv_sec;
  scalar_t__ tv_usec;
};
struct itimerval {
  TYPE_1__ it_value;
  TYPE_2__ 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_interval.tv_usec = 0;
  new.it_interval.tv_sec = 0;
  new.it_value.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 >= 500000 ||
      (retval == 0 && old.it_value.tv_usec > 0))
    ++retval;
  return retval;
}


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)
movl   $0x0,-0x48(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x40(%rbp)
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <__setitimer@plt>
cmp    $0x0,%rax
jge    1165 <alarm+0x55>
movl   $0x0,-0x4(%rbp)
jmp    119c <alarm+0x8c>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4c(%rbp)
cmpl   $0x7a120,-0x28(%rbp)
jge    118d <alarm+0x7d>
cmpl   $0x0,-0x4c(%rbp)
jne    1196 <alarm+0x86>
cmpl   $0x0,-0x28(%rbp)
jle    1196 <alarm+0x86>
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
movl   $0x0,0x8(%rsp)
mov    %edi,%eax
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
mov    %rax,0x10(%rsp)
mov    0x2eae(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
lea    0x28(%rsp),%rdx
call   1030 <__setitimer@plt>
test   %rax,%rax
js     1168 <alarm+0x58>
mov    0x28(%rsp),%ecx
mov    0x30(%rsp),%eax
cmp    $0x7a11f,%ecx
jg     1160 <alarm+0x50>
test   %eax,%eax
jne    1163 <alarm+0x53>
test   %ecx,%ecx
jle    1163 <alarm+0x53>
add    $0x1,%eax
add    $0x48,%rsp
ret
xor    %eax,%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
%struct.itimerval = type { %struct.TYPE_3__, %struct.TYPE_4__ }
%struct.TYPE_3__ = type { i32, i64 }
%struct.TYPE_4__ = 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_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_4__, %struct.TYPE_4__* %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_3__, %struct.TYPE_3__* %11, i32 0, i32 0
store i32 0, i32* %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_3__, %struct.TYPE_3__* %15, i32 0, i32 1
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 %43
21: ; preds = %1
%22 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %4, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i32 0, i32 1
%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_3__, %struct.TYPE_3__* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = icmp sge i32 %28, 500000
br i1 %29, label %38, label %30
30: ; preds = %21
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %4, i32 0, i32 0
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33, %21
%39 = load i32, i32* %6
%40 = add i32 %39, 1
store i32 %40, i32* %6
br label %41
41: ; preds = %38, %33, %30
%42 = load i32, i32* %6
store i32 %42, i32* %2
br label %43
43: ; preds = %41, %20
%44 = load i32, i32* %2
ret i32 %44
}

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