#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*/ ssize_t;
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ __ptr_t;
typedef int /*<<< orphan*/ __SOCKADDR_ARG;

/* Variables and functions */
int PTHREAD_CANCEL_ASYNCHRONOUS;
int /*<<< orphan*/ __libc_recvfrom(int, int /*<<< orphan*/, size_t, int,
                                   int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_setcanceltype(int, int *);
ssize_t __attribute__((weak))
recvfrom(int fd, __ptr_t buf, size_t n, int flags, __SOCKADDR_ARG addr,
         socklen_t *addr_len) {
  ssize_t result;
  int oldtype;
  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
  result = __libc_recvfrom(fd, buf, n, flags, addr, addr_len);
  pthread_setcanceltype(oldtype, NULL);
  return result;
}


x86 assembly (clang, -O0):
<recvfrom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1040 <pthread_setcanceltype@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x20(%rbp),%r9
call   1030 <__libc_recvfrom@plt>
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pthread_setcanceltype@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recvfrom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rsi
call   1040 <pthread_setcanceltype@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r13,%rdx
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    %r14,%r9
call   1030 <__libc_recvfrom@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_setcanceltype@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PTHREAD_CANCEL_ASYNCHRONOUS = global i32 0
define weak i32 @recvfrom(i32 %0, i32 %1, i64 %2, i32 %3, i32 %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32* %5, i32** %12
%15 = load i32, i32* @PTHREAD_CANCEL_ASYNCHRONOUS
%16 = call i32 @pthread_setcanceltype(i32 %15, i32* %14)
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = load i64, i64* %9
%20 = load i32, i32* %10
%21 = load i32, i32* %11
%22 = load i32*, i32** %12
%23 = call i32 @__libc_recvfrom(i32 %17, i32 %18, i64 %19, i32 %20, i32 %21, i32* %22)
store i32 %23, i32* %13
%24 = load i32, i32* %14
%25 = call i32 @pthread_setcanceltype(i32 %24, i32* null)
%26 = load i32, i32* %13
ret i32 %26
}

LLVM IR (-O2):
@PTHREAD_CANCEL_ASYNCHRONOUS = global i32 0
define weak i32 @recvfrom(i32 %0, i32 %1, i64 %2, i32 %3, i32 %4, i32* %5) {
%7 = alloca i32
%8 = bitcast i32* %7 to i8*
%9 = load i32, i32* @PTHREAD_CANCEL_ASYNCHRONOUS
%10 = call i32 @pthread_setcanceltype(i32 %9, i32* %7)
%11 = call i32 @__libc_recvfrom(i32 %0, i32 %1, i64 %2, i32 %3, i32 %4, i32* %5)
%12 = load i32, i32* %7
%13 = call i32 @pthread_setcanceltype(i32 %12, i32* null)
ret i32 %11
}