#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 drcom_handle {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_CANCEL_ASYNCHRONOUS;
int /*<<< orphan*/ PTHREAD_CANCEL_ENABLE;
int /*<<< orphan*/ block_sigusr1();
int /*<<< orphan*/ drcom_keepalive(struct drcom_handle *);
int /*<<< orphan*/ loginfo(char *);
int /*<<< orphan*/ pthread_setcancelstate(int /*<<< orphan*/,
                                          int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_setcanceltype(int /*<<< orphan*/,
                                         int /*<<< orphan*/ *);
void *daemon_keepalive(void *arg) {
  block_sigusr1();
  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
  drcom_keepalive((struct drcom_handle *)arg);
  loginfo("keepalive returns\n");
  return NULL;
}


x86 assembly (clang, -O0):
<daemon_keepalive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <block_sigusr1@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <pthread_setcancelstate@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <pthread_setcanceltype@plt>
mov    -0x8(%rbp),%rdi
call   1060 <drcom_keepalive@plt>
lea    0xe69(%rip),%rdi
call   1030 <loginfo@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemon_keepalive>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <block_sigusr1@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <pthread_setcancelstate@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1070 <pthread_setcanceltype@plt>
mov    %rbx,%rdi
call   1060 <drcom_keepalive@plt>
lea    0xe76(%rip),%rdi
call   1030 <loginfo@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.drcom_handle = type { i32 }
@PTHREAD_CANCEL_ENABLE = global i32 0
@PTHREAD_CANCEL_ASYNCHRONOUS = global i32 0
@.str = [19 x i8] c"keepalive returns\0A\00"
define i8* @daemon_keepalive(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 (...) @block_sigusr1()
%4 = load i32, i32* @PTHREAD_CANCEL_ENABLE
%5 = call i32 @pthread_setcancelstate(i32 %4, i32* null)
%6 = load i32, i32* @PTHREAD_CANCEL_ASYNCHRONOUS
%7 = call i32 @pthread_setcanceltype(i32 %6, i32* null)
%8 = load i8*, i8** %2
%9 = bitcast i8* %8 to %struct.drcom_handle*
%10 = call i32 @drcom_keepalive(%struct.drcom_handle* %9)
%11 = call i32 @loginfo(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
ret i8* null
}

LLVM IR (-O2):
%struct.drcom_handle = type { i32 }
@PTHREAD_CANCEL_ENABLE = global i32 0
@PTHREAD_CANCEL_ASYNCHRONOUS = global i32 0
@.str = [19 x i8] c"keepalive returns\0A\00"
define noalias i8* @daemon_keepalive(i8* %0) {
%2 = tail call i32 (...) @block_sigusr1()
%3 = load i32, i32* @PTHREAD_CANCEL_ENABLE
%4 = tail call i32 @pthread_setcancelstate(i32 %3, i32* null)
%5 = load i32, i32* @PTHREAD_CANCEL_ASYNCHRONOUS
%6 = tail call i32 @pthread_setcanceltype(i32 %5, i32* null)
%7 = bitcast i8* %0 to %struct.drcom_handle*
%8 = tail call i32 @drcom_keepalive(%struct.drcom_handle* %7)
%9 = tail call i32 @loginfo(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
ret i8* null
}