Skip to content

x8664-cvs-863633: collapse duplicate scalar local declarations (option dedupvardecls) - #42

Merged
mahaloz merged 2 commits into
mainfrom
feat/angr-x8664-cvs-863633
Jun 25, 2026
Merged

mahaloz merged 2 commits into
mainfrom
feat/angr-x8664-cvs-863633

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

x8664-cvs-863633: collapse duplicate scalar local declarations (option dedupvardecls, DIV-7)

Closes the angr-vs-kuna gap on test_decompiling_x8664_cvs::main (x86_64/cvs). kuna emitted a
wall of duplicate local-variable declarations — on cvs main the single stack slot
stack - 0x3c (option_index) was declared 166 times, stack - 0x38 53×, etc. — where angr
declares each local exactly once. This was the dominant cause of kuna's main being ~30% longer
than angr (677 vs 472 loc); with the fix on, main drops to 461 loc.

See docs/features/x8664-cvs-863633/analysis.md for
the full side-by-side analysis.

Why angr is better

angr's variable recovery yields one variable per storage location, so its declaration block lists
each local once. kuna's C printer instead walks HighVariables (the W4 ScopeLocal Symbol walk
is the documented missing surface), so when the angr-style naming maps many distinct scalar
HighVariables that share one stack slot to the same name + type + storage, kuna emits one
declaration line per high — textually identical, and (strictly) invalid C re-declarations. The
function body refers to all of them by the one shared name, so the duplicate declaration lines
are pure noise.

Mechanism (S9 emit)

emit_local_var_decls (s9_emit/printc.rs) now skips a declaration whose fully-rendered
signature
(final declarator type + name + array adornment + storage comment) is byte-identical to
one already emitted — the scalar analogue of the composite-symbol (array/struct/union) collapse kuna
already performs, approximating Ghidra's once-per-Symbol emitScopeVarDecls walk. The option parser
and the DeclDedup signature tracker live in the new module
s9_emit/kuna_dedupvardecls.rs
(ElementId 4091). Pure presentation: the statement body markup, naming, and which HighVariables
exist are all unchanged — only redundant declaration lines are removed (provably lossless: it
removes only lines whose emitted bytes are character-identical to an already-emitted one).

Option

  • option dedupvardecls on|off (arch flag dedup_var_decls), DIV-7 default-on.
  • Flip off to restore the one-declaration-per-high rendering: option dedupvardecls off, or
    kuna decompile <bin> <fn> --option dedupvardecls off.
  • Discoverable via kuna catalog --json (provenance: source_decompiler="angr").

Ablation / parity / speed

  • Ablation: 0 of 675 upstream datatest assertions change with the feature default-ON
    (make test stays PARITY OK without baseline regeneration).
  • Speed: +0.14% on the target (off 2236 ms → on 2239 ms, 5% budget) — an O(decls) HashSet pass.
  • A clean ablation + within-budget speed is why this ships default-ON (DIV-7).
  • Stage test: tests/stages/ghangr-x8664-cvs-863633.xml (+2 assertions); make test-stages PARITY OK.

🤖 Generated with Claude Code


Before / after — main in cvs

Real captured kuna output on the function this feature was built for, with option dedupvardecls flipped. Ported from angr — test_decompiling_x8664_cvs; angr variable recovery (one variable per storage location, declared once); main.

metric dedupvardecls off dedupvardecls on (default)
gotos 50 50
labels 26 26
loc 677 458 ⬇️
switches 1 1
speed 2236.27 ms 2239.31 ms — Δ 0.14% (budget 5.0%)
kuna — before (option dedupvardecls off)
unsigned long main(int4 a0,void **a1)

