#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;
typedef int /*<<< orphan*/ pthread_t;

/* Variables and functions */
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ SIGUSR2;
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ pthread_kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigwait(int /*<<< orphan*/ *, int *);
void *odd(void *arg) {
  int catch;
  pthread_t target = *((pthread_t *)arg);
  int i = 1;
  sigset_t set;
  sigemptyset(&set);
  sigaddset(&set, SIGUSR1);
  while (1) {
    sigwait(&set, &catch);
    printf("Odd!: %d\n", i);
    i = i + 2;
    pthread_kill(target, SIGUSR2);
  }
}


x86 assembly (clang, -O0):
<odd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1070 <sigaddset@plt>
lea    -0x18(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <sigwait@plt>
mov    -0x14(%rbp),%esi
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
call   1040 <pthread_kill@plt>
jmp    1187 <odd+0x37>

x86 assembly (clang, -O2):
<odd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%ebx
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <sigaddset@plt>
mov    $0x1,%ebp
lea    0x4(%rsp),%r15
lea    0xe76(%rip),%r12
mov    0x2e47(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <sigwait@plt>
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x2,%ebp
mov    0x0(%r13),%esi
mov    %ebx,%edi
call   1040 <pthread_kill@plt>
jmp    11a0 <odd+0x50>

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

LLVM IR (-O2):
@SIGUSR1 = global i32 0
@.str = [10 x i8] c"Odd!: %d\0A\00"
@SIGUSR2 = global i32 0
define noalias i8* @odd(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)
br label %11
11: ; preds = %11, %1
%12 = phi i32 [ 1, %1 ], [ %15, %11 ]
%13 = call i32 @sigwait(i32* %3, i32* %2)
%14 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %12)
%15 = add nuw nsw i32 %12, 2
%16 = load i32, i32* @SIGUSR2
%17 = call i32 @pthread_kill(i32 %6, i32 %16)
br label %11
}