#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 */
struct timespec {
  int dummy;
};
typedef int /*<<< orphan*/ sigset_t;
typedef int /*<<< orphan*/ siginfo_t;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int syscall_cp(int, int /*<<< orphan*/ const *, int /*<<< orphan*/ *,
               struct timespec const *, int);
int sigtimedwait(const sigset_t *mask, siginfo_t *si,
                 const struct timespec *timeout) {
  int ret;
  do
    ret = syscall_cp(128, mask, si, timeout, 8);
  while (ret < 0 && errno == EINTR);
  return ret;
}


x86 assembly (clang, -O0):
<sigtimedwait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x80,%edi
mov    $0x8,%r8d
call   1030 <syscall_cp@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jge    116c <sigtimedwait+0x5c>
mov    0x2e87(%rip),%rax
mov    (%rax),%rax
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1124 <sigtimedwait+0x14>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigtimedwait>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2eb7(%rip),%r12
mov    0x2ea8(%rip),%r13
mov    $0x80,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    $0x8,%r8d
call   1030 <syscall_cp@plt>
test   %eax,%eax
jns    1157 <sigtimedwait+0x47>
mov    0x0(%r13),%rcx
cmp    %rcx,(%r12)
je     1130 <sigtimedwait+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @sigtimedwait(i32* %0, i32* %1, %struct.timespec* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca %struct.timespec*
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store %struct.timespec* %2, %struct.timespec** %6
br label %8
8: ; preds = %20, %3
%9 = load i32*, i32** %4
%10 = load i32*, i32** %5
%11 = load %struct.timespec*, %struct.timespec** %6
%12 = call i32 @syscall_cp(i32 128, i32* %9, i32* %10, %struct.timespec* %11, i32 8)
store i32 %12, i32* %7
br label %13
13: ; preds = %8
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i64, i64* @errno
%18 = load i64, i64* @EINTR
%19 = icmp eq i64 %17, %18
br label %20
20: ; preds = %16, %13
%21 = phi i1 [ false, %13 ], [ %19, %16 ]
br i1 %21, label %8, label %22
22: ; preds = %20
%23 = load i32, i32* %7
ret i32 %23
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @sigtimedwait(i32* %0, i32* %1, %struct.timespec* %2) {
br label %4
4: ; preds = %4, %3
%5 = tail call i32 @syscall_cp(i32 128, i32* %0, i32* %1, %struct.timespec* %2, i32 8)
%6 = icmp slt i32 %5, 0
%7 = load i64, i64* @errno
%8 = load i64, i64* @EINTR
%9 = icmp eq i64 %7, %8
%10 = select i1 %6, i1 %9, i1 false
br i1 %10, label %4, label %11
11: ; preds = %4
ret i32 %5
}