Hanmin Jung

122 papers B 2C 9Journal 40Unranked 67
YearRankTypeTitle / Venue / Authors
2025 C conf
IoTBDS
Athiruj Poositaporn, Hanmin Jung
2025 C conf
IoTBDS
Hanmin Jung, Athiruj Poositaporn
2022 conf
BigComp
Athiruj Poositaporn, Athita Onuean, Hanmin Jung
2019 J jnl
Int. J. Geogr. Inf. Sci.
Yee Leung, Yu Zhou, Ka-Yu Lam, Tung Fung, Kwan-Yau Cheung, Taehong Kim, Hanmin Jung
2018 ed.
JIST (Workshops & Posters)
Rathachai Chawuthai, Seiji Koide, Naoki Fukuta, Takeshi Morita, Hanmin Jung, Shinichi Nagano
2017 J jnl
Neurocomputing
Hyung-Jun Yim, Dongmin Seo, Hanmin Jung, Moon-Ki Back, InA Kim, Kyu-Chul Lee
2017 ed.
AIRS
Won-Kyung Sung, Hanmin Jung, Shuo Xu, Krisana Chinnasarn, Kazutoshi Sumiya, Jeonghoon Lee, Zhicheng Dou, Grace Hui Yang, Young-Guk Ha, Seungbock Lee
2017 C conf
IoTBDS
Joschka Kersting, Michaela Geierhos, Hanmin Jung, Taehong Kim
2017 conf
KST
Athita Onuean, Jangwon Gim, Yunji Jang, Hanmin Jung
2017 ed.
JIST (Workshops & Posters)
Marut Buranarach, Kouji Kozaki, Thepchai Supnithi, Hanmin Jung, Yuefeng Li
2016 J jnl
Wirel. Pers. Commun.
Jangwon Gim, Jinpyo Lee, Yunji Jang, Do-Heon Jeong, Hanmin Jung
2016 J jnl
J. Supercomput.
Jung-Ho Um, Seungwoo Lee, Taehong Kim, Chang-Hoo Jeong, Sa-Kwang Song, Hanmin Jung
2016 J jnl
Wirel. Pers. Commun.
Jangwon Gim, Yunji Jang, Hanmin Jung, Do-Heon Jeong
2016 J jnl
Neurocomputing
Jung-Ho Um, Seungwoo Lee, Taehong Kim, Chang-Hoo Jeong, Sa-Kwang Song, Hanmin Jung
2015 conf
HCI (23)
Jangwon Gim, Yunji Jang, Yeonghun Chae, Hanmin Jung, Do-Heon Jeong
2015 J jnl
KSII Trans. Internet Inf. Syst.
Sungho Shin, Hanmin Jung, Mun Yong Yi
2015 J jnl
Multim. Tools Appl.
Sung-Pil Choi, Sungho Shin, Hanmin Jung, Daesung Lee
2015 J jnl
Softw. Pract. Exp.
Taehong Kim, Myunggwon Hwang, Mi-Nyeong Hwang, Sa-Kwang Song, Do-Heon Jeong, Hanmin Jung
2015 J jnl
Multim. Tools Appl.
Jinhyung Kim, Do-Heon Jeong, Donghwi Lee, Hanmin Jung
2014 J jnl
Int. J. Distributed Sens. Networks
Shuo Xu, Qingwei Shi, Xiaodong Qiao, Lijun Zhu, Han Zhang, Hanmin Jung, Seungwoo Lee, Sung-Pil Choi
2014 J jnl
Comput. Informatics
Myunggwon Hwang, Do-Heon Jeong, Jinhyung Kim, Sa-Kwang Song, Hanmin Jung, Mazhar Sajjad
2014 J jnl
Multim. Tools Appl.
Sung-Pil Choi, Seungwoo Lee, Hanmin Jung, Sa-Kwang Song
2014 conf
JIST (Workshops & Posters)
Jangwon Gim, Yunji Jang, Do-Heon Jeong, Hanmin Jung
2014 conf
JIST (Workshops & Posters)
Sungho Shin, Young-Min Kim, Choong-Nyoung Seon, Seunggyun Hong, Sa-Kwang Song, Hanmin Jung
2014 conf
IMIS
Myunggwon Hwang, Ha Neul Yeom, Mi-Nyeong Hwang, Hanmin Jung
2014 conf
JIST (Workshops & Posters)
Mi-Nyeong Hwang, Myunggwon Hwang, Ha Neul Yeom, Kwang-Young Kim, Su-Mi Shin, Taehong Kim, Hanmin Jung
2014 J jnl
Clust. Comput.
Dongmin Seo, Hanmin Jung, Won-Kyung Sung, Sukil Kim, Sangho Lee
2014 J jnl
J. Appl. Math.
Dongmin Seo, Hanmin Jung, Won-Kyung Sung, Dukyun Nam
2014 J jnl
Int. J. Distributed Sens. Networks
Sung-Jae Jung, Dong Min Seo, Seungwoo Lee, Hwan-Min Kim, Hanmin Jung
2014 J jnl
Int. J. Distributed Sens. Networks
Myunggwon Hwang, Jinhyung Kim, Jangwon Gim, Sa-Kwang Song, Hanmin Jung, Do-Heon Jeong
2014 J jnl
Multim. Tools Appl.
Wongoo Lee, Minho Lee, Yunsoo Choi, Donghoon Choi, Min-Hee Cho, Sa-Kwang Song, Hanmin Jung, Donghwi Lee, Hwa-Mook Yoon
2014 J jnl
Multim. Tools Appl.
Chang-Hoo Jeong, Yunsoo Choi, Hong-Woo Chun, Sa-Kwang Song, Hanmin Jung, Sangkwan Lee, Sung-Pil Choi
2014 J jnl
Int. J. Distributed Sens. Networks
Jong-Yong Lee, Kyedong Jung, Hanmin Jung, Daesung Lee
2014 conf
IPaMin@KONVENS
Frederik Simon Bäumer, Jangwon Gim, Do-Heon Jeong, Michaela Geierhos, Hanmin Jung
2014 J jnl
J. Appl. Math.
Hyeok-June Jeong, Myunggwon Hwang, Hanmin Jung, Young-Guk Ha
2014 conf
IMIS
Myunggwon Hwang, Mi-Nyeong Hwang, Hanmin Jung
2014 conf
JIST (Workshops & Posters)
Seungwoo Lee, Chang-Hoo Jeong, Jung-Ho Um, Taehong Kim, Hanmin Jung
2014 J jnl
Int. J. Distributed Sens. Networks
Sungho Shin, Jung-Ho Um, Dongmin Seo, Sung-Pil Choi, Seungwoo Lee, Hanmin Jung, Mun Yong Yi
2014 conf
HCI (26)
Mikyoung Lee, Min-Hee Cho, Jangwon Gim, Do-Heon Jeong, Hanmin Jung
2014 ed.
IPaMin@Konvens
Hanmin Jung, Thomas Mandl, Christa Womser-Hacker, Shuo Xu
2014 conf
JIST (Workshops & Posters)
Mikyoung Lee, Min-Hee Cho, Chang-Hoo Jeong, Hanmin Jung
2014 conf
IPaMin@KONVENS
Jens Weber, Min-Hee Cho, Mikyoung Lee, Sa-Kwang Song, Michaela Geierhos, Hanmin Jung
2014 J jnl
Multim. Tools Appl.
Qing Li, Seungwoo Lee, Hanmin Jung, Yeong Su Lee, Jae-Hyun Cho, Sa-Kwang Song
2013 J jnl
Multim. Tools Appl.
Myunggwon Hwang, Do-Heon Jeong, Jinhyung Kim, Sa-Kwang Song, Hanmin Jung, Juhyun Shin, Pankoo Kim
2013 J jnl
Comput. Sci. Inf. Syst.
Myunggwon Hwang, Do-Heon Jeong, Jinhyung Kim, Sa-Kwang Song, Hanmin Jung
2013 conf
HCI (13)
Sungho Shin, Sangkeun Park, JinSeop Shin, Sa-Kwang Song, Sung-Pil Choi, Hanmin Jung
2013 conf
MUSIC
Myunggwon Hwang, Do-Heon Jeong, Jinhyung Kim, Jangwon Gim, Sa-Kwang Song, Mazhar Sajjad, Hanmin Jung, Shuo Xu, Lijun Zhu
2013 conf
GreenCom/iThings/CPScom
Sebastian Kastner, Sung-Pil Choi, Hanmin Jung
2013 conf
MUSIC
Shuo Xu, Qingwei Shi, Xiaodong Qiao, Lijun Zhu, Hanmin Jung, Seungwoo Lee, Sung-Pil Choi
2013 J jnl
J. Comput. Sci.
Jinhyung Kim, Myunggwon Hwang, Do-Heon Jeong, Sa-Kwang Song, Hanmin Jung
2013 conf
IMIS
Myunggwon Hwang, Taehong Kim, Jinhee Lee, Donald J. Kim, Do-Heon Jeong, Sa-Kwang Song, Hanmin Jung
2013 conf
SocialCom
Chang-Hoo Jeong, Sung-Pil Choi, Sungho Shin, Seungwoo Lee, Hanmin Jung, Soon-Young Kim, Pyung Kim
2013 J jnl
J. Supercomput.
Jung-Ho Um, Hoon Choi, Sa-Kwang Song, Sung-Pil Choi, Hwa-Mook Yoon, Hanmin Jung, Tai-Hoon Kim
2013 J jnl
Int. J. Distributed Sens. Networks
Jung-Ho Um, Chang-Hoo Jeong, Sung-Pil Choi, Seungwoo Lee, Hwan-Min Kim, Hanmin Jung
2013 conf
MUSIC
Jinhyung Kim, Myunggwon Hwang, Do-Heon Jeong, Sa-Kwang Song, Jangwon Gim, Hanmin Jung, Shuo Xu, Lijun Zhu
2013 conf
GreenCom/iThings/CPScom
Jangwon Gim, Donald J. Kim, Myunggwon Hwang, Sa-Kwang Song, Do-Heon Jeong, Hanmin Jung
2013 conf
MUSIC
Jung-Ho Um, Chang-Hoo Jeong, Sung-Pil Choi, Seungwoo Lee, Hanmin Jung
2013 conf
GreenCom/iThings/CPScom
Jangwon Gim, Do-Heon Jeong, Myunggwon Hwang, Sung-Pil Choi, Donald J. Kim, Seungwoo Lee, Sa-Kwang Song, Hanmin Jung
2013 conf
AMT
Jung-Ho Um, Sungho Shin, Sung-Pil Choi, Seungwoo Lee, Hanmin Jung
2013 conf
SocialCom
Donald J. Kim, Myunggwon Hwang, Jangwon Gim, Sa-Kwang Song, Do-Heon Jeong, Seungwoo Lee, Hanmin Jung
2013 conf
MUSIC
Sungho Shin, Jung-Ho Um, Sung-Pil Choi, Hanmin Jung, Shuo Xu, Lijun Zhu
2013 conf
MUSIC
Junyoung Choi, Daesung Lee, Hanmin Jung
2013 conf
HCI (15)
Seungwoo Lee, Min-Hee Cho, Sa-Kwang Song, Hanmin Jung
2013 conf
HCI (13)
Clara Peters, Mazhar Sajjad, Myungkwon Hwang, Jinhyung Kim, Sa-Kwang Song, Do-Heon Jeong, Seungwoo Lee, Hanmin Jung
2013 conf
HCI (14)
Hong-Woo Chun, Sung-Jae Jung, Mi-Nyeong Hwang, Chang-Hoo Jeong, Sa-Kwang Song, Seungwoo Lee, Sung-Pil Choi, Hanmin Jung
2013 conf
CSE
Sa-Kwang Song, Donald J. Kim, Myunggwon Hwang, Jangwon Kim, Do-Heon Jeong, Seungwoo Lee, Hanmin Jung, Won-Kyung Sung
2013 conf
MUSIC
Sung-Jae Jung, Dongmin Seo, Seungwoo Lee, Hanmin Jung
2013 conf
AMT
Myunggwon Hwang, Jangwon Gim, Do-Heon Jeong, Jinhyung Kim, Sa-Kwang Song, Mazhar Sajjad, Hanmin Jung, Jung-Hoon Park
2013 conf
HCI (13)
Nadine Pietras, Mazhar Sajjad, Myungkwon Hwang, Jinhyung Kim, Sa-Kwang Song, Do-Heon Jeong, Seungwoo Lee, Hanmin Jung
2012 conf
ICAISC (1)
Myunggwon Hwang, Do-Heon Jeong, Hanmin Jung, Won-Kyung Sung, Juhyun Shin, Pankoo Kim
2012 C conf
ISMIS
Hong-Woo Chun, Sa-Kwang Song, Sung-Pil Choi, Hanmin Jung
2012 conf
GreenCom
Myunggwon Hwang, Donald J. Kim, Do-Heon Jeong, Sa-Kwang Song, Hanmin Jung, Hoon Ko
2012 C conf
ISMIS
Jung-Whoan Choi, Seungwoo Lee, Dongmin Seo, Sa-Kwang Song, Hanmin Jung, Sang-Hwan Lee, Pyung Kim
2012 conf
GreenCom
Sung-Pil Choi, Hong-Woo Chun, Chang-Hoo Jeong, Sa-Kwang Song, Hanmin Jung
2012 conf
IMIS
Myunggwon Hwang, Sa-Kwang Song, Do-Heon Jeong, Hanmin Jung, Jinhyung Kim
2012 conf
ICBO
Hong-Woo Chun, Chang-Hoo Jeong, Sa-Kwang Song, Yunsoo Choi, Sung-Pil Choi, Hanmin Jung
2012 J jnl
Expert Syst. Appl.
Jinhyung Kim, Myunggwon Hwang, Do-Heon Jeong, Hanmin Jung
2011 J jnl
Inf. Process. Manag.
In-Su Kang, Pyung Kim, Seungwoo Lee, Hanmin Jung, Beom-Jong You
2011 conf
FGIT-UNESST
Mikyoung Lee, Seungwoo Lee, Jinhyung Kim, Dongmin Seo, Pyung Kim, Hanmin Jung, Jinhee Lee, Taehong Kim, Hee-Kwan Koo, Won-Kyung Sung
2011 conf
FGIT-UNESST
Jinhyung Kim, Seungwoo Lee, Jinhee Lee, Mikyoung Lee, Hanmin Jung
2011 conf
FGIT-UNESST
Dongmin Seo, Hee-Kwan Koo, Seungwoo Lee, Pyung Kim, Hanmin Jung, Won-Kyung Sung
2011 conf
iThings/CPSCom
Mikyoung Lee, Hanmin Jung, Jinhyung Kim, Young-Hyun Choi, Seungin Kim
2011 conf
FGIT-UNESST
Seungwoo Lee, Mikyoung Lee, Hanmin Jung, Won-Kyung Sung
2011 conf
iThings/CPSCom
Myunggwon Hwang, Do-Heon Jeong, Seungwoo Lee, Hanmin Jung
2011 conf
iThings/CPSCom
Seungwoo Lee, Pyung Kim, Dongmin Seo, Jinhyung Kim, Jinhee Lee, Hanmin Jung, Christian Dirschl
2011 J jnl
Expert Syst. Appl.
Sungin Lee, Senator Jeong, Hong-Gee Kim, Hanmin Jung, Mikyoung Lee, Seung-Jae Song, Beom-Jong You
2011 conf
FGIT-UNESST
Taehong Kim, Pyung Kim, Seungwoo Lee, Hanmin Jung, Won-Kyung Sung
2011 conf
iThings/CPSCom
Jinhyung Kim, Dongmin Seo, Hanmin Jung, Pyung Kim, Seungwoo Lee, Won-Kyung Sung
2011 conf
HCI (22)
Mikyoung Lee, Seungwoo Lee, Pyung Kim, Hanmin Jung, Won-Kyung Sung
2011 conf
ITNG
Hanmin Jung, Mikyoung Lee, Pyung Kim, Do-Wan Kim
2011 conf
HCI (12)
Hanmin Jung, Mikyoung Lee, Pyung Kim, Won-Kyung Sung
2011 conf
iThings/CPSCom
Jinhee Lee, Jinhyung Kim, Seungwoo Lee, Dongmin Seo, Hanmin Jung, Won-Kyung Sung
2011 C conf
ISI
Hanmin Jung, Mikyoung Lee, Won-Kyung Sung, Do-Wan Kim
2011 conf
AMT
Seungwoo Lee, Mikyoung Lee, Hanmin Jung, Pyung Kim, Dongmin Seo, Taehong Kim, Jinhee Lee, Won-Kyung Sung
2010 conf
ESWC (2)
Seungwoo Lee, Mikyoung Lee, Pyung Kim, Hanmin Jung, Won-Kyung Sung
2010 conf
JCDL
Seungwoo Lee, Mikyoung Lee, Pyung Kim, Hanmin Jung, Won-Kyung Sung
2010 conf
AMT
Pyung Kim, Dongmin Seo, Mikyoung Lee, Seungwoo Lee, Hanmin Jung, Won-Kyung Sung
2010 conf
SWWS
Mikyoung Lee, Seungwoo Lee, Pyung Kim, Hanmin Jung, Dongmin Seo
2009 conf
HCI (9)
Hanmin Jung, Mikyoung Lee, Won-Kyung Sung, Beom-Jong You
2009 conf
AMT
Hanmin Jung, Mikyoung Lee, Beom-Jong You, Do-Wan Kim
2009 conf
BlogTalk
Hanmin Jung, Mikyoung Lee, Pyung Kim, Seungwoo Lee
2009 J jnl
Inf. Process. Manag.
In-Su Kang, Seung-Hoon Na, Seungwoo Lee, Hanmin Jung, Pyung Kim, Won-Kyung Sung, Jong-Hyeok Lee
2008 C conf
ACHI
Hanmin Jung, Mikyoung Lee, Seungwoo Lee, Won-Kyung Sung
2008 conf
NCM (2)
Hanmin Jung, Mikyoung Lee, Won-Kyung Sung
2007 conf
ITNG
Hanmin Jung, Seungwoo Lee, In-Su Kang, Hee-Kwan Koo, Won-Kyung Sung
2007 conf
FEWS
Hanmin Jung, Mikyoung Lee, In-Su Kang, Seungwoo Lee, Won-Kyung Sung
2007 J jnl
Data Sci. J.
Hanmin Jung, Hee-Kwan Koo, Won-Kyung Sung, Dong-In Park
2007 J jnl
Data Sci. J.
Hanmin Jung, Mikyoung Lee, Won-Kyung Sung, Dong-In Park
2006 J jnl
Res. Comput. Sci.
Dong-In Park, Hanmin Jung, Hee-Kwan Koo, Won-Kyung Sung
2005 conf
ACIS-ICIS
Hanmin Jung, Hee-Kwan Koo, Byeong-Hee Lee, Won-Kyung Sung
2005 C conf
NLDB
Hanmin Jung, Choong-Nyoung Seon, Jaehong Kim, Joo-Chan Sohn, Won-Kyung Sung, Dong-In Park
2005 conf
EuroIMSA
Hanmin Jung, Choong-Nyoung Seon, Joo-Chan Sohn, Won-Kyung Sung, Dong-In Park
2005 J jnl
Inf. Process. Manag.
Hanmin Jung, Eunji Yi, Dongseok Kim, Gary Geunbae Lee
2003 J jnl
Inf. Process. Manag.
Dongseok Kim, Hanmin Jung, Gary Geunbae Lee
2001 conf
TREC
Gary Geunbae Lee, Jungyun Seo, Seungwoo Lee, Hanmin Jung, Bong-Hyun Cho, Changki Lee, Byung-Kwan Kwak, Jeongwon Cha, Dongseok Kim, Joohui An, Harksoo Kim, Kyungsun Kim
1999 J jnl
Comput. Intell.
Hanmin Jung, Sanghwa Yuh, Taewan Kim, Sangkyu Park
1999 J jnl
Inf. Process. Manag.
Taewan Kim, Chul-Min Sim, Sanghwa Yuh, Hanmin Jung, Young Kil Kim, Sung-Kwon Choi, Dong-In Park, Key-Sun Choi
1998 B conf
LREC
Hanmin Jung, Sanghwa Yuh, Chul-Min Sim, Taewan Kim, Dong-In Park
1998 B conf
LREC
Young Kil Kim, Sanghwa Yuh, Hanmin Jung, Taewan Kim, Dong-In Park
1998 conf
COLING-ACL
Sung-Kwon Choi, Hanmin Jung, Chul-Min Sim, Taewan Kim, Dong-In Park, Junsik Park, Key-Sun Choi
1998 C conf
PACLIC
Hanmin Jung, Sanghwa Yuh, Taewan Kim, Dong-In Park
1995 J jnl
CoRR
Geunbae Lee, Hanmin Jung, Jong-Hyeok Lee
redb/extractors/decompiler/bninja/analysis/cfg_features.py
← Index redb/extractors/decompiler/bninja/analysis/cfg_features.py python
import struct
from collections import deque
from typing import Optional