{
  void **cpp; // rax
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  char *end; // stack - 0x38
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  int4 option_index; // stack - 0x3c
  bool v1;
  unsigned long v10; // rax
  cvsroot_s *v11; // rax
  node *v12; // rax
  int4 *v13; // rax
  char *v14; // rax
  code *v15; // rdx
  char *v16;
  void **v17; // rbx
  void **v18;
  void **v19; // stack - 0x58
  void **v19; // stack - 0x58
  void **v19; // stack - 0x58
  bool v2;
  int4 v20 [4]; // stack - 0x4c
  uint1 *v23; // rdi
  uint1 *v24;
  char *v25; // r13
  int8 v26; // fs_offset
  int8 v27; // fs_offset
  bool v28; // cf
  bool v29;
  char v3; // al
  uint1 v30; // df
  int8 v31; // stack - 0x30
  int4 v4;
  uint4 v5; // eax
  int4 v6; // eax
  int8 v7;
  uint8 v9; // rax
  
  v30 = 0;
  v31 = *(int8 *)(v26 + 0x28);
  v7 = getenv("CHESS");
  if (v7 == 0) {
    puts("Failed testbed check");
    if (v31 != *(int8 *)(v27 + 0x28)) {
                    /* WARNING: Subroutine does not return */
      __stack_chk_fail();
    }
    return 1;
  }
  option_index = 0;
  tzset();
  RAX = Xstrdup(*v19);
  RAX = last_component(*v19);
  v8 = (char *)getenv("CVSEDITOR");
  if ((((v8 != (char *)0x0) && (*v8 != '\0')) || ((v8 = (char *)getenv("VISUAL"), v8 != (char *)0x0 && (*v8 != '\0')))) || ((v8 = (char *)getenv(0x49777e), v8 != (char *)0x0 && (*v8 != '\0')))) {
  }
  v7 = getenv("CVSREAD");
  if (v7 != 0) {
    dat_4cbb54 = 0;
  }
  v7 = getenv("CVSREADONLYFS");
  if (v7 != 0) {
    dat_4cca7c = 1;
    dat_4cca78 = 1;
  }
  dat_4cc418 = 0;
  v18 = (void **)&option_index;
  dat_4cc440 = 0;
  while( true ) {
    v4 = getopt_long(v20[0],v19,"+QqrwgtnRvb:T:e:d:Hfz:s:xal",0x4cbb60,v18);
    if (v4 == -1) break;
    if (v4 == 0x66) {
      dat_4cbb58 = 0;
    }
  }
  if (dat_4cc418 < v20[0]) {
    Unique00023e00 = v19[dat_4cc418];
    v4 = strcmp((char *)Unique00023e00,"pserver");
    if ((v4 == 0) || (v4 = strcmp((char *)Unique00023e00,"server"), v4 == 0)) {
      dat_4cbb58 = 0;
      parseServerOptions(v20[0] - Unique10000e6f,&v19[dat_4cc418]);
    }
  }
  if (dat_4cbb58 != 0) {
    read_cvsrc(v20,&v19,"cvs");
  }
  dat_4cc418 = 0;
  v1 = 0;
  v8 = (char *)0x0;
  v24 = (uint1 *)0x49b8f0;
  dat_4cc440 = 1;
label_404f5c:
  v4 = getopt_long(v20[0],v19,"+QqrwgtnRvb:T:e:d:Hfz:s:xal",0x4cbb60,v18);
  if (v4 == -1) {
    v20[0] = v20[0] - dat_4cc418;
    v19 = &v19[dat_4cc418];
    if (1 <= v20[0]) {
      v9 = random();
      v5 = getpid();
      v10 = time(0);
      v18 = (void **)cmds;
      RAX = Xasprintf("1%010llX%04X%04X",v10,(uint8)v5 & 0xffff,v9 & 0xffff);
      v8 = "add";
      cvs_trace(1,"main: Session ID is %s",RAX);
      v24 = *v19;
      goto label_405419;
    }
    goto label_405a6a;
  }
  switch(v4) {
    default:
      goto label_405a6a;
    case 1:
      goto label_405a5e;
    case 2:
      v15 = cmds;
      v4 = 3;
      do {
        v15 = &v15[0x28];
        v4 = v4 + 1;
      } while (*(int8 *)v15 != 0);
      v15 = cmds;
      cpp = xnmalloc((int8)v4,8);
      v25 = "";
      v8 = "add";
      v18 = &cpp[1];
      *cpp = "CVS command synonyms are:\n";
      do {
        v16 = *(char **)&v15[8];
        v7 = *(int8 *)&v15[0x10];
        if (v16 == (char *)0x0) {
          if (v7 != 0) goto label_404ff6;
        }
        else {
          if (v7 == 0) {
            v7 = 0x4ab0a2;
          }
label_404ff6:
          v17 = &v18[1];
          v8 = Xasprintf("        %-12s %s %s\n",v8,v16,v7);
          *v18 = v8;
        }
        v8 = *(char **)&v15[0x28];
        v15 = &v15[0x28];
      } while (v8 != (char *)0x0);
      v18[1] = (void *)0x0;
      *v18 = "(Specify the --help option for a list of other help options)\n";
      usage(cpp);
      goto label_405bbb;
    case 3:
      root_allow_add(dat_4cc420,dat_4cd498);
      goto label_404f5c;
    case 4:
      usage((void **)opt_usage);
      goto label_405a41;
    case 0xe:
      root_allow_regexp_add(dat_4cc420,dat_4cd498);
      goto label_404f5c;
    case 0x48:
      v1 = 1;
      goto label_404f5c;
    case 0x51:
      dat_4cca8c = 1;
      goto label_405041;
    case 0x52:
      dat_4cca7c = 0xffffffff;
      dat_4cca78 = 1;
      goto label_404f5c;
    case 0x54:
      if (dat_4ccad0 != (char *)0x0) {
        free(dat_4ccad0);
      }
      RAX = Xstrdup(dat_4cc420);
      goto label_404f5c;
    case 0x61:
      dat_4cd480 = 1;
      goto label_404f5c;
    case 0x62:
    case 0x6c:
      goto label_404f5c;
    case 100:
      if (dat_4cd470 != (char *)0x0) {
        free(dat_4cd470);
      }
      RAX = Xstrdup(dat_4cc420);
      goto label_404f5c;
    case 0x65:
      if ((int4)v8 != 0) {
        free(dat_4cbc60);
      }
      v8 = (char *)0x1;
      RAX = Xstrdup(dat_4cc420);
      goto label_404f5c;
    case 0x66:
      dat_4cbb58 = 0;
      goto label_404f5c;
    case 0x67:
      v5 = umask(0x3f);
      umask(v5 & 7);
      goto label_404f5c;
    case 0x6e:
      dat_4cca80 = 1;
      dat_4cca78 = 1;
      goto label_404f5c;
    case 0x71:
label_405041:
      dat_4cca88 = 1;
      goto label_404f5c;
    case 0x72:
      dat_4cbb54 = 0;
      goto label_404f5c;
    case 0x73:
      variable_set(dat_4cc420);
      goto label_404f5c;
    case 0x74:
      dat_4cca84 = dat_4cca84 + 1;
      goto label_404f5c;
    case 0x76:
      fputc_unlocked();
      version(0,(char **)0x0);
      fputc_unlocked(10,dat_4cc400);
      fwrite_unlocked("Copyright (C) 2005 Free Software Foundation, Inc.\n\nPortions contributed by Thorsten Glaser for the MirOS Project and Debian.\nSenior active maintainers include Larry Jones, Derek R. Price,\nand Mark D. Baushke.  Please see the AUTHORS and README files from the CVS\ndistribution kit for a complete list of contributors and copyrights.\n",1,0x14c,dat_4cc400);
      fputc_unlocked(10,dat_4cc400);
      fwrite_unlocked("CVS may be copied only under the terms of the GNU General Public License,\n",1,0x4a,dat_4cc400);
      fwrite_unlocked("a copy of which can be found with the CVS distribution kit.\n",1,0x3c,dat_4cc400);
      fputc_unlocked(10,dat_4cc400);
      fwrite_unlocked("Specify the --help option for further information about CVS\n",1,0x3c,dat_4cc400);
                    /* WARNING: Subroutine does not return */
      exit(0);
    case 0x77:
      dat_4cbb54 = 1;
      goto label_404f5c;
    case 0x78:
      dat_4cd490 = 1;
      goto label_404f5c;
    case 0x7a:
      EAX = strtol(dat_4cc420,&end,10);
      if ((*end != '\0') || (10 <= EAX)) {
        error(1,0,"gzip compression level must be between 0 and 9");
      }
      goto label_404f5c;
    
  }
  while( true ) {
    Unique00023e00 = v18[5];
    v18 = &v18[5];
    v8 = (char *)0x0;
    if (Unique00023e00 == (uint1 *)0x0) break;
label_405419:
    if ((((v18[1] != (char *)0x0) && (v4 = strcmp((char *)v24,v18[1]), v4 == 0)) || ((v18[2] != (char *)0x0 && (v4 = strcmp((char *)v24,v18[2]), v4 == 0)))) || (v4 = strcmp((char *)v24,(char *)RBP), v4 == 0)) {
      if (v1) {
        v20[0] = -1;
        v4 = (*v18[3])(0xffffffff,v19);
label_40567d:
        dat_4cd450 = 0;
        root_allow_free();
                    /* WARNING: Subroutine does not return */
        exit(v4 != 0);
      }
      v8 = (char *)getenv();
      if ((v8 == (char *)0x0) || (*v8 == '\0')) goto label_4054a6;
      EAX = strtol(v8,&end,8);
      EAX = EAX & 0x1ff;
      if (*end == '\0') goto label_4054a6;
      goto label_405a76;
    }
  }
label_405a41:
  __fprintf_chk(dat_4cc460,1,"Unknown command: `%s\'\n\n",v24);
label_405a5e:
  usage((void **)cmd_usage);
label_405a6a:
  usage((void **)usg);
label_405a76:
  v13 = (int4 *)__errno_location();
  error(1,*v13,"invalid umask value in %s (%s)","CVSUMASK",v8);
label_4054a6:
  RAX = xgethostname();
  if (RAX == (char *)0x0) {
    v13 = (int4 *)__errno_location();
    error(0,*v13,"xgethostname () returned NULL, using \"localhost\"");
    RAX = Xstrdup("localhost");
  }
  RAX = Xstrdup(dat_4cd448);
  v4 = strcmp((char *)dat_4cd430,"pserver");
  if (v4 == 0) {
    pserver_start_listener();
    pserver_authenticate_connection();
    dat_4ccce0 = 1;
    v8 = "server";
label_405718:
    RAX = Xstrdup("<remote>");
    cleanup_register(server_cleanup);
  }
  else {
    v4 = strcmp((char *)dat_4cd430,"server");
    EDX = (uint4)(v4 == 0);
    if (v4 == 0) goto label_405718;
    cleanup_register(close_stdout);
    RAX = xgetcwd();
    if (RAX == (char *)0x0) {
      v13 = (int4 *)__errno_location();
      error(1,*v13,"cannot get working directory");
    }
  }
  v4 = getpid();
  v8 = Xasprintf("%ld",(int8)v4);
  setenv("CVS_PID",v8,1);
  free(v8);
  signals_register(main_cleanup);
  if (dat_4cbb58 != 0) {
    read_cvsrc(v20,&v19,(char *)dat_4cd430);
  }
  if (dat_4ccce0 == 0) {
    if (dat_4cd470 == (char *)0x0) {
label_4059c4:
      if ((((uint8)v18[4] & 1) != 0) || (v11 = Name_Root((char *)0x0,(char *)0x0), v11 == (cvsroot_s *)0x0)) {
        v1 = 1;
        v8 = (char *)getenv();
        if ((v8 != (char *)0x0) && (*v8 != '\0')) {
label_405bbb:
          v1 = 0;
          v11 = parse_cvsroot(v8);
          if (v11 != (cvsroot_s *)0x0) goto label_4055b1;
          error(1,0,"Bad CVSROOT: `%s\'.",v25);
        }
        if (v18[3] != version) {
          error(0,0,"No CVSROOT specified!  Please use the `-d\' option");
          error(1,0,"or set the %s environment variable.","CVSROOT");
        }
        goto label_405947;
      }
      v1 = 1;
    }
    else {
      v11 = parse_cvsroot(dat_4cd470);
      v1 = 1;
      if (v11 == (cvsroot_s *)0x0) {
        error(1,0,"Bad CVSROOT: `%s\'.",dat_4cd470);
        goto label_4059c4;
      }
    }
label_4055b1:
    if (dat_4cca70 != (list *)0x0) goto label_405b0c;
    RAX = getlist();
    v12 = getnode();
    v8 = *(char **)v11;
    *(void *)v12 = 0;
    v8 = Xstrdup(v8);
    *(cvsroot_s **)((int8)v12 + 0x30) = v11;
    *(char **)((int8)v12 + 0x28) = v8;
    v4 = addnode(dat_4cca70);
    if (v4 != 0) {
      error(1,0,"cannot add initial CVSROOT %s",*(void *)((int8)v12 + 0x28));
    }
    if (dat_4ccc50 != (void *)0x0) goto label_405bf4;
  }
  else {
    v1 = 1;
label_405947:
    if (dat_4cca70 != (list *)0x0) {
label_405b0c:
                    /* WARNING: Subroutine does not return */
      __assert_fail("root_directories == NULL","main.c",0x3d7,0x49badc);
    }
    RAX = getlist();
    if (dat_4ccc50 != (void *)0x0) {
label_405bf4:
                    /* WARNING: Subroutine does not return */
      __assert_fail("current_parsed_root == NULL","main.c",999,0x49badc);
    }
    if (v18[3] == version) {
      dat_4ccce0 = 1;
    }
  }
  v2 = 0;
  v4 = 0;
  if (dat_4ccce0 == 0) goto label_40578b;
label_405628:
  if (RAX == (void *)0x0) goto label_405644;
label_40562d:
  if (*(char *)&RAX[3] != '\0') goto label_4056b0;
  if (dat_4ccce0 != 0) goto label_405644;
label_40563f:
  if (v2) goto label_405655;
label_405644:
  v2 = 1;
  cleanup_register(Lock_Cleanup);
  do {
label_405655:
    v4 = (*v18[3])(v20[0],v19);
    if (dat_4ccce0 != 0) {
label_405671:
      dellist((void **)0x4cca70);
      goto label_40567d;
    }
    v12 = findnode(dat_4cca70,(char *)*dat_4cd478);
    if (v12 == (node *)0x0) {
                    /* WARNING: Subroutine does not return */
      __assert_fail(0x4a3179,"main.c",0x463,0x49badc);
    }
    if (*(int8 *)((int8)v12 + 0x30) == 0) {
                    /* WARNING: Subroutine does not return */
      __assert_fail("n->data != NULL","main.c",0x464,0x49badc);
    }
    *(void *)((int8)v12 + 0x30) = 0;
    dat_4ccc50 = (void *)0x0;
    if (dat_4ccce0 != 0) goto label_405671;
label_40578b:
    v6 = walklist(dat_4cca70,set_root_directory,(void *)0x0);
    if (v6 == 0) goto label_405671;
    if (dat_4ccce0 != 0) goto label_405628;
    v8 = "(null)";
    if (dat_4ccc50 != (void *)0x0) {
      v8 = (char *)dat_4ccc50[2];
    }
    cvs_trace(1,"main loop with CVSROOT=%s",v8);
    if (*(char *)&dat_4ccc50[3] == '\0') {
      v8 = Xasprintf("%s/%s",dat_4ccc50[2],"CVSROOT");
      v3 = isaccessible(v8);
      v28 = 0;
      if (v3 == '\0') {
        v7 = 5;
        v24 = (uint1 *)0x49496e;
        v29 = 1;
        do {
          if (v7 == 0) goto label_4058ca;
          v7 = v7 + -1;
          v23 = &v24[(uint8)v30 * -2 + 1];
          v21 = &v22[(uint8)v30 * -2 + 1];
          v28 = *v22 < *v24;
          v29 = *v22 == *v24;
        } while (v29);
label_4058ca:
        if ((!v28 && !v29) != v28) {
          v13 = (int4 *)__errno_location();
          error(1,*v13,"%s",v8);
        }
      }
      free(v8);
    }
    if (v1) {
      setenv("CVSROOT",*dat_4ccc50,1);
    }
    if (dat_4ccce0 != 0) goto label_405628;
    if (*(char *)&RAX[3] == '\0') {
      if (dat_4cd450 != (config *)0x0) {
        free_config(dat_4cd450);
      }
      RAX = parse_config((char *)RDX[2],(char *)0x0);
      push_env_temp_dir();
      if (dat_4ccc50 != (void *)0x0) goto label_40562d;
    }
    else {
label_4056b0:
      if (dat_4cd400 != (list *)0x0) {
        dellist((void **)0x4cd400);
      }
      RAX = getlist();
    }
    if (dat_4ccce0 != 0) goto label_405644;
    if (*(char *)&dat_4ccc50[3] == '\0') goto label_40563f;
  } while( true );
}
kuna — after (option dedupvardecls on)
unsigned long main(int4 a0,void **a1)

