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

/* Variables and functions */
int PTHREAD_CANCEL_ASYNCHRONOUS;
int /*<<< orphan*/ __libc_pwrite(int, void const *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ pthread_setcanceltype(int, int *);
ssize_t __attribute__((weak))
pwrite(int fd, const void *buf, size_t n, off_t offset) {
  ssize_t result;
  int oldtype;
  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
  result = __libc_pwrite(fd, buf, n, offset);
  pthread_setcanceltype(oldtype, NULL);
  return result;
}


x86 assembly (clang, -O0):
<pwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
lea    -0x24(%rbp),%rsi
call   1040 <pthread_setcanceltype@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <__libc_pwrite@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pthread_setcanceltype@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pwrite>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2eaf(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rsi
call   1040 <pthread_setcanceltype@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <__libc_pwrite@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    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PTHREAD_CANCEL_ASYNCHRONOUS = global i32 0
define weak i32 @pwrite(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 %3, i32* %8
%11 = load i32, i32* @PTHREAD_CANCEL_ASYNCHRONOUS
%12 = call i32 @pthread_setcanceltype(i32 %11, i32* %10)
%13 = load i32, i32* %5
%14 = load i8*, i8** %6
%15 = load i64, i64* %7
%16 = load i32, i32* %8
%17 = call i32 @__libc_pwrite(i32 %13, i8* %14, i64 %15, i32 %16)
store i32 %17, i32* %9
%18 = load i32, i32* %10
%19 = call i32 @pthread_setcanceltype(i32 %18, i32* null)
%20 = load i32, i32* %9
ret i32 %20
}

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