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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ pthread_cancel(int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ write(int, char *, int);
void *thread_canceler(void *a) {
  sleep(3);
  write(1, "<send cancel> ", sizeof("<send cancel> ") - 1);
  if (pthread_cancel(*((pthread_t *)a))) {
    do {
      write(2, "cancel error\n", sizeof("cancel error\n") - 1);
      exit(2);
    } while (0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<thread_canceler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x3,%edi
call   1060 <sleep@plt>
mov    $0x1,%edi
lea    0xe9e(%rip),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <pthread_cancel@plt>
cmp    $0x0,%rax
je     11a6 <thread_canceler+0x66>
jmp    1186 <thread_canceler+0x46>
mov    $0x2,%edi
lea    0xe7d(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1040 <exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_canceler>:
push   %rbx
mov    %rdi,%rbx
mov    $0x3,%edi
call   1060 <sleep@plt>
lea    0xeab(%rip),%rsi
mov    $0x1,%edi
mov    $0xe,%edx
call   1030 <write@plt>
mov    (%rbx),%edi
call   1050 <pthread_cancel@plt>
test   %rax,%rax
jne    1174 <thread_canceler+0x34>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe94(%rip),%rsi
mov    $0x2,%edi
mov    $0xd,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"<send cancel> \00"
@.str.1 = [14 x i8] c"cancel error\0A\00"
define i8* @thread_canceler(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 @sleep(i32 3)
%4 = call i32 @write(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 14)
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to i32*
%7 = load i32, i32* %6
%8 = call i64 @pthread_cancel(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1
br label %11
11: ; preds = %10
%12 = call i32 @write(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 13)
%13 = call i32 @exit(i32 2)
unreachable
14: ; No predecessors!
br label %15
15: ; preds = %14, %1
ret i8* null
}

LLVM IR (-O2):
@.str = [15 x i8] c"<send cancel> \00"
@.str.1 = [14 x i8] c"cancel error\0A\00"
define noalias i8* @thread_canceler(i8* nocapture %0) {
%2 = tail call i32 @sleep(i32 3)
%3 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 14)
%4 = bitcast i8* %0 to i32*
%5 = load i32, i32* %4
%6 = tail call i64 @pthread_cancel(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 13)
%10 = tail call i32 @exit(i32 2)
unreachable
11: ; preds = %1
ret i8* null
}