unsigned _alarm(n)
unsigned n;
{
  struct {
    long l1, l2, l3, l4;
  } t1, t2;
  t1.l1 = 0;
  t1.l2 = 0;
  t1.l4 = 0;
  t1.l3 = n;
  if (_setitimer(0, &t1, &t2) < 0)
    return -1;
  if (t2.l4)
    t2.l3++;
  return t2.l3;
}


x86 assembly (clang, -O0):
<_alarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x18(%rbp)
xor    %edi,%edi
lea    -0x28(%rbp),%rsi
lea    -0x48(%rbp),%rdx
mov    $0x0,%al
call   1030 <_setitimer@plt>
cmp    $0x0,%eax
jge    1160 <_alarm+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    117e <_alarm+0x6e>
cmpq   $0x0,-0x30(%rbp)
je     1177 <_alarm+0x67>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_alarm>:
sub    $0x48,%rsp
movq   $0x0,0x18(%rsp)
mov    %edi,%eax
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    %rax,0x10(%rsp)
mov    %rsp,%rsi
lea    0x28(%rsp),%rdx
xor    %edi,%edi
xor    %eax,%eax
call   1030 <_setitimer@plt>
test   %eax,%eax
js     1152 <_alarm+0x42>
mov    0x38(%rsp),%eax
cmpq   $0x1,0x40(%rsp)
sbb    $0xffffffff,%eax
add    $0x48,%rsp
ret
mov    $0xffffffff,%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
%struct.anon = type { i64, i64, i64, i64 }
define i32 @_alarm(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.anon
%5 = alloca %struct.anon
store i32 %0, i32* %3
%6 = getelementptr inbounds %struct.anon, %struct.anon* %4, i32 0, i32 0
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.anon, %struct.anon* %4, i32 0, i32 1
store i64 0, i64* %7
%8 = getelementptr inbounds %struct.anon, %struct.anon* %4, i32 0, i32 3
store i64 0, i64* %8
%9 = load i32, i32* %3
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds %struct.anon, %struct.anon* %4, i32 0, i32 2
store i64 %10, i64* %11
%12 = call i32 (i32, %struct.anon*, %struct.anon*, ...) bitcast (i32 (...)* @_setitimer to i32 (i32, %struct.anon*, %struct.anon*, ...)*)(i32 0, %struct.anon* %4, %struct.anon* %5)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 -1, i32* %2
br label %27
15: ; preds = %1
%16 = getelementptr inbounds %struct.anon, %struct.anon* %5, i32 0, i32 3
%17 = load i64, i64* %16
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = getelementptr inbounds %struct.anon, %struct.anon* %5, i32 0, i32 2
%21 = load i64, i64* %20
%22 = add nsw i64 %21, 1
store i64 %22, i64* %20
br label %23
23: ; preds = %19, %15
%24 = getelementptr inbounds %struct.anon, %struct.anon* %5, i32 0, i32 2
%25 = load i64, i64* %24
%26 = trunc i64 %25 to i32
store i32 %26, i32* %2
br label %27
27: ; preds = %23, %14
%28 = load i32, i32* %2
ret i32 %28
}

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