void set_ipi_descriptor(void (*ipi_entry)(void)) {
  unsigned short *desc = (void *)(0x20 * sizeof(long) * 2);
  unsigned short cs;
  unsigned long ipi = (unsigned long)ipi_entry;
  asm("mov %%cs, %0" : "=r"(cs));
  desc[0] = ipi;
  desc[1] = cs;
  desc[2] = 0x8e00;
  desc[3] = ipi >> 16;
  desc[4] = ipi >> 32;
  desc[5] = ipi >> 48;
  desc[6] = 0;
  desc[7] = 0;
}


x86 assembly (clang, -O0):
<set_ipi_descriptor>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    $0x200,%eax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    %cs,%ax
mov    %ax,-0x12(%rbp)
mov    -0x20(%rbp),%rax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
mov    -0x12(%rbp),%cx
mov    -0x10(%rbp),%rax
mov    %cx,0x2(%rax)
mov    -0x10(%rbp),%rax
movw   $0x8e00,0x4(%rax)
mov    -0x20(%rbp),%rax
shr    $0x10,%rax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,0x6(%rax)
mov    -0x20(%rbp),%rax
shr    $0x20,%rax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,0x8(%rax)
mov    -0x20(%rbp),%rax
shr    $0x30,%rax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,0xa(%rax)
mov    -0x10(%rbp),%rax
movw   $0x0,0xc(%rax)
mov    -0x10(%rbp),%rax
movw   $0x0,0xe(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_ipi_descriptor>:
mov    %cs,%ax
mov    %di,0x200
mov    %ax,0x202
movw   $0x8e00,0x204
mov    %rdi,%rax
shr    $0x10,%rax
mov    %ax,0x206
mov    %rdi,%rax
shr    $0x20,%rax
mov    %ax,0x208
shr    $0x30,%rdi
mov    %di,0x20a
movw   $0x0,0x20c
movw   $0x0,0x20e
ret

LLVM IR (-O0):
define void @set_ipi_descriptor(void ()* %0) {
%2 = alloca void ()*
%3 = alloca i16*
%4 = alloca i16
%5 = alloca i64
store void ()* %0, void ()** %2
store i16* inttoptr (i64 512 to i16*), i16** %3
%6 = load void ()*, void ()** %2
%7 = ptrtoint void ()* %6 to i64
store i64 %7, i64* %5
%8 = call i16 asm "mov %cs, $0", "=r,~{dirflag},~{fpsr},~{flags}"()
store i16 %8, i16* %4
%9 = load i64, i64* %5
%10 = trunc i64 %9 to i16
%11 = load i16*, i16** %3
%12 = getelementptr inbounds i16, i16* %11, i64 0
store i16 %10, i16* %12
%13 = load i16, i16* %4
%14 = load i16*, i16** %3
%15 = getelementptr inbounds i16, i16* %14, i64 1
store i16 %13, i16* %15
%16 = load i16*, i16** %3
%17 = getelementptr inbounds i16, i16* %16, i64 2
store i16 -29184, i16* %17
%18 = load i64, i64* %5
%19 = lshr i64 %18, 16
%20 = trunc i64 %19 to i16
%21 = load i16*, i16** %3
%22 = getelementptr inbounds i16, i16* %21, i64 3
store i16 %20, i16* %22
%23 = load i64, i64* %5
%24 = lshr i64 %23, 32
%25 = trunc i64 %24 to i16
%26 = load i16*, i16** %3
%27 = getelementptr inbounds i16, i16* %26, i64 4
store i16 %25, i16* %27
%28 = load i64, i64* %5
%29 = lshr i64 %28, 48
%30 = trunc i64 %29 to i16
%31 = load i16*, i16** %3
%32 = getelementptr inbounds i16, i16* %31, i64 5
store i16 %30, i16* %32
%33 = load i16*, i16** %3
%34 = getelementptr inbounds i16, i16* %33, i64 6
store i16 0, i16* %34
%35 = load i16*, i16** %3
%36 = getelementptr inbounds i16, i16* %35, i64 7
store i16 0, i16* %36
ret void
}

LLVM IR (-O2):
define void @set_ipi_descriptor(void ()* %0) {
%2 = ptrtoint void ()* %0 to i64
%3 = tail call i16 asm "mov %cs, $0", "=r,~{dirflag},~{fpsr},~{flags}"()
%4 = trunc i64 %2 to i16
store i16 %4, i16* inttoptr (i64 512 to i16*)
store i16 %3, i16* inttoptr (i64 514 to i16*)
store i16 -29184, i16* inttoptr (i64 516 to i16*)
%5 = lshr i64 %2, 16
%6 = trunc i64 %5 to i16
store i16 %6, i16* inttoptr (i64 518 to i16*)
%7 = lshr i64 %2, 32
%8 = trunc i64 %7 to i16
store i16 %8, i16* inttoptr (i64 520 to i16*)
%9 = lshr i64 %2, 48
%10 = trunc i64 %9 to i16
store i16 %10, i16* inttoptr (i64 522 to i16*)
store i16 0, i16* inttoptr (i64 524 to i16*)
store i16 0, i16* inttoptr (i64 526 to i16*)
ret void
}