{
  void **cpp; // rax
  char *end; // stack - 0x38
  int4 option_index; // stack - 0x3c
  bool v1;
  unsigned long v10; // rax
  cvsroot_s *v11; // rax
  node *v12; // rax
  int4 *v13; // rax
  char *v14; // rax
  code *v15; // rdx
  char *v16;
  void **v17; // rbx
  void **v18;
  void **v19; // stack - 0x58
  bool v2;
  int4 v20 [4]; // stack - 0x4c
  uint1 *v23; // rdi
  uint1 *v24;
  char *v25; // r13
  int8 v26; // fs_offset
  int8 v27; // fs_offset
  bool v28; // cf
  bool v29;
  char v3; // al
  uint1 v30; // df
  int8 v31; // stack - 0x30
  int4 v4;
  uint4 v5; // eax
  int4 v6; // eax
  int8 v7;
  uint8 v9; // rax
  
  v30 = 0;
  v31 = *(int8 *)(v26 + 0x28);
  v7 = getenv("CHESS");
  if (v7 == 0) {
    puts("Failed testbed check");
    if (v31 != *(int8 *)(v27 + 0x28)) {
                    /* WARNING: Subroutine does not return */
      __stack_chk_fail();
    }
    return 1;
  }
  option_index = 0;
  tzset();
  RAX = Xstrdup(*v19);
  RAX = last_component(*v19);
  v8 = (char *)getenv("CVSEDITOR");
  if ((((v8 != (char *)0x0) && (*v8 != '\0')) || ((v8 = (char *)getenv("VISUAL"), v8 != (char *)0x0 && (*v8 != '\0')))) || ((v8 = (char *)getenv(0x49777e), v8 != (char *)0x0 && (*v8 != '\0')))) {
  }
  v7 = getenv("CVSREAD");
  if (v7 != 0) {
    dat_4cbb54 = 0;
  }
  v7 = getenv("CVSREADONLYFS");
  if (v7 != 0) {
    dat_4cca7c = 1;
    dat_4cca78 = 1;
  }
  dat_4cc418 = 0;
  v18 = (void **)&option_index;
  dat_4cc440 = 0;
  while( true ) {
    v4 = getopt_long(v20[0],v19,"+QqrwgtnRvb:T:e:d:Hfz:s:xal",0x4cbb60,v18);
    if (v4 == -1) break;
    if (v4 == 0x66) {
      dat_4cbb58 = 0;
    }
  }
  if (dat_4cc418 < v20[0]) {
    Unique00023e00 = v19[dat_4cc418];
    v4 = strcmp((char *)Unique00023e00,"pserver");
    if ((v4 == 0) || (v4 = strcmp((char *)Unique00023e00,"server"), v4 == 0)) {
      dat_4cbb58 = 0;
      parseServerOptions(v20[0] - Unique10000e6f,&v19[dat_4cc418]);
    }
  }
  if (dat_4cbb58 != 0) {
    read_cvsrc(v20,&v19,"cvs");
  }
  dat_4cc418 = 0;
  v1 = 0;
  v8 = (char *)0x0;
  v24 = (uint1 *)0x49b8f0;
  dat_4cc440 = 1;
label_404f5c:
  v4 = getopt_long(v20[0],v19,"+QqrwgtnRvb:T:e:d:Hfz:s:xal",0x4cbb60,v18);
  if (v4 == -1) {
    v20[0] = v20[0] - dat_4cc418;
    v19 = &v19[dat_4cc418];
    if (1 <= v20[0]) {
      v9 = random();
      v5 = getpid();
      v10 = time(0);
      v18 = (void **)cmds;
      RAX = Xasprintf("1%010llX%04X%04X",v10,(uint8)v5 & 0xffff,v9 & 0xffff);
      v8 = "add";
      cvs_trace(1,"main: Session ID is %s",RAX);
      v24 = *v19;
      goto label_405419;
    }
    goto label_405a6a;
  }
  switch(v4) {
    default:
      goto label_405a6a;
    case 1:
      goto label_405a5e;
    case 2:
      v15 = cmds;
      v4 = 3;
      do {
        v15 = &v15[0x28];
        v4 = v4 + 1;
      } while (*(int8 *)v15 != 0);
      v15 = cmds;
      cpp = xnmalloc((int8)v4,8);
      v25 = "";
      v8 = "add";
      v18 = &cpp[1];
      *cpp = "CVS command synonyms are:\n";
      do {
        v16 = *(char **)&v15[8];
        v7 = *(int8 *)&v15[0x10];
        if (v16 == (char *)0x0) {
          if (v7 != 0) goto label_404ff6;
        }
        else {
          if (v7 == 0) {
            v7 = 0x4ab0a2;
          }
label_404ff6:
          v17 = &v18[1];
          v8 = Xasprintf("        %-12s %s %s\n",v8,v16,v7);
          *v18 = v8;
        }
        v8 = *(char **)&v15[0x28];
        v15 = &v15[0x28];
      } while (v8 != (char *)0x0);
      v18[1] = (void *)0x0;
      *v18 = "(Specify the --help option for a list of other help options)\n";
      usage(cpp);
      goto label_405bbb;
    case 3:
      root_allow_add(dat_4cc420,dat_4cd498);
      goto label_404f5c;
    case 4:
      usage((void **)opt_usage);
      goto label_405a41;
    case 0xe:
      root_allow_regexp_add(dat_4cc420,dat_4cd498);
      goto label_404f5c;
    case 0x48:
      v1 = 1;
      goto label_404f5c;
    case 0x51:
      dat_4cca8c = 1;
      goto label_405041;
    case 0x52:
      dat_4cca7c = 0xffffffff;
      dat_4cca78 = 1;
      goto label_404f5c;
    case 0x54:
      if (dat_4ccad0 != (char *)0x0) {
        free(dat_4ccad0);
      }
      RAX = Xstrdup(dat_4cc420);
      goto label_404f5c;
    case 0x61:
      dat_4cd480 = 1;
      goto label_404f5c;
    case 0x62:
    case 0x6c:
      goto label_404f5c;
    case 100:
      if (dat_4cd470 != (char *)0x0) {
        free(dat_4cd470);
      }
      RAX = Xstrdup(dat_4cc420);
      goto label_404f5c;
    case 0x65:
      if ((int4)v8 != 0) {
        free(dat_4cbc60);
      }
      v8 = (char *)0x1;
      RAX = Xstrdup(dat_4cc420);
      goto label_404f5c;
    case 0x66:
      dat_4cbb58 = 0;
      goto label_404f5c;
    case 0x67:
      v5 = umask(0x3f);
      umask(v5 & 7);
      goto label_404f5c;
    case 0x6e:
      dat_4cca80 = 1;
      dat_4cca78 = 1;
      goto label_404f5c;
    case 0x71:
label_405041:
      dat_4cca88 = 1;
      goto label_404f5c;
    case 0x72:
      dat_4cbb54 = 0;
      goto label_404f5c;
    case 0x73:
      variable_set(dat_4cc420);
      goto label_404f5c;
    case 0x74:
      dat_4cca84 = dat_4cca84 + 1;
      goto label_404f5c;
    case 0x76:
      fputc_unlocked();
      version(0,(char **)0x0);
      fputc_unlocked(10,dat_4cc400);
      fwrite_unlocked("Copyright (C) 2005 Free Software Foundation, Inc.\n\nPortions contributed by Thorsten Glaser for the MirOS Project and Debian.\nSenior active maintainers include Larry Jones, Derek R. Price,\nand Mark D. Baushke.  Please see the AUTHORS and README files from the CVS\ndistribution kit for a complete list of contributors and copyrights.\n",1,0x14c,dat_4cc400);
      fputc_unlocked(10,dat_4cc400);
      fwrite_unlocked("CVS may be copied only under the terms of the GNU General Public License,\n",1,0x4a,dat_4cc400);
      fwrite_unlocked("a copy of which can be found with the CVS distribution kit.\n",1,0x3c,dat_4cc400);
      fputc_unlocked(10,dat_4cc400);
      fwrite_unlocked("Specify the --help option for further information about CVS\n",1,0x3c,dat_4cc400);
                    /* WARNING: Subroutine does not return */
      exit(0);
    case 0x77:
      dat_4cbb54 = 1;
      goto label_404f5c;
    case 0x78:
      dat_4cd490 = 1;
      goto label_404f5c;
    case 0x7a:
      EAX = strtol(dat_4cc420,&end,10);
      if ((*end != '\0') || (10 <= EAX)) {
        error(1,0,"gzip compression level must be between 0 and 9");
      }
      goto label_404f5c;
    
  }
  while( true ) {
    Unique00023e00 = v18[5];
    v18 = &v18[5];
    v8 = (char *)0x0;
    if (Unique00023e00 == (uint1 *)0x0) break;
label_405419:
    if ((((v18[1] != (char *)0x0) && (v4 = strcmp((char *)v24,v18[1]), v4 == 0)) || ((v18[2] != (char *)0x0 && (v4 = strcmp((char *)v24,v18[2]), v4 == 0)))) || (v4 = strcmp((char *)v24,(char *)RBP), v4 == 0)) {
      if (v1) {
        v20[0] = -1;
        v4 = (*v18[3])(0xffffffff,v19);
label_40567d:
        dat_4cd450 = 0;
        root_allow_free();
                    /* WARNING: Subroutine does not return */
        exit(v4 != 0);
      }
      v8 = (char *)getenv();
      if ((v8 == (char *)0x0) || (*v8 == '\0')) goto label_4054a6;
      EAX = strtol(v8,&end,8);
      EAX = EAX & 0x1ff;
      if (*end == '\0') goto label_4054a6;
      goto label_405a76;
    }
  }
label_405a41:
  __fprintf_chk(dat_4cc460,1,"Unknown command: `%s\'\n\n",v24);
label_405a5e:
  usage((void **)cmd_usage);
label_405a6a:
  usage((void **)usg);
label_405a76:
  v13 = (int4 *)__errno_location();
  error(1,*v13,"invalid umask value in %s (%s)","CVSUMASK",v8);
label_4054a6:
  RAX = xgethostname();
  if (RAX == (char *)0x0) {
    v13 = (int4 *)__errno_location();
    error(0,*v13,"xgethostname () returned NULL, using \"localhost\"");
    RAX = Xstrdup("localhost");
  }
  RAX = Xstrdup(dat_4cd448);
  v4 = strcmp((char *)dat_4cd430,"pserver");
  if (v4 == 0) {
    pserver_start_listener();
    pserver_authenticate_connection();
    dat_4ccce0 = 1;
    v8 = "server";
label_405718:
    RAX = Xstrdup("<remote>");
    cleanup_register(server_cleanup);
  }
  else {
    v4 = strcmp((char *)dat_4cd430,"server");
    EDX = (uint4)(v4 == 0);
    if (v4 == 0) goto label_405718;
    cleanup_register(close_stdout);
    RAX = xgetcwd();
    if (RAX == (char *)0x0) {
      v13 = (int4 *)__errno_location();
      error(1,*v13,"cannot get working directory");
    }
  }
  v4 = getpid();
  v8 = Xasprintf("%ld",(int8)v4);
  setenv("CVS_PID",v8,1);
  free(v8);
  signals_register(main_cleanup);
  if (dat_4cbb58 != 0) {
    read_cvsrc(v20,&v19,(char *)dat_4cd430);
  }
  if (dat_4ccce0 == 0) {
    if (dat_4cd470 == (char *)0x0) {
label_4059c4:
      if ((((uint8)v18[4] & 1) != 0) || (v11 = Name_Root((char *)0x0,(char *)0x0), v11 == (cvsroot_s *)0x0)) {
        v1 = 1;
        v8 = (char *)getenv();
        if ((v8 != (char *)0x0) && (*v8 != '\0')) {
label_405bbb:
          v1 = 0;
          v11 = parse_cvsroot(v8);
          if (v11 != (cvsroot_s *)0x0) goto label_4055b1;
          error(1,0,"Bad CVSROOT: `%s\'.",v25);
        }
        if (v18[3] != version) {
          error(0,0,"No CVSROOT specified!  Please use the `-d\' option");
          error(1,0,"or set the %s environment variable.","CVSROOT");
        }
        goto label_405947;
      }
      v1 = 1;
    }
    else {
      v11 = parse_cvsroot(dat_4cd470);
      v1 = 1;
      if (v11 == (cvsroot_s *)0x0) {
        error(1,0,"Bad CVSROOT: `%s\'.",dat_4cd470);
        goto label_4059c4;
      }
    }
label_4055b1:
    if (dat_4cca70 != (list *)0x0) goto label_405b0c;
    RAX = getlist();
    v12 = getnode();
    v8 = *(char **)v11;
    *(void *)v12 = 0;
    v8 = Xstrdup(v8);
    *(cvsroot_s **)((int8)v12 + 0x30) = v11;
    *(char **)((int8)v12 + 0x28) = v8;
    v4 = addnode(dat_4cca70);
    if (v4 != 0) {
      error(1,0,"cannot add initial CVSROOT %s",*(void *)((int8)v12 + 0x28));
    }
    if (dat_4ccc50 != (void *)0x0) goto label_405bf4;
  }
  else {
    v1 = 1;
label_405947:
    if (dat_4cca70 != (list *)0x0) {
label_405b0c:
                    /* WARNING: Subroutine does not return */
      __assert_fail("root_directories == NULL","main.c",0x3d7,0x49badc);
    }
    RAX = getlist();
    if (dat_4ccc50 != (void *)0x0) {
label_405bf4:
                    /* WARNING: Subroutine does not return */
      __assert_fail("current_parsed_root == NULL","main.c",999,0x49badc);
    }
    if (v18[3] == version) {
      dat_4ccce0 = 1;
    }
  }
  v2 = 0;
  v4 = 0;
  if (dat_4ccce0 == 0) goto label_40578b;
label_405628:
  if (RAX == (void *)0x0) goto label_405644;
label_40562d:
  if (*(char *)&RAX[3] != '\0') goto label_4056b0;
  if (dat_4ccce0 != 0) goto label_405644;
label_40563f:
  if (v2) goto label_405655;
label_405644:
  v2 = 1;
  cleanup_register(Lock_Cleanup);
  do {
label_405655:
    v4 = (*v18[3])(v20[0],v19);
    if (dat_4ccce0 != 0) {
label_405671:
      dellist((void **)0x4cca70);
      goto label_40567d;
    }
    v12 = findnode(dat_4cca70,(char *)*dat_4cd478);
    if (v12 == (node *)0x0) {
                    /* WARNING: Subroutine does not return */
      __assert_fail(0x4a3179,"main.c",0x463,0x49badc);
    }
    if (*(int8 *)((int8)v12 + 0x30) == 0) {
                    /* WARNING: Subroutine does not return */
      __assert_fail("n->data != NULL","main.c",0x464,0x49badc);
    }
    *(void *)((int8)v12 + 0x30) = 0;
    dat_4ccc50 = (void *)0x0;
    if (dat_4ccce0 != 0) goto label_405671;
label_40578b:
    v6 = walklist(dat_4cca70,set_root_directory,(void *)0x0);
    if (v6 == 0) goto label_405671;
    if (dat_4ccce0 != 0) goto label_405628;
    v8 = "(null)";
    if (dat_4ccc50 != (void *)0x0) {
      v8 = (char *)dat_4ccc50[2];
    }
    cvs_trace(1,"main loop with CVSROOT=%s",v8);
    if (*(char *)&dat_4ccc50[3] == '\0') {
      v8 = Xasprintf("%s/%s",dat_4ccc50[2],"CVSROOT");
      v3 = isaccessible(v8);
      v28 = 0;
      if (v3 == '\0') {
        v7 = 5;
        v24 = (uint1 *)0x49496e;
        v29 = 1;
        do {
          if (v7 == 0) goto label_4058ca;
          v7 = v7 + -1;
          v23 = &v24[(uint8)v30 * -2 + 1];
          v21 = &v22[(uint8)v30 * -2 + 1];
          v28 = *v22 < *v24;
          v29 = *v22 == *v24;
        } while (v29);
label_4058ca:
        if ((!v28 && !v29) != v28) {
          v13 = (int4 *)__errno_location();
          error(1,*v13,"%s",v8);
        }
      }
      free(v8);
    }
    if (v1) {
      setenv("CVSROOT",*dat_4ccc50,1);
    }
    if (dat_4ccce0 != 0) goto label_405628;
    if (*(char *)&RAX[3] == '\0') {
      if (dat_4cd450 != (config *)0x0) {
        free_config(dat_4cd450);
      }
      RAX = parse_config((char *)RDX[2],(char *)0x0);
      push_env_temp_dir();
      if (dat_4ccc50 != (void *)0x0) goto label_40562d;
    }
    else {
label_4056b0:
      if (dat_4cd400 != (list *)0x0) {
        dellist((void **)0x4cd400);
      }
      RAX = getlist();
    }
    if (dat_4ccce0 != 0) goto label_405644;
    if (*(char *)&dat_4ccc50[3] == '\0') goto label_40563f;
  } while( true );
}
angr reference (the goal, v9.2.213)
typedef struct struct_0 {
    unsigned int field_0;
    unsigned int field_4;
    unsigned int field_8;
    unsigned int field_c;
} struct_0;

