#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  unsigned long start;
  size_t len;
};
struct uffdio_register {
  int /*<<< orphan*/ mode;
  TYPE_1__ range;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ UFFDIO_REGISTER;
int /*<<< orphan*/ UFFDIO_REGISTER_MODE_MISSING;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, struct uffdio_register *);
int /*<<< orphan*/ perror(char *);
void register_uffd_addr(void *addr, size_t len, int fd) {
  struct uffdio_register uffdio_register;
  uffdio_register.range.start = (unsigned long)addr;
  uffdio_register.range.len = len;
  uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;
  if (ioctl(fd, UFFDIO_REGISTER, &uffdio_register) == -1) {
    do {
      perror("ioctl-UFFDIO_REGISTER");
      exit(EXIT_FAILURE);
    } while (0);
  }
}


x86 assembly (clang, -O0):
<register_uffd_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    119c <register_uffd_addr+0x6c>
jmp    1182 <register_uffd_addr+0x52>
lea    0xe77(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<register_uffd_addr>:
sub    $0x18,%rsp
mov    %edx,%eax
mov    %rdi,0x8(%rsp)
mov    %rsi,0x10(%rsp)
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rsp)
mov    0x2e85(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1169 <register_uffd_addr+0x39>
add    $0x18,%rsp
ret
lea    0xe90(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.uffdio_register = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
@UFFDIO_REGISTER_MODE_MISSING = global i32 0
@UFFDIO_REGISTER = global i32 0
@.str = [22 x i8] c"ioctl-UFFDIO_REGISTER\00"
@EXIT_FAILURE = global i32 0
define void @register_uffd_addr(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.uffdio_register
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = ptrtoint i8* %8 to i64
%10 = getelementptr inbounds %struct.uffdio_register, %struct.uffdio_register* %7, i32 0, i32 1
%11 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %10, i32 0, i32 0
store i64 %9, i64* %11
%12 = load i64, i64* %5
%13 = getelementptr inbounds %struct.uffdio_register, %struct.uffdio_register* %7, i32 0, i32 1
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 1
store i64 %12, i64* %14
%15 = load i32, i32* @UFFDIO_REGISTER_MODE_MISSING
%16 = getelementptr inbounds %struct.uffdio_register, %struct.uffdio_register* %7, i32 0, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* %6
%18 = load i32, i32* @UFFDIO_REGISTER
%19 = call i32 @ioctl(i32 %17, i32 %18, %struct.uffdio_register* %7)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %27
21: ; preds = %3
br label %22
22: ; preds = %21
%23 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; No predecessors!
br label %27
27: ; preds = %26, %3
ret void
}

LLVM IR (-O2):
%struct.uffdio_register = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
@UFFDIO_REGISTER_MODE_MISSING = global i32 0
@UFFDIO_REGISTER = global i32 0
@.str = [22 x i8] c"ioctl-UFFDIO_REGISTER\00"
@EXIT_FAILURE = global i32 0
define void @register_uffd_addr(i8* %0, i64 %1, i32 %2) {
%4 = alloca %struct.uffdio_register
%5 = bitcast %struct.uffdio_register* %4 to i8*
%6 = ptrtoint i8* %0 to i64
%7 = getelementptr inbounds %struct.uffdio_register, %struct.uffdio_register* %4, i64 0, i32 1, i32 0
store i64 %6, i64* %7
%8 = getelementptr inbounds %struct.uffdio_register, %struct.uffdio_register* %4, i64 0, i32 1, i32 1
store i64 %1, i64* %8
%9 = load i32, i32* @UFFDIO_REGISTER_MODE_MISSING
%10 = getelementptr inbounds %struct.uffdio_register, %struct.uffdio_register* %4, i64 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @UFFDIO_REGISTER
%12 = call i32 @ioctl(i32 %2, i32 %11, %struct.uffdio_register* %4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %3
ret void
}