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

/* Variables and functions */
scalar_t__ sigsetjmp(int /*<<< orphan*/, int);
void stub1(void *, void const *, int);
unsigned long __do_user_copy(void *to, const void *from, int n,
                             void **fault_addr, void **fault_catcher,
                             void (*op)(void *to, const void *from, int n),
                             int *faulted_out) {
  unsigned long *faddrp = (unsigned long *)fault_addr, ret;
  sigjmp_buf jbuf;
  *fault_catcher = &jbuf;
  if (sigsetjmp(jbuf, 1) == 0) {
    (*op)(to, from, n);
    ret = 0;
    *faulted_out = 0;
  } else {
    ret = *faddrp;
    *faulted_out = 1;
  }
  *fault_addr = NULL;
  *fault_catcher = NULL;
  return ret;
}


x86 assembly (clang, -O0):
<__do_user_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x44(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x44(%rbp),%edi
mov    $0x1,%esi
call   1030 <sigsetjmp@plt>
cmp    $0x0,%rax
jne    1185 <__do_user_copy+0x75>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   *%rax
movq   $0x0,-0x40(%rbp)
mov    0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    119a <__do_user_copy+0x8a>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__do_user_copy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x8(%rsp)
mov    %r8,%rbx
mov    %rcx,%r14
mov    %edx,%r12d
mov    %rsi,%r13
mov    %rdi,%rbp
lea    0x14(%rsp),%rax
mov    %rax,(%r8)
mov    $0x1,%r15d
mov    $0x1,%esi
call   1030 <sigsetjmp@plt>
test   %rax,%rax
je     1154 <__do_user_copy+0x44>
mov    (%r14),%rax
jmp    1166 <__do_user_copy+0x56>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   *0x8(%rsp)
xor    %r15d,%r15d
xor    %eax,%eax
mov    0x50(%rsp),%rcx
mov    %r15d,(%rcx)
movq   $0x0,(%r14)
movq   $0x0,(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @__do_user_copy(i8* %0, i8* %1, i32 %2, i8** %3, i8** %4, void (i8*, i8*, i32)* %5, i32* %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8**
%12 = alloca i8**
%13 = alloca void (i8*, i8*, i32)*
%14 = alloca i32*
%15 = alloca i64*
%16 = alloca i64
%17 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i8** %3, i8*** %11
store i8** %4, i8*** %12
store void (i8*, i8*, i32)* %5, void (i8*, i8*, i32)** %13
store i32* %6, i32** %14
%18 = load i8**, i8*** %11
%19 = bitcast i8** %18 to i64*
store i64* %19, i64** %15
%20 = bitcast i32* %17 to i8*
%21 = load i8**, i8*** %12
store i8* %20, i8** %21
%22 = load i32, i32* %17
%23 = call i64 @sigsetjmp(i32 %22, i32 1)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %7
%26 = load void (i8*, i8*, i32)*, void (i8*, i8*, i32)** %13
%27 = load i8*, i8** %8
%28 = load i8*, i8** %9
%29 = load i32, i32* %10
store i64 0, i64* %16
%30 = load i32*, i32** %14
store i32 0, i32* %30
br label %35
31: ; preds = %7
%32 = load i64*, i64** %15
%33 = load i64, i64* %32
store i64 %33, i64* %16
%34 = load i32*, i32** %14
store i32 1, i32* %34
br label %35
35: ; preds = %31, %25
%36 = load i8**, i8*** %11
store i8* null, i8** %36
%37 = load i8**, i8*** %12
store i8* null, i8** %37
%38 = load i64, i64* %16
ret i64 %38
}

LLVM IR (-O2):
define i64 @__do_user_copy(i8* %0, i8* %1, i32 %2, i8** nocapture %3, i8** nocapture writeonly %4, void (i8*, i8*, i32)* nocapture %5, i32* nocapture writeonly %6) {
%8 = alloca i32
%9 = bitcast i32* %8 to i8*
%10 = bitcast i8** %4 to i32**
store i32* %8, i32** %10
%11 = call i64 @sigsetjmp(i32 undef, i32 1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %7
br label %17
14: ; preds = %7
%15 = bitcast i8** %3 to i64*
%16 = load i64, i64* %15
br label %17
17: ; preds = %14, %13
%18 = phi i32 [ 1, %14 ], [ 0, %13 ]
%19 = phi i64 [ %16, %14 ], [ 0, %13 ]
store i32 %18, i32* %6
store i8* null, i8** %3
store i8* null, i8** %4
ret i64 %19
}