typedef struct struct_1 {
    char field_0[8];
    unsigned long long field_8;
    unsigned long long field_10;
    struct struct_2 *field_18;
    char field_20;
    char padding_21[7];
    struct struct_3 *field_28;
} struct_1;

typedef struct FILE {
} FILE;

typedef struct struct_4 {
    unsigned int field_0;
    char padding_4[36];
    long long field_28;
    struct struct_5 *field_30;
} struct_4;

typedef struct struct_2 {
    unsigned long long field_0;
} struct_2;

typedef struct struct_3 {
    char field_0;
} struct_3;

typedef struct struct_5 {
    unsigned long long field_0;
} struct_5;

typedef struct option {
    char * name;
    int has_arg;
    char padding_c[4];
    int * flag;
    int val;
} option;

extern void CVSroot_cmdline;
extern unsigned long long CurDir;
extern void* Editor;
extern FILE *__TMC_END__;
extern long long cmd_usage;
extern struct_1 cmds;
extern unsigned long long config;
extern void* current_parsed_root;
extern unsigned long long cvs_cmd_name;
extern unsigned int cvsauthenticate;
extern unsigned int cvsencrypt;
extern unsigned int cvsumask;
extern unsigned int cvswrite;
extern unsigned long long dirs_sent_to_server;
extern long long gConfigPath;
extern unsigned int g_49b8f0[4];
extern char g_4ab0a2;
extern long long global_session_id;
extern unsigned int gzip_level;
extern long long hostname;
extern unsigned int logoff;
extern option long_options.9386;
extern unsigned int noexec;
extern long long opt_usage;
extern void optarg;
extern unsigned int opterr;
extern unsigned int optind;
extern unsigned long long program_name;
extern unsigned long long program_path;
extern unsigned int quiet;
extern unsigned int readonlyfs;
extern unsigned int really_quiet;
extern long long root_directories;
extern unsigned int server_active;
extern unsigned long long server_hostname;
extern unsigned long long stderr;
extern void* tmpdir_cmdline;
extern unsigned int trace;
extern unsigned int use_cvsrc;
extern long long usg;

