void i_install(unsigned char vector, void (*func)(), unsigned char type) {
  char *idt_table = (char *)0x100000;
  unsigned char i;
  unsigned char b[8];
  b[0] = (unsigned int)func & 0x000000FF;
  b[1] = ((unsigned int)func & 0x0000FF00) >> 8;
  b[2] = 0x8;
  b[3] = 0;
  b[4] = 0;
  b[5] = type;
  b[6] = ((unsigned int)func & 0x00FF0000) >> 16;
  b[7] = ((unsigned int)func & 0xFF000000) >> 24;
  for (i = 0; i < 8; i++) {
    *(idt_table + vector * 8 + i) = b[i];
  }
}


x86 assembly (clang, -O0):
<i_install>:
push   %rbp
mov    %rsp,%rbp
mov    %dl,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    $0x100000,%eax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
and    $0xff,%eax
mov    %al,-0x29(%rbp)
mov    -0x10(%rbp),%rax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %al,-0x28(%rbp)
movb   $0x8,-0x27(%rbp)
movb   $0x0,-0x26(%rbp)
movb   $0x0,-0x25(%rbp)
mov    -0x11(%rbp),%al
mov    %al,-0x24(%rbp)
mov    -0x10(%rbp),%rax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %al,-0x23(%rbp)
mov    -0x10(%rbp),%rax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,-0x22(%rbp)
movb   $0x0,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
cmp    $0x8,%eax
jge    11a8 <i_install+0xa8>
movzbl -0x21(%rbp),%eax
mov    -0x29(%rbp,%rax,1),%dl
mov    -0x20(%rbp),%rax
movzbl -0x1(%rbp),%ecx
shl    $0x3,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
movzbl -0x21(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x21(%rbp),%al
add    $0x1,%al
mov    %al,-0x21(%rbp)
jmp    116b <i_install+0x6b>
pop    %rbp
ret

x86 assembly (clang, -O2):
<i_install>:
mov    %rsi,%rax
mov    %rsi,%rcx
mov    %edi,%esi
mov    %al,0x100000(,%rsi,8)
mov    %ah,0x100001(,%rsi,8)
shr    $0x10,%rax
shr    $0x18,%rcx
movw   $0x8,0x100002(,%rsi,8)
movb   $0x0,0x100004(,%rsi,8)
mov    %dl,0x100005(,%rsi,8)
mov    %al,0x100006(,%rsi,8)
mov    %cl,0x100007(,%rsi,8)
ret

LLVM IR (-O0):
define void @i_install(i8 zeroext %0, void (...)* %1, i8 zeroext %2) {
%4 = alloca i8
%5 = alloca void (...)*
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8
%9 = alloca [8 x i8]
store i8 %0, i8* %4
store void (...)* %1, void (...)** %5
store i8 %2, i8* %6
store i8* inttoptr (i64 1048576 to i8*), i8** %7
%10 = load void (...)*, void (...)** %5
%11 = ptrtoint void (...)* %10 to i32
%12 = and i32 %11, 255
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
store i8 %13, i8* %14
%15 = load void (...)*, void (...)** %5
%16 = ptrtoint void (...)* %15 to i32
%17 = and i32 %16, 65280
%18 = lshr i32 %17, 8
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 1
store i8 %19, i8* %20
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 2
store i8 8, i8* %21
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 3
store i8 0, i8* %22
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 4
store i8 0, i8* %23
%24 = load i8, i8* %6
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 5
store i8 %24, i8* %25
%26 = load void (...)*, void (...)** %5
%27 = ptrtoint void (...)* %26 to i32
%28 = and i32 %27, 16711680
%29 = lshr i32 %28, 16
%30 = trunc i32 %29 to i8
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 6
store i8 %30, i8* %31
%32 = load void (...)*, void (...)** %5
%33 = ptrtoint void (...)* %32 to i32
%34 = and i32 %33, -16777216
%35 = lshr i32 %34, 24
%36 = trunc i32 %35 to i8
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 7
store i8 %36, i8* %37
store i8 0, i8* %8
br label %38
38: ; preds = %57, %3
%39 = load i8, i8* %8
%40 = zext i8 %39 to i32
%41 = icmp slt i32 %40, 8
br i1 %41, label %42, label %60
42: ; preds = %38
%43 = load i8, i8* %8
%44 = zext i8 %43 to i64
%45 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = load i8*, i8** %7
%48 = load i8, i8* %4
%49 = zext i8 %48 to i32
%50 = mul nsw i32 %49, 8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %47, i64 %51
%53 = load i8, i8* %8
%54 = zext i8 %53 to i32
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
store i8 %46, i8* %56
br label %57
57: ; preds = %42
%58 = load i8, i8* %8
%59 = add i8 %58, 1
store i8 %59, i8* %8
br label %38
60: ; preds = %38
ret void
}

LLVM IR (-O2):
define void @i_install(i8 zeroext %0, void (...)* %1, i8 zeroext %2) {
%4 = ptrtoint void (...)* %1 to i64
%5 = trunc i64 %4 to i8
%6 = lshr i64 %4, 8
%7 = trunc i64 %6 to i8
%8 = lshr i64 %4, 16
%9 = trunc i64 %8 to i8
%10 = lshr i64 %4, 24
%11 = trunc i64 %10 to i8
%12 = zext i8 %0 to i64
%13 = shl nuw nsw i64 %12, 3
%14 = getelementptr inbounds i8, i8* inttoptr (i64 1048576 to i8*), i64 %13
store i8 %5, i8* %14
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %7, i8* %15
%16 = getelementptr inbounds i8, i8* %14, i64 2
store i8 8, i8* %16
%17 = getelementptr inbounds i8, i8* %14, i64 3
store i8 0, i8* %17
%18 = getelementptr inbounds i8, i8* %14, i64 4
store i8 0, i8* %18
%19 = getelementptr inbounds i8, i8* %14, i64 5
store i8 %2, i8* %19
%20 = getelementptr inbounds i8, i8* %14, i64 6
store i8 %9, i8* %20
%21 = getelementptr inbounds i8, i8* %14, i64 7
store i8 %11, i8* %21
ret void
}