import blake3
import mmh3


# ---------------------------------------------------------------------------
# Task 1.1: Core Graph Utilities
# ---------------------------------------------------------------------------

def bfs_order(successors: list[list[int]], n: int) -> list[int]:
    """
    BFS traversal from node 0 (entry block), returns node indices in visit order.
    Unreachable nodes appended at the end.
    """
    if n == 0:
        return []

    visited = set()
    order = []
    queue = deque([0])
    visited.add(0)

    while queue:
        idx = queue.popleft()
        order.append(idx)
        for target in successors[idx]:
            if target not in visited:
                visited.add(target)
                queue.append(target)

    # Append unreachable blocks (dead code)
    for i in range(n):
        if i not in visited:
            order.append(i)

    return order


def bfs_max_depth(successors: list[list[int]], n: int) -> int:
    """
    Maximum BFS depth from entry block (node 0).
    Replaces the per-block depth column with a single scalar.
    """
    if n == 0:
        return 0

    depth = {0: 0}
    max_d = 0
    queue = deque([0])

    while queue:
        node = queue.popleft()
        for s in successors[node]:
            if s not in depth:
                depth[s] = depth[node] + 1
                if depth[s] > max_d:
                    max_d = depth[s]
                queue.append(s)

    return max_d


# ---------------------------------------------------------------------------
# Task 1.2: Back-Edge Detection (Iterative DFS)
# ---------------------------------------------------------------------------

def count_back_edges(successors: list[list[int]], n: int) -> int:
    """
    Count natural loops via iterative DFS back-edge detection.
    A back edge is an edge to a GRAY (in-stack) node.

    Iterative to avoid stack overflow on functions with 1000+ blocks
    (common in obfuscated malware, VM dispatchers, unrolled loops).
    """
    if n == 0:
        return 0

    WHITE, GRAY, BLACK = 0, 1, 2
    color = [WHITE] * n
    back_edges = 0

    stack = [(0, iter(successors[0]))]
    color[0] = GRAY

    while stack:
        u, children = stack[-1]
        try:
            v = next(children)
            if color[v] == GRAY:
                back_edges += 1
            elif color[v] == WHITE:
                color[v] = GRAY
                stack.append((v, iter(successors[v])))
        except StopIteration:
            color[u] = BLACK
            stack.pop()

    return back_edges


# ---------------------------------------------------------------------------
# Task 1.3: Topology Hash
# ---------------------------------------------------------------------------

def compute_topology_hash(
    successors: list[list[int]],
    bfs: list[int],
    n: int,
) -> bytes:
    """
    BLAKE3 hash of BFS-ordered canonical adjacency.
    Pure graph shape — ignores all block content.
    Two functions with identical control flow structure produce identical hashes.

    Returns 16 bytes (128-bit).
    """
    if n == 0:
        return b'\x00' * 16

    # Remap: original index -> BFS position
    remap = {original: position for position, original in enumerate(bfs)}

    canonical = bytearray()
    for position in range(n):
        original_idx = bfs[position]
        remapped_succs = sorted(
            remap[s] for s in successors[original_idx] if s in remap
        )
        # Pack: node_index (2 bytes) + num_successors (1 byte) + successor indices (2 bytes each)
        canonical.extend(struct.pack('<HB', position, len(remapped_succs)))
        for s in remapped_succs:
            canonical.extend(struct.pack('<H', s))

    return blake3.blake3(bytes(canonical)).digest(length=16)


# ---------------------------------------------------------------------------
# Task 1.4: MD-Index (Top-Down and Bottom-Up)
# ---------------------------------------------------------------------------

def compute_md_index_topdown(
    successors: list[list[int]],
    predecessors: list[list[int]],
    bfs: list[int],
) -> int:
    """
    BinDiff-style top-down MD-index.
    Hash of (in_degree, out_degree) sequence in BFS order from entry.
    Returns UInt64.
    """
    if not bfs:
        return 0

    degree_bytes = bytearray()
    for idx in bfs:
        in_deg = min(len(predecessors[idx]), 255)
        out_deg = min(len(successors[idx]), 255)
        degree_bytes.extend(struct.pack('<BB', in_deg, out_deg))

    h = blake3.blake3(bytes(degree_bytes)).digest(length=8)
    return struct.unpack('<Q', h)[0]


def compute_md_index_bottomup(
    successors: list[list[int]],
    predecessors: list[list[int]],
    n: int,
) -> int:
    """
    Bottom-up MD-index: BFS from exit blocks (no successors),
    traversing edges in reverse.
    Returns UInt64.
    """
    if n == 0:
        return 0

    exits = [i for i in range(n) if len(successors[i]) == 0]
    if not exits:
        exits = [n - 1]  # Fallback: use last block

    visited = set(exits)
    order = []
    queue = deque(exits)

    while queue:
        idx = queue.popleft()
        order.append(idx)
        for pred in predecessors[idx]:
            if pred not in visited:
                visited.add(pred)
                queue.append(pred)

    # Append unreachable blocks
    for i in range(n):
        if i not in visited:
            order.append(i)

    degree_bytes = bytearray()
    for idx in order:
        in_deg = min(len(predecessors[idx]), 255)
        out_deg = min(len(successors[idx]), 255)
        degree_bytes.extend(struct.pack('<BB', in_deg, out_deg))

    h = blake3.blake3(bytes(degree_bytes)).digest(length=8)
    return struct.unpack('<Q', h)[0]


# ---------------------------------------------------------------------------
# Task 1.5: Prime Product
# ---------------------------------------------------------------------------

# Small primes assigned to LLIL opcode categories.
# Keys are the integer values of binaryninja.LowLevelILOperation enum members.
# We use integer keys so this module doesn't import binaryninja.
#
# Mapping rationale: same operation class -> same prime.
# Using LLIL (not native asm) makes this architecture-independent.
#
# Populated at import time by cfg.py using the real LowLevelILOperation enum values.
# Unknown ops map to prime 1 (identity element) in compute_prime_product().
LLIL_OP_PRIMES: dict[int, int] = {}


def compute_prime_product(llil_operations: list[int]) -> int:
    """
    Product of small primes assigned to each LLIL opcode.
    Position-independent: block reordering doesn't change the result.
    Mod 2^64 for fixed-size storage.

    Args:
        llil_operations: flat list of LLIL operation enum integer values
                         for all instructions in the function.
    Returns:
        UInt64 prime product, or 0 if no instructions.
    """
    if not llil_operations:
        return 0

    product = 1
    for op in llil_operations:
        prime = LLIL_OP_PRIMES.get(op, 1)
        product = (product * prime) % (2**64)

    return product


# ---------------------------------------------------------------------------
# Task 1.6: ACFG Block Features
# ---------------------------------------------------------------------------

# Instruction category indices for ACFG feature vectors
CAT_ARITHMETIC = 0
CAT_LOGIC = 1
CAT_TRANSFER = 2
CAT_CALL = 3
CAT_COMPARISON = 4
CAT_MEMORY = 5
CAT_OTHER = 6

# Maps LLIL operation integer values to category indices.
# Populated at import time by cfg.py using the real LowLevelILOperation enum.
LLIL_OP_CATEGORIES: dict[int, int] = {}


def build_block_features(
    block_llil_ops: list[list[int]],
    successors: list[list[int]],
    n: int,
) -> list[list[int]]:
    """
    Extract Gemini-style ACFG features per block.

    Args:
        block_llil_ops: per-block list of LLIL operation integer values.
                        block_llil_ops[i] is the list of ops for block i.
                        Empty list if LLIL unavailable for that block.
        successors: index-based adjacency list.
        n: number of blocks.

    Returns:
        List of [instr_count, arithmetic, logic, transfer, call, comparison,
                 memory, successor_count] per block. All values capped at 65535.
    """
    features = []
    for i in range(n):
        cats = [0, 0, 0, 0, 0, 0, 0]
        ops = block_llil_ops[i] if i < len(block_llil_ops) else []
        for op in ops:
            cat = LLIL_OP_CATEGORIES.get(op, CAT_OTHER)
            cats[cat] += 1

        instr_count = len(ops)
        features.append([
            min(instr_count, 65535),
            min(cats[CAT_ARITHMETIC], 65535),
            min(cats[CAT_LOGIC], 65535),
            min(cats[CAT_TRANSFER], 65535),
            min(cats[CAT_CALL], 65535),
            min(cats[CAT_COMPARISON], 65535),
            min(cats[CAT_MEMORY], 65535),
            min(len(successors[i]), 65535),
        ])

    return features


# ---------------------------------------------------------------------------
# Task 1.7: CFG Feature TLSH
# ---------------------------------------------------------------------------

def compute_cfg_feature_tlsh(
    bb_features: list[list[int]],
    bfs: list[int],
) -> Optional[str]:
    """
    TLSH hash of BFS-ordered per-block feature vectors.
    Captures both structure (BFS ordering) and instruction distribution.

    Returns TLSH hex string or None if too few bytes for TLSH (< 50).
    """
    import tlsh as _tlsh

    feature_bytes = bytearray()
    for idx in bfs:
        feats = bb_features[idx]
        feature_bytes.extend(struct.pack(
            '<HBBBBBBB',
            min(feats[0], 65535),
            min(feats[1], 255),
            min(feats[2], 255),
            min(feats[3], 255),
            min(feats[4], 255),
            min(feats[5], 255),
            min(feats[6], 255),
            min(feats[7], 255),
        ))

    if len(feature_bytes) < 50:
        return None

    try:
        h = _tlsh.hash(bytes(feature_bytes))
        return h if h and h != 'TNULL' else None
    except Exception:
        return None


# ---------------------------------------------------------------------------
# Task 1.8: WL-MinHash
# ---------------------------------------------------------------------------

# Pre-computed seeds for MinHash permutations.
NUM_WL_MINHASH_PERMS = 128
_WL_MINHASH_SEEDS = list(range(NUM_WL_MINHASH_PERMS))  # Seeds 0..127


