void *kill_pointer(void *stub) {
  int *ptr = (int *)((int)stub + 8);
  int *ptr2 = (int *)((int)stub + 12);
  assert((*ptr & 0x0ff00000) == 0x03000000);
  assert((*ptr2 & 0x0ff00000) == 0x03400000);
  int *i_ptr = (int *)((*ptr & 0xfff) | ((*ptr >> 4) & 0xf000) |
                       ((*ptr2 & 0xfff) << 16) | ((*ptr2 & 0xf0000) << 12));
  assert((*i_ptr & 0x0f000000) == 0x0a000000);
  set_jump_target((int)i_ptr, (int)stub);
  return i_ptr;
}


x86 assembly (clang, -O0):
<kill_pointer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0xff00000,%eax
cmp    $0x3000000,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0xff00000,%eax
cmp    $0x3400000,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0xfff,%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sar    $0x4,%ecx
and    $0xf000,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
and    $0xfff,%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
and    $0xf0000,%ecx
shl    $0xc,%ecx
or     %ecx,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
and    $0xf000000,%eax
cmp    $0xa000000,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
mov    -0x8(%rbp),%rax
mov    %eax,%esi
mov    $0x0,%al
call   1040 <set_jump_target@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_pointer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rdi,%rax
shl    $0x20,%rax
movabs $0x800000000,%rbx
add    %rax,%rbx
sar    $0x20,%rbx
movabs $0xc00000000,%r15
add    %rax,%r15
sar    $0x20,%r15
mov    $0xff00000,%ebp
mov    (%rbx),%eax
and    %ebp,%eax
xor    %edi,%edi
cmp    $0x3000000,%eax
sete   %dil
xor    %eax,%eax
call   1030 <assert@plt>
and    (%r15),%ebp
xor    %edi,%edi
cmp    $0x3400000,%ebp
sete   %dil
xor    %eax,%eax
call   1030 <assert@plt>
mov    (%rbx),%eax
mov    %eax,%ecx
and    $0xfff,%ecx
shr    $0x4,%eax
and    $0xf000,%eax
or     %ecx,%eax
mov    (%r15),%ecx
mov    %ecx,%edx
shl    $0x10,%edx
and    $0xfff0000,%edx
or     %eax,%edx
shl    $0xc,%ecx
and    $0xf0000000,%ecx
or     %edx,%ecx
movslq %ecx,%rbx
mov    $0xf000000,%eax
and    (%rbx),%eax
xor    %edi,%edi
cmp    $0xa000000,%eax
sete   %dil
xor    %eax,%eax
call   1030 <assert@plt>
mov    %ebx,%edi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <set_jump_target@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @kill_pointer(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = ptrtoint i8* %6 to i32
%8 = add nsw i32 %7, 8
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %3
%11 = load i8*, i8** %2
%12 = ptrtoint i8* %11 to i32
%13 = add nsw i32 %12, 12
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %4
%16 = load i32*, i32** %3
%17 = load i32, i32* %16
%18 = and i32 %17, 267386880
%19 = icmp eq i32 %18, 50331648
%20 = zext i1 %19 to i32
%21 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %20)
%22 = load i32*, i32** %4
%23 = load i32, i32* %22
%24 = and i32 %23, 267386880
%25 = icmp eq i32 %24, 54525952
%26 = zext i1 %25 to i32
%27 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %26)
%28 = load i32*, i32** %3
%29 = load i32, i32* %28
%30 = and i32 %29, 4095
%31 = load i32*, i32** %3
%32 = load i32, i32* %31
%33 = ashr i32 %32, 4
%34 = and i32 %33, 61440
%35 = or i32 %30, %34
%36 = load i32*, i32** %4
%37 = load i32, i32* %36
%38 = and i32 %37, 4095
%39 = shl i32 %38, 16
%40 = or i32 %35, %39
%41 = load i32*, i32** %4
%42 = load i32, i32* %41
%43 = and i32 %42, 983040
%44 = shl i32 %43, 12
%45 = or i32 %40, %44
%46 = sext i32 %45 to i64
%47 = inttoptr i64 %46 to i32*
store i32* %47, i32** %5
%48 = load i32*, i32** %5
%49 = load i32, i32* %48
%50 = and i32 %49, 251658240
%51 = icmp eq i32 %50, 167772160
%52 = zext i1 %51 to i32
%53 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %52)
%54 = load i32*, i32** %5
%55 = ptrtoint i32* %54 to i32
%56 = load i8*, i8** %2
%57 = ptrtoint i8* %56 to i32
%58 = call i32 (i32, i32, ...) bitcast (i32 (...)* @set_jump_target to i32 (i32, i32, ...)*)(i32 %55, i32 %57)
%59 = load i32*, i32** %5
%60 = bitcast i32* %59 to i8*
ret i8* %60
}

LLVM IR (-O2):
define i8* @kill_pointer(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
%4 = shl i64 %2, 32
%5 = add i64 %4, 34359738368
%6 = ashr exact i64 %5, 32
%7 = inttoptr i64 %6 to i32*
%8 = add i64 %4, 51539607552
%9 = ashr exact i64 %8, 32
%10 = inttoptr i64 %9 to i32*
%11 = load i32, i32* %7
%12 = and i32 %11, 267386880
%13 = icmp eq i32 %12, 50331648
%14 = zext i1 %13 to i32
%15 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %14)
%16 = load i32, i32* %10
%17 = and i32 %16, 267386880
%18 = icmp eq i32 %17, 54525952
%19 = zext i1 %18 to i32
%20 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %19)
%21 = load i32, i32* %7
%22 = and i32 %21, 4095
%23 = lshr i32 %21, 4
%24 = and i32 %23, 61440
%25 = or i32 %24, %22
%26 = load i32, i32* %10
%27 = shl i32 %26, 16
%28 = and i32 %27, 268369920
%29 = or i32 %25, %28
%30 = shl i32 %26, 12
%31 = and i32 %30, -268435456
%32 = or i32 %29, %31
%33 = sext i32 %32 to i64
%34 = inttoptr i64 %33 to i32*
%35 = load i32, i32* %34
%36 = and i32 %35, 251658240
%37 = icmp eq i32 %36, 167772160
%38 = zext i1 %37 to i32
%39 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %38)
%40 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @set_jump_target to i32 (i32, i32, ...)*)(i32 %32, i32 %3)
%41 = inttoptr i64 %33 to i8*
ret i8* %41
}