unsigned int main(int a0, struct_0 **a1)
{
    char *v5;  // rax
    struct_1 *cur;  // rbx
    struct_1 *v15;  // rdx
    unsigned int v16;  // eax
    struct_1 *v17;  // r12
    char *v18;  // r13
    struct_1 *ptr;  // rbp
    struct_1 *v20;  // r12
    struct_1 *v21;  // r12
    char *v22;  // rax
    unsigned int v7;  // eax
    unsigned short v23;  // ax
    unsigned short v24;  // ax
    struct_0 **addr;  // r14
    char *v26;  // rbp
    unsigned int v27;  // r13d
    unsigned int *err;  // rax
    unsigned int *err;  // rax
    unsigned long str;  // rax
    unsigned long v31;  // rbp
    unsigned long v8;  // r12
    unsigned int v32;  // eax
    long long v33;  // rdi
    long long v34;  // rsi
    long long v35;  // rdx
    long long v36;  // rcx
    long long v37;  // r8
    long long v38;  // r9
    unsigned int *err;  // rax
    struct_0 **ptr4;  // r14
    unsigned int v10[4];  // r13
    void* v40;  // rax
    char v41;  // r12b
    long long *ptr5;  // rbp
    struct_4 *ptr6;  // rax
    long long v44;  // rdi
    struct_4 *ptr;  // r13
    unsigned long long str;  // rax
    unsigned long v47;  // rax
    unsigned long long v48;  // 4098
    unsigned int v11;  // r13d
    unsigned long long v49;  // rax
    unsigned short v50;  // _bp
    unsigned int v12[4];  // r12
    unsigned int v13;  // eax
    struct_0 **v0;  // [bp-0x58]
    int v1;  // [bp-0x4c], Other Possible Types: unsigned int
    int flag;  // [bp-0x3c]
    char *v3;  // [bp-0x38]

    v1 = a0;
    v0 = a1;
    if (!getenv("CHESS"))
    {
        puts("Failed testbed check");
        return 1;
    }
    flag = 0;
    tzset();
    program_path = Xstrdup(*(v0));
    program_name = last_component(*(v0));
    v5 = getenv("CVSEDITOR");
    if (v5 && *(v5) || (v5 = getenv("VISUAL"), v5 && *(v5) || (v5 = getenv("EDITOR"), v5 && *(v5))))
        Editor = v5;
    if (getenv("CVSREAD"))
        cvswrite = 0;
    if (getenv("CVSREADONLYFS"))
    {
        readonlyfs = 1;
        logoff = 1;
    }
    optind = 0;
    cur = &flag;
    opterr = 0;
    while (true)
    {
        v7 = getopt_long(v1, v0, "+QqrwgtnRvb:T:e:d:Hfz:s:xal", &long_options.9386.name, &flag);
        if (v7 == 4294967295)
            break;
        if (v7 != 102)
            continue;
        use_cvsrc = 0;
    }
    v8 = optind;
    if ((unsigned int)v8 < v1)
    {
        ptr4 = &v0[(unsigned int)v8];
        v10 = *(ptr4);
        if (!strcmp(v10, "pserver") || !strcmp(v10, "server"))
        {
            cvs_cmd_name = v10;
            use_cvsrc = 0;
            parseServerOptions(v1 - v8, ptr4);
        }
    }
    if (use_cvsrc)
        read_cvsrc(&v1, &v0, "cvs");
    optind = 0;
    v11 = 0;
    v26 = NULL;
    v12 = &g_49b8f0[0];
    opterr = 1;
    while (true)
    {
        v13 = getopt_long(v1, v0, "+QqrwgtnRvb:T:e:d:Hfz:s:xal", &long_options.9386.name, &flag);
        if (v13 == 4294967295)
            break;
        switch (v13)
        {
        case 1:
            usage(&cmd_usage);
        case 2:
            v15 = &cmds.field_0[0];
            v16 = 3;
            do
            {
                v15 = &v15->field_28;
                v16 += 1;
            } while (v15->field_0);
            v17 = &cmds.field_0[0];
            v18 = &g_4ab0a2;
            ptr = xnmalloc(v16, 8);
            cur = &ptr->field_8;
            *((char **)&ptr->field_0[0]) = "CVS command synonyms are:\n";
            do
            {
                v20 = v17;
                if (!v20->field_8 && !v20->field_10)
                    continue;
                cur = &cur->field_8;
                cur->field_8 = Xasprintf("        %-12s %s %s\n");
            } while ((v21 = v20 + 40, v17 = v20 + 40, v20->field_28));
            cur->field_8 = 0;
            *((char **)&cur->field_0[0]) = "(Specify the --help option for a list of other help options)\n";
            v22 = usage(ptr);
            goto LABEL_405bbb;
        case 3:
            root_allow_add(*((long long *)&optarg), gConfigPath);
            break;
        case 4:
            usage(&opt_usage);
        case 14:
            root_allow_regexp_add(*((long long *)&optarg), gConfigPath);
            break;
        case 72:
            v11 = 1;
            break;
        case 82:
            readonlyfs = 4294967295;
            logoff = 1;
            break;
        case 84:
            if (tmpdir_cmdline)
                free(tmpdir_cmdline);
            tmpdir_cmdline = Xstrdup(*((long long *)&optarg));
            break;
        case 97:
            cvsauthenticate = 1;
            break;
        case 98: case 108:
            break;
        case 100:
            if (*((long long *)&CVSroot_cmdline))
                free(*((long long *)&CVSroot_cmdline));
            *((unsigned long long *)&CVSroot_cmdline) = Xstrdup(*((long long *)&optarg));
            break;
        case 101:
            if ((unsigned int)v26)
                free(Editor);
            v26 = 0x1;
            Editor = Xstrdup(*((long long *)&optarg));
            break;
        case 102:
            use_cvsrc = 0;
            break;
        case 103:
            umask(umask(63) & 7);
            break;
        case 110:
            noexec = 1;
            logoff = 1;
            break;
        case 114:
            cvswrite = 0;
            break;
        case 115:
            variable_set(*((long long *)&optarg));
            break;
        case 116:
            trace = trace + 1;
            break;
        case 118:
            fputc_unlocked(10, __TMC_END__);
            version(0, 0);
            fputc_unlocked(10, __TMC_END__);
            fwrite_unlocked("Copyright (C) 2005 Free Software Foundation, Inc.\n\nPortions contributed by Thorsten Glaser for the MirOS Project and Debian.\nSenior active maintainers include Larry Jones, Derek R. Price,\nand Mark D. Baushke.  Please see the AUTHORS and README files from the CVS\ndistribution kit for a complete list of contributors and copyrights.\n", 1, 332, __TMC_END__);
            fputc_unlocked(10, __TMC_END__);
            fwrite_unlocked("CVS may be copied only under the terms of the GNU General Public License,\n", 1, 74, __TMC_END__);
            fwrite_unlocked("a copy of which can be found with the CVS distribution kit.\n", 1, 60, __TMC_END__);
            fputc_unlocked(10, __TMC_END__);
            fwrite_unlocked("Specify the --help option for further information about CVS\n", 1, 60, __TMC_END__);
            exit(0); /* do not return */
        case 119:
            cvswrite = 1;
            break;
        case 120:
            cvsencrypt = 1;
            break;
        case 122:
            gzip_level = strtol(*((long long *)&optarg), &v3, 10);
            if (*(v3) || gzip_level > 9)
            {
                error(1, 0, "gzip compression level must be between 0 and 9");
                break;
            }
            break;
        case 81:
            really_quiet = 1;
        case 113:
            quiet = 1;
            break;
        default:
LABEL_405a6a:
            usage(&usg);
        }
    }
    v0 = &v0[optind];
    v1 -= optind;
    if (v1 <= 0)
        goto LABEL_405a6a;
    v23 = random();
    v24 = getpid();
    cur = &cmds.field_0[0];
    v26 = "add";
    global_session_id = Xasprintf("1%010llX%04X%04X", time(NULL), v24, v23);
    cvs_trace(1, "main: Session ID is %s", global_session_id);
    addr = v0;
    v12 = *(addr);
    cvs_cmd_name = v12;
    while ((!cur->field_8 || strcmp(v12, cur->field_8)) && (!cur->field_10 || strcmp(v12, cur->field_10)) && strcmp(v12, v26))
    {
        v26 = &cur->field_28->field_0;
        cur = &cur->field_28;
        if (!v26)
            __fprintf_chk(stderr, 0x1, "Unknown command: `%s'\n\n", v12);
    }
    cvs_cmd_name = v26;
    if (!v11)
    {
        v26 = getenv("CVSUMASK");
        if (v26 && *(v26) && !((cvsumask = (int)strtol(v26, &v3, 8) & 511, !*(v3))))
        {
            err = __errno_location();
            error(1, *(err), "invalid umask value in %s (%s)", "CVSUMASK", v26);
        }
        hostname = xgethostname();
        if (!hostname)
        {
            err = __errno_location();
            error(0, *(err), "xgethostname () returned NULL, using \"localhost\"");
            hostname = Xstrdup("localhost");
        }
        str = Xstrdup(hostname);
        v31 = cvs_cmd_name;
        server_hostname = str;
        if (strcmp(v31, "pserver"))
        {
            v32 = strcmp(v31, "server");
            server_active = !v32;
            if (v32)
            {
                cleanup_register(close_stdout);
                CurDir = xgetcwd(v33, v34, v35, v36, v37, v38);
                if (!CurDir)
                {
                    err = __errno_location();
                    error(1, *(err), "cannot get working directory");
                    goto LABEL_40552f;
                }
            }
        }
        else
        {
            pserver_start_listener();
            pserver_authenticate_connection(v33, v34, v35, v36, v37, v38);
            server_active = 1;
            cvs_cmd_name = "server";
        }
        CurDir = Xstrdup("<remote>");
        cleanup_register(server_cleanup);
LABEL_40552f:
        v40 = Xasprintf("%ld", (int)getpid());
        setenv("CVS_PID", v40, 1);
        free(v40);
        signals_register(main_cleanup);
        if (use_cvsrc)
            read_cvsrc(&v1, &v0, cvs_cmd_name);
        if (server_active)
        {
            v41 = 1;
            goto LABEL_405947;
        }
        if (*((long long *)&CVSroot_cmdline))
        {
            v41 = 1;
            ptr5 = parse_cvsroot(*((long long *)&CVSroot_cmdline));
            if (ptr5)
                goto LABEL_4055b1;
            error(1, 0, "Bad CVSROOT: `%s'.", *((long long *)&CVSroot_cmdline));
        }
        if ((cur->field_20 & 1) || !((ptr5 = (long long *)(unsigned long long)Name_Root(0, 0), ptr5)))
        {
            v41 = 1;
            v22 = getenv("CVSROOT");
            v18 = v22;
            if (!v22 || !*(v22))
                goto LABEL_4059f1;
LABEL_405bbb:
            v41 = 0;
            ptr5 = parse_cvsroot(v22);
            if (!ptr5)
            {
                error(1, 0, "Bad CVSROOT: `%s'.", v18);
LABEL_4059f1:
                if (cur->field_18 != version)
                {
                    error(0, 0, "No CVSROOT specified!  Please use the `-d' option");
                    error(1, 0, "or set the %s environment variable.", "CVSROOT");
                }
LABEL_405947:
                if (root_directories)
                {
LABEL_405b0c:
                    __assert_fail(); /* do not return */
                }
                v47 = getlist();
                v48 = current_parsed_root;
                root_directories = v47;
                if (v48)
                {
LABEL_405bf4:
                    __assert_fail(); /* do not return */
                }
                else if (cur->field_18 == version)
                {
                    server_active = 1;
                }
LABEL_40560f:
                v27 = server_active;
                v49 = current_parsed_root;
                v50 = 0;
                if (!server_active)
                    goto LABEL_0x40578b;
                if (!v49)
                    continue;
                if (!*((char *)(v49 + 24)) && (server_active || !v50))
                    continue;
                if (dirs_sent_to_server)
                    dellist(&dirs_sent_to_server);
                dirs_sent_to_server = getlist();
            }
        }
        else
        {
            v41 = 1;
        }
LABEL_4055b1:
        if (root_directories)
            goto LABEL_405b0c;
        root_directories = getlist();
        ptr6 = getnode(v33, v34, v35, v36, v37, v38);
        v44 = *(ptr5);
        ptr6->field_0 = 0;
        ptr = ptr6;
        str = Xstrdup(v44);
        ptr->field_30 = ptr5;
        ptr->field_28 = str;
        if ((int)addnode(root_directories, ptr))
            error(1, 0, "cannot add initial CVSROOT %s", ptr->field_28);
        if (current_parsed_root)
            goto LABEL_405bf4;
        goto LABEL_40560f;
    }
    else
    {
        v1 = 4294967295;
        v27 = cur->field_18(4294967295, addr);
    }
    config = 0;
    root_allow_free();
    exit(v27); /* do not return */
}