def compute_wl_minhash(
    successors: list[list[int]],
    predecessors: list[list[int]],
    bb_features: list[list[int]],
    n: int,
    iterations: int = 3,
) -> list[int]:
    """
    Weisfeiler-Leman MinHash for fuzzy topology similarity.

    Initial labels: mmh3 hash of per-block ACFG feature tuple (content-aware).
    WL refinement: incorporate sorted neighbor labels at each iteration.
    MinHash: 128-permutation signature over shingle set.

    Returns list of 128 uint8 values, or [255]*128 sentinel for empty functions.
    """
    if n == 0:
        return [255] * NUM_WL_MINHASH_PERMS

    # Initial labels: hash of instruction category tuple per block
    labels = []
    for i in range(n):
        feats = bb_features[i] if i < len(bb_features) else [0] * 8
        # mmh3 with seed=0 for initial labels
        label = mmh3.hash(str(tuple(feats)), 0) & 0xFFFFFFFF
        labels.append(label)

    # Collect shingles: (iteration, label) pairs as strings for mmh3
    shingles: set[str] = set()

    # Iteration 0: individual block labels
    for label in labels:
        shingles.add(f"0:{label}")

    # WL iterations: refine labels by neighborhood aggregation
    for iteration in range(1, iterations + 1):
        new_labels = []
        for i in range(n):
            succ_labels = tuple(sorted(labels[s] for s in successors[i]))
            pred_labels = tuple(sorted(labels[p] for p in predecessors[i]))
            composite = f"{labels[i]}|{succ_labels}|{pred_labels}"
            new_label = mmh3.hash(composite, 0) & 0xFFFFFFFF
            new_labels.append(new_label)
            shingles.add(f"{iteration}:{new_label}")
        labels = new_labels

    if not shingles:
        return [255] * NUM_WL_MINHASH_PERMS

    # Compute MinHash signature using mmh3 with different seeds
    shingle_list = list(shingles)
    signature = []
    for seed in _WL_MINHASH_SEEDS:
        min_val = 0xFFFFFFFF
        for s in shingle_list:
            h = mmh3.hash(s, seed) & 0xFFFFFFFF
            if h < min_val:
                min_val = h
        # Compress to uint8 for storage
        signature.append(min_val & 0xFF)

    return signature


# ---------------------------------------------------------------------------
# Task 1.9: Packed Adjacency
# ---------------------------------------------------------------------------

def pack_adjacency(successors: list[list[int]]) -> list[int]:
    """
    Pack CFG edges as Array(UInt32).
    Each UInt32 = (source_index << 16) | target_index.
    Supports up to 65,535 blocks per function.
    """
    edges = []
    for src, targets in enumerate(successors):
        for tgt in targets:
            if src < 65536 and tgt < 65536:
                edges.append((src << 16) | tgt)
    return edges