void *kill_pointer(void *stub) {
  int *ptr = (int *)(stub + 8);
  int *ptr2 = (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,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc,%rax
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   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0xff00000,%ebx
mov    0x8(%rdi),%eax
and    %ebx,%eax
xor    %edi,%edi
cmp    $0x3000000,%eax
sete   %dil
xor    %eax,%eax
call   1030 <assert@plt>
and    0xc(%r14),%ebx
xor    %edi,%edi
cmp    $0x3400000,%ebx
sete   %dil
xor    %eax,%eax
call   1030 <assert@plt>
mov    0x8(%r14),%eax
mov    0xc(%r14),%ecx
mov    %eax,%edx
and    $0xfff,%edx
shr    $0x4,%eax
and    $0xf000,%eax
or     %edx,%eax
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
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 = getelementptr i8, i8* %6, i64 8
%8 = bitcast i8* %7 to i32*
store i32* %8, i32** %3
%9 = load i8*, i8** %2
%10 = getelementptr i8, i8* %9, i64 12
%11 = bitcast i8* %10 to i32*
store i32* %11, i32** %4
%12 = load i32*, i32** %3
%13 = load i32, i32* %12
%14 = and i32 %13, 267386880
%15 = icmp eq i32 %14, 50331648
%16 = zext i1 %15 to i32
%17 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %16)
%18 = load i32*, i32** %4
%19 = load i32, i32* %18
%20 = and i32 %19, 267386880
%21 = icmp eq i32 %20, 54525952
%22 = zext i1 %21 to i32
%23 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %22)
%24 = load i32*, i32** %3
%25 = load i32, i32* %24
%26 = and i32 %25, 4095
%27 = load i32*, i32** %3
%28 = load i32, i32* %27
%29 = ashr i32 %28, 4
%30 = and i32 %29, 61440
%31 = or i32 %26, %30
%32 = load i32*, i32** %4
%33 = load i32, i32* %32
%34 = and i32 %33, 4095
%35 = shl i32 %34, 16
%36 = or i32 %31, %35
%37 = load i32*, i32** %4
%38 = load i32, i32* %37
%39 = and i32 %38, 983040
%40 = shl i32 %39, 12
%41 = or i32 %36, %40
%42 = sext i32 %41 to i64
%43 = inttoptr i64 %42 to i32*
store i32* %43, i32** %5
%44 = load i32*, i32** %5
%45 = load i32, i32* %44
%46 = and i32 %45, 251658240
%47 = icmp eq i32 %46, 167772160
%48 = zext i1 %47 to i32
%49 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %48)
%50 = load i32*, i32** %5
%51 = ptrtoint i32* %50 to i32
%52 = load i8*, i8** %2
%53 = ptrtoint i8* %52 to i32
%54 = call i32 (i32, i32, ...) bitcast (i32 (...)* @set_jump_target to i32 (i32, i32, ...)*)(i32 %51, i32 %53)
%55 = load i32*, i32** %5
%56 = bitcast i32* %55 to i8*
ret i8* %56
}

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