…n dedupvardecls, DIV-7)

Close the angr-vs-kuna gap on test_decompiling_x8664_cvs::main (x86_64/cvs): kuna
emitted a wall of duplicate local-variable declarations (the stack slot
`stack - 0x3c` declared 166x, `stack - 0x38` 53x) where angr declares each local
once -- the dominant cause of main being ~30% longer than angr (677 vs 472 loc).

kuna's C printer walks HighVariables (the W4 ScopeLocal Symbol walk is the missing
surface), so many distinct scalar highs sharing one stack slot, mapped by the
angr-style naming to the same name+type+storage, each emit one declaration line --
textually identical, strictly invalid C re-declarations. emit_local_var_decls now
skips a declaration whose fully-rendered signature (type + name + array adornment +
storage comment) is byte-identical to one already emitted: the scalar analogue of
the existing composite-symbol collapse, approximating Ghidra's once-per-Symbol
emitScopeVarDecls walk. Pure presentation: body markup is unchanged.

option dedupvardecls (arch flag dedup_var_decls, ElementId 4091), DIV-7 default-on:
ablation 0/675 (PARITY OK without re-pin), speed +0.14% (within 5% budget).
New module s9_emit/kuna_dedupvardecls.rs; stage test
tests/stages/ghangr-x8664-cvs-863633.xml (+2). main 680 -> 461 loc with the flag on.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@mahaloz

mahaloz commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

APPROVED

mahaloz added a commit that referenced this pull request Jun 25, 2026
Bring the dedupvardecls feature branch up to current main. Conflicts were
mechanical, additive registrations resolved by UNION:
- stages.toml: 39 settable blocks (foldcallret + dedupvardecls), header count updated
- catalog_bytecompat / kuna_stages tests: settable count 39
- xml corpus count: 135 (83 datatests + 52 stage testcases)
- kuna-catalog.xml / baseline KUNA-CATALOG #6: 5 angr-derived options
  (loweredswitch, namestyle, stackguard, foldcallret, dedupvardecls)
- PROGRESS.md: both session entries kept
- assertions.md + baseline-stages.json regenerated

Gates: catalog OK, make test PARITY OK (675/675), make test-stages PARITY OK (163/163).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
Bring the dedupvardecls feature branch up to current main. Conflicts were
mechanical, additive registrations resolved by UNION:
- stages.toml: 39 settable blocks (foldcallret + dedupvardecls), header count updated
- catalog_bytecompat / kuna_stages tests: settable count 39
- xml corpus count: 135 (83 datatests + 52 stage testcases)
- kuna-catalog.xml / baseline KUNA-CATALOG #6: 5 angr-derived options
  (loweredswitch, namestyle, stackguard, foldcallret, dedupvardecls)
- PROGRESS.md: both session entries kept
- assertions.md + baseline-stages.json regenerated

Gates: catalog OK, make test PARITY OK (675/675), make test-stages PARITY OK (163/163).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
@mahaloz
mahaloz force-pushed the feat/angr-x8664-cvs-863633 branch from 2ecbe48 to 736f11a Compare June 25, 2026 15:23
@mahaloz
mahaloz merged commit 8a76f22 into main Jun 25, 2026
@mahaloz
mahaloz deleted the feat/angr-x8664-cvs-863633 branch July 29, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant