// File: ctSkennerton[P]fxtract/util/thread_x.c
// Function: main
int main(void)
{
    start = tick();
    setvbuf(stderr, NULL, _IOLBF, 0);

    FLAG   *flag = flag_create();
    THREAD *thrd = thread_start(flagging, flag);

    int rc;
#undef  TRY
#define TRY(x) diag(#x " ...\n"); rc = (intptr_t)(x); diag(#x ": %d %s", rc, errname[errno])
    TRY(flag_watch(flag, 0));
    TRY(flag_watch(flag, 0.5));
    TRY(flag_watch(flag, 0.5));
    TRY(sleep(1));

    thread_result(thrd);

    thrd = thread_start(sleeping, flag);
    TRY(thread_cancel(thrd));
    TRY(thread_result(thrd));

    flag_destroy(flag);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
callq 0x5990
movsd %xmm0, 0x728c(%rip)     # 0xa7f8
movq 0x6a6d(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %ecx
movl $0x1, %edx
movq %rcx, %rsi
callq 0x3040
callq 0x5a40
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x1f5(%rip), %rdi       # 0x3790
callq 0x5c40
movq %rax, -0x18(%rbp)
leaq 0x3a65(%rip), %rdi      # 0x7010
movb $0x0, %al
callq 0x3820
movq -0x10(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x5b10
cltq
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x34(%rbp)
callq 0x3050
movl -0x34(%rbp), %esi
movslq (%rax), %rcx
leaq 0x6c65(%rip), %rax      # 0xa240
movq (%rax,%rcx,8), %rdx
leaq 0x3a43(%rip), %rdi      # 0x7029
movb $0x0, %al
callq 0x3820
leaq 0x3a50(%rip), %rdi      # 0x7044
movb $0x0, %al
callq 0x3820
movq -0x10(%rbp), %rdi
movsd 0x3a01(%rip), %xmm0     # 0x7008
callq 0x5b10
cltq
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x30(%rbp)
callq 0x3050
movl -0x30(%rbp), %esi
movslq (%rax), %rcx
leaq 0x6c17(%rip), %rax      # 0xa240
movq (%rax,%rcx,8), %rdx
leaq 0x3a2b(%rip), %rdi      # 0x705f
movb $0x0, %al
callq 0x3820
leaq 0x3a02(%rip), %rdi      # 0x7044
movb $0x0, %al
callq 0x3820
movq -0x10(%rbp), %rdi
movsd 0x39b3(%rip), %xmm0     # 0x7008
callq 0x5b10
cltq
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
callq 0x3050
movl -0x2c(%rbp), %esi
movslq (%rax), %rcx
leaq 0x6bc9(%rip), %rax      # 0xa240
movq (%rax,%rcx,8), %rdx
leaq 0x39dd(%rip), %rdi      # 0x705f
movb $0x0, %al
callq 0x3820
leaq 0x39ec(%rip), %rdi      # 0x707c
movb $0x0, %al
callq 0x3820
movl $0x1, %edi
callq 0x3160
movl %eax, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x28(%rbp)
callq 0x3050
movl -0x28(%rbp), %esi
movslq (%rax), %rcx
leaq 0x6b82(%rip), %rax      # 0xa240
movq (%rax,%rcx,8), %rdx
leaq 0x39c1(%rip), %rdi      # 0x708a
movb $0x0, %al
callq 0x3820
movq -0x18(%rbp), %rdi
callq 0x5d00
movq -0x10(%rbp), %rsi
leaq 0x22c(%rip), %rdi       # 0x3910
callq 0x5c40
movq %rax, -0x18(%rbp)
leaq 0x39a6(%rip), %rdi      # 0x709a
movb $0x0, %al
callq 0x3820
movq -0x18(%rbp), %rdi
callq 0x5cb0
cltq
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
callq 0x3050
movl -0x24(%rbp), %esi
movslq (%rax), %rcx
leaq 0x6b1f(%rip), %rax      # 0xa240
movq (%rax,%rcx,8), %rdx
leaq 0x3987(%rip), %rdi      # 0x70b3
movb $0x0, %al
callq 0x3820
leaq 0x3994(%rip), %rdi      # 0x70ce
movb $0x0, %al
callq 0x3820
movq -0x18(%rbp), %rdi
callq 0x5d00
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
callq 0x3050
movl -0x20(%rbp), %esi
movslq (%rax), %rcx
leaq 0x6adb(%rip), %rax      # 0xa240
movq (%rax,%rcx,8), %rdx
leaq 0x3977(%rip), %rdi      # 0x70e7
movb $0x0, %al
callq 0x3820
movq -0x10(%rbp), %rdi
callq 0x5a90
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)