#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 /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ SIGUSR2;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ raise(int /*<<< orphan*/);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigwait(int /*<<< orphan*/ *, int *);
void *one(void *arg) {
  int catch;
  int i = 0;
  int target = *((int *)arg);
  sigset_t signal_catch;
  sigemptyset(&signal_catch);
  sigaddset(&signal_catch, SIGUSR1);
  while (i <= target) {
    printf("Evens Waiting...\n");
    sigwait(&signal_catch, &catch);
    printf("Evens!: %d\n", i);
    i = i + 2;
    raise(SIGUSR2);
  }
}


x86 assembly (clang, -O0):
<one>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1070 <sigaddset@plt>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11db <one+0x8b>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <sigwait@plt>
mov    -0x18(%rbp),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
jmp    1187 <one+0x37>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<one>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%ebx
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1080 <sigaddset@plt>
test   %ebx,%ebx
js     11e2 <one+0x82>
mov    %rsp,%r15
lea    0x4(%rsp),%r12
lea    0xe64(%rip),%r13
mov    0x2e35(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <sigwait@plt>
mov    %r13,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x2,%ebp
mov    (%r14),%edi
call   1030 <raise@plt>
cmp    %ebx,%ebp
jle    11b0 <one+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SIGUSR1 = global i32 0
@.str = [18 x i8] c"Evens Waiting...\0A\00"
@.str.1 = [12 x i8] c"Evens!: %d\0A\00"
@SIGUSR2 = global i32 0
define i8* @one(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
%8 = load i8*, i8** %3
%9 = bitcast i8* %8 to i32*
%10 = load i32, i32* %9
store i32 %10, i32* %6
%11 = call i32 @sigemptyset(i32* %7)
%12 = load i32, i32* @SIGUSR1
%13 = call i32 @sigaddset(i32* %7, i32 %12)
br label %14
14: ; preds = %18, %1
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @sigwait(i32* %7, i32* %4)
%21 = load i32, i32* %5
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 2
store i32 %24, i32* %5
%25 = load i32, i32* @SIGUSR2
%26 = call i32 @raise(i32 %25)
br label %14
27: ; preds = %14
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@SIGUSR1 = global i32 0
@.str.1 = [12 x i8] c"Evens!: %d\0A\00"
@SIGUSR2 = global i32 0
@str = [17 x i8] c"Evens Waiting...\00"
define noalias i8* @one(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i8* %0 to i32*
%6 = load i32, i32* %5
%7 = bitcast i32* %3 to i8*
%8 = call i32 @sigemptyset(i32* %3)
%9 = load i32, i32* @SIGUSR1
%10 = call i32 @sigaddset(i32* %3, i32 %9)
%11 = icmp slt i32 %6, 0
br i1 %11, label %21, label %12
12: ; preds = %1, %12
%13 = phi i32 [ %17, %12 ], [ 0, %1 ]
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%15 = call i32 @sigwait(i32* %3, i32* %2)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%17 = add nuw nsw i32 %13, 2
%18 = load i32, i32* @SIGUSR2
%19 = call i32 @raise(i32 %18)
%20 = icmp sgt i32 %17, %6
br i1 %20, label %21, label %12
21: ; preds = %12, %1
ret i8* undef
}