#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 */

/* Type definitions */
typedef int uint32_t;
typedef scalar_t__ uint16_t;
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ SIGALRM;
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sigwait(int /*<<< orphan*/ *, int *);
void timer_delay_ms(uint16_t ms) {
  int signum = 0;
  int retval = 0;
  sigset_t set;
  uint32_t counts = 0;
  sigaddset(&set, SIGALRM);
  do {
    retval = sigwait(&set, &signum);
    counts++;
  } while ((retval != -1) && ((counts) < ((uint32_t)ms * 10)));
}


x86 assembly (clang, -O0):
<timer_delay_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1040 <sigaddset@plt>
lea    -0x14(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1030 <sigwait@plt>
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x10(%rbp)
mov    %al,-0x19(%rbp)
je     118d <timer_delay_ms+0x6d>
mov    -0x18(%rbp),%eax
mov    -0x8(%rbp),%rcx
imul   $0xa,%ecx,%ecx
cmp    %ecx,%eax
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1153 <timer_delay_ms+0x33>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_delay_ms>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movl   $0x0,(%rsp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <sigaddset@plt>
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%ebp
mov    $0x1,%ebx
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <sigwait@plt>
cmp    $0xffffffff,%eax
je     1179 <timer_delay_ms+0x59>
lea    0x1(%rbx),%eax
cmp    %ebp,%ebx
mov    %eax,%ebx
jl     1160 <timer_delay_ms+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SIGALRM = global i32 0
define void @timer_delay_ms(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i64 %0, i64* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %6
%7 = load i32, i32* @SIGALRM
%8 = call i32 @sigaddset(i32* %5, i32 %7)
br label %9
9: ; preds = %22, %1
%10 = call i32 @sigwait(i32* %5, i32* %3)
store i32 %10, i32* %4
%11 = load i32, i32* %6
%12 = add nsw i32 %11, 1
store i32 %12, i32* %6
br label %13
13: ; preds = %9
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i32, i32* %6
%18 = load i64, i64* %2
%19 = trunc i64 %18 to i32
%20 = mul nsw i32 %19, 10
%21 = icmp slt i32 %17, %20
br label %22
22: ; preds = %16, %13
%23 = phi i1 [ false, %13 ], [ %21, %16 ]
br i1 %23, label %9, label %24
24: ; preds = %22
ret void
}

LLVM IR (-O2):
@SIGALRM = global i32 0
define void @timer_delay_ms(i64 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @SIGALRM
%7 = call i32 @sigaddset(i32* %3, i32 %6)
%8 = trunc i64 %0 to i32
%9 = mul nsw i32 %8, 10
br label %10
10: ; preds = %10, %1
%11 = phi i32 [ 0, %1 ], [ %13, %10 ]
%12 = call i32 @sigwait(i32* %3, i32* %2)
%13 = add nuw nsw i32 %11, 1
%14 = icmp ne i32 %12, -1
%15 = icmp slt i32 %13, %9
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %10, label %17
17: ; preds = %10
ret void
}