// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/redis.c
// Function: initServerConfig
void initServerConfig() {
    int j;

    // 服务器状态

    // 设置服务器的运行 ID
    getRandomHexChars(server.runid,REDIS_RUN_ID_SIZE);
    // 设置默认配置文件路径
    server.configfile = NULL;
    // 设置默认服务器频率
    server.hz = REDIS_DEFAULT_HZ;
    // 为运行 ID 加上结尾字符
    server.runid[REDIS_RUN_ID_SIZE] = '\0';
    // 设置服务器的运行架构
    server.arch_bits = (sizeof(long) == 8) ? 64 : 32;
    // 设置默认服务器端口号
    server.port = REDIS_SERVERPORT;
    server.tcp_backlog = REDIS_TCP_BACKLOG;
    server.bindaddr_count = 0;
    server.unixsocket = NULL;
    server.unixsocketperm = REDIS_DEFAULT_UNIX_SOCKET_PERM;
    server.ipfd_count = 0;
    server.sofd = -1;
    server.dbnum = REDIS_DEFAULT_DBNUM;
    server.verbosity = REDIS_DEFAULT_VERBOSITY;
    server.maxidletime = REDIS_MAXIDLETIME;
    server.tcpkeepalive = REDIS_DEFAULT_TCP_KEEPALIVE;
    server.active_expire_enabled = 1;
    server.client_max_querybuf_len = REDIS_MAX_QUERYBUF_LEN;
    server.saveparams = NULL;
    server.loading = 0;
    server.logfile = zstrdup(REDIS_DEFAULT_LOGFILE);
    server.syslog_enabled = REDIS_DEFAULT_SYSLOG_ENABLED;
    server.syslog_ident = zstrdup(REDIS_DEFAULT_SYSLOG_IDENT);
    server.syslog_facility = LOG_LOCAL0;
    server.daemonize = REDIS_DEFAULT_DAEMONIZE;
    server.aof_state = REDIS_AOF_OFF;
    server.aof_fsync = REDIS_DEFAULT_AOF_FSYNC;
    server.aof_no_fsync_on_rewrite = REDIS_DEFAULT_AOF_NO_FSYNC_ON_REWRITE;
    server.aof_rewrite_perc = REDIS_AOF_REWRITE_PERC;
    server.aof_rewrite_min_size = REDIS_AOF_REWRITE_MIN_SIZE;
    server.aof_rewrite_base_size = 0;
    server.aof_rewrite_scheduled = 0;
    server.aof_last_fsync = time(NULL);
    server.aof_rewrite_time_last = -1;
    server.aof_rewrite_time_start = -1;
    server.aof_lastbgrewrite_status = REDIS_OK;
    server.aof_delayed_fsync = 0;
    server.aof_fd = -1;
    server.aof_selected_db = -1; /* Make sure the first time will not match */
    server.aof_flush_postponed_start = 0;
    server.aof_rewrite_incremental_fsync = REDIS_DEFAULT_AOF_REWRITE_INCREMENTAL_FSYNC;
    server.pidfile = zstrdup(REDIS_DEFAULT_PID_FILE);
    server.rdb_filename = zstrdup(REDIS_DEFAULT_RDB_FILENAME);
    server.aof_filename = zstrdup(REDIS_DEFAULT_AOF_FILENAME);
    server.requirepass = NULL;
    server.rdb_compression = REDIS_DEFAULT_RDB_COMPRESSION;
    server.rdb_checksum = REDIS_DEFAULT_RDB_CHECKSUM;
    server.stop_writes_on_bgsave_err = REDIS_DEFAULT_STOP_WRITES_ON_BGSAVE_ERROR;
    server.activerehashing = REDIS_DEFAULT_ACTIVE_REHASHING;
    server.notify_keyspace_events = 0;
    server.maxclients = REDIS_MAX_CLIENTS;
    server.bpop_blocked_clients = 0;
    server.maxmemory = REDIS_DEFAULT_MAXMEMORY;
    server.maxmemory_policy = REDIS_DEFAULT_MAXMEMORY_POLICY;
    server.maxmemory_samples = REDIS_DEFAULT_MAXMEMORY_SAMPLES;
    server.hash_max_ziplist_entries = REDIS_HASH_MAX_ZIPLIST_ENTRIES;
    server.hash_max_ziplist_value = REDIS_HASH_MAX_ZIPLIST_VALUE;
    server.list_max_ziplist_entries = REDIS_LIST_MAX_ZIPLIST_ENTRIES;
    server.list_max_ziplist_value = REDIS_LIST_MAX_ZIPLIST_VALUE;
    server.set_max_intset_entries = REDIS_SET_MAX_INTSET_ENTRIES;
    server.zset_max_ziplist_entries = REDIS_ZSET_MAX_ZIPLIST_ENTRIES;
    server.zset_max_ziplist_value = REDIS_ZSET_MAX_ZIPLIST_VALUE;
    server.hll_sparse_max_bytes = REDIS_DEFAULT_HLL_SPARSE_MAX_BYTES;
    server.shutdown_asap = 0;
    server.repl_ping_slave_period = REDIS_REPL_PING_SLAVE_PERIOD;
    server.repl_timeout = REDIS_REPL_TIMEOUT;
    server.repl_min_slaves_to_write = REDIS_DEFAULT_MIN_SLAVES_TO_WRITE;
    server.repl_min_slaves_max_lag = REDIS_DEFAULT_MIN_SLAVES_MAX_LAG;
    server.cluster_enabled = 0;
    server.cluster_node_timeout = REDIS_CLUSTER_DEFAULT_NODE_TIMEOUT;
    server.cluster_migration_barrier = REDIS_CLUSTER_DEFAULT_MIGRATION_BARRIER;
    server.cluster_configfile = zstrdup(REDIS_DEFAULT_CLUSTER_CONFIG_FILE);
    server.lua_caller = NULL;
    server.lua_time_limit = REDIS_LUA_TIME_LIMIT;
    server.lua_client = NULL;
    server.lua_timedout = 0;
    server.migrate_cached_sockets = dictCreate(&migrateCacheDictType,NULL);
    server.loading_process_events_interval_bytes = (1024*1024*2);

    // 初始化 LRU 时间
    server.lruclock = getLRUClock();

    // 初始化并设置保存条件
    resetServerSaveParams();

    appendServerSaveParams(60*60,1);  /* save after 1 hour and 1 change */
    appendServerSaveParams(300,100);  /* save after 5 minutes and 100 changes */
    appendServerSaveParams(60,10000); /* save after 1 minute and 10000 changes */

    /* Replication related */
    // 初始化和复制相关的状态
    server.masterauth = NULL;
    server.masterhost = NULL;
    server.masterport = 6379;
    server.master = NULL;
    server.cached_master = NULL;
    server.repl_master_initial_offset = -1;
    server.repl_state = REDIS_REPL_NONE;
    server.repl_syncio_timeout = REDIS_REPL_SYNCIO_TIMEOUT;
    server.repl_serve_stale_data = REDIS_DEFAULT_SLAVE_SERVE_STALE_DATA;
    server.repl_slave_ro = REDIS_DEFAULT_SLAVE_READ_ONLY;
    server.repl_down_since = 0; /* Never connected, repl is down since EVER. */
    server.repl_disable_tcp_nodelay = REDIS_DEFAULT_REPL_DISABLE_TCP_NODELAY;
    server.slave_priority = REDIS_DEFAULT_SLAVE_PRIORITY;
    server.master_repl_offset = 0;

    /* Replication partial resync backlog */
    // 初始化 PSYNC 命令所使用的 backlog
    server.repl_backlog = NULL;
    server.repl_backlog_size = REDIS_DEFAULT_REPL_BACKLOG_SIZE;
    server.repl_backlog_histlen = 0;
    server.repl_backlog_idx = 0;
    server.repl_backlog_off = 0;
    server.repl_backlog_time_limit = REDIS_DEFAULT_REPL_BACKLOG_TIME_LIMIT;
    server.repl_no_slaves_since = time(NULL);

    /* Client output buffer limits */
    // 设置客户端的输出缓冲区限制
    for (j = 0; j < REDIS_CLIENT_LIMIT_NUM_CLASSES; j++)
        server.client_obuf_limits[j] = clientBufferLimitsDefaults[j];

    /* Double constants initialization */
    // 初始化浮点常量
    R_Zero = 0.0;
    R_PosInf = 1.0/R_Zero;
    R_NegInf = -1.0/R_Zero;
    R_Nan = R_Zero/R_Zero;

    /* Command table -- we initiialize it here as it is part of the
     * initial configuration, since command names may be changed via
     * redis.conf using the rename-command directive. */
    // 初始化命令表
    // 在这里初始化是因为接下来读取 .conf 文件时可能会用到这些命令
    server.commands = dictCreate(&commandTableDictType,NULL);
    server.orig_commands = dictCreate(&commandTableDictType,NULL);
    populateCommandTable();
    server.delCommand = lookupCommandByCString("del");
    server.multiCommand = lookupCommandByCString("multi");
    server.lpushCommand = lookupCommandByCString("lpush");
    server.lpopCommand = lookupCommandByCString("lpop");
    server.rpopCommand = lookupCommandByCString("rpop");
    
    /* Slow log */
    // 初始化慢查询日志
    server.slowlog_log_slower_than = REDIS_SLOWLOG_LOG_SLOWER_THAN;
    server.slowlog_max_len = REDIS_SLOWLOG_MAX_LEN;

    /* Debugging */
    // 初始化调试项
    server.assert_failed = "<no assertion failed>";
    server.assert_file = "<no file>";
    server.assert_line = 0;
    server.bug_report_start = 0;
    server.watchdog_period = 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0xa5544(%rip), %rdi     # 0xca000
movl $0x28, %esi
callq 0x3036a
xorl %r14d, %r14d
movq %r14, 0xa54d8(%rip)     # 0xc9fa8
movl $0xa, %ebx
movl %ebx, 0xa54d5(%rip)     # 0xc9fb0
movb $0x0, 0xa5546(%rip)     # 0xca028
movl $0x40, 0xa550c(%rip)    # 0xc9ff8
movabsq $0x1ff000018eb, %rax    # imm = 0x1FF000018EB
movq %rax, 0xa5533(%rip)     # 0xca030
movl %r14d, 0xa55b4(%rip)    # 0xca0b8
movq %r14, 0xa55b5(%rip)     # 0xca0c0
movl %r14d, 0xa55b6(%rip)    # 0xca0c8
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0xa55e9(%rip)     # 0xca10c
movl $0x10, 0xa58fb(%rip)    # 0xca428
movdqa 0x6f6eb(%rip), %xmm0    # 0x94220
movdqu %xmm0, 0xa58cf(%rip)    # 0xca40c
movq $0x40000000, 0xa58d8(%rip) # imm = 0x40000000
movq %r14, 0xa59d1(%rip)     # 0xca520
movl %r14d, 0xa5742(%rip)    # 0xca298
leaq 0x727e4(%rip), %rdi     # 0x97341
callq 0x29b31
movq %rax, 0xa5a0f(%rip)     # 0xca578
movl %r14d, 0xa5a10(%rip)    # 0xca580
leaq 0x701da(%rip), %rdi     # 0x94d51
callq 0x29b31
movq %rax, 0xa5a05(%rip)     # 0xca588
movl $0x80, 0xa5a03(%rip)    # 0xca590
movl %r14d, 0xa5898(%rip)    # 0xca42c
movabsq $0x200000000, %rax      # imm = 0x200000000
movq %rax, 0xa58d3(%rip)     # 0xca478
movabsq $0x6400000000, %r12     # imm = 0x6400000000
movq %r12, 0xa58d2(%rip)     # 0xca488
movq $0x4000000, 0xa58cf(%rip) # imm = 0x4000000
movq %r14, 0xa58d0(%rip)     # 0xca498
movl %r14d, 0xa58d9(%rip)    # 0xca4a8
xorl %edi, %edi
callq 0x1fc50
movq %rax, 0xa58f3(%rip)     # 0xca4d0
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xa58ef(%rip)    # 0xca4d8
movl %r14d, 0xa58f8(%rip)    # 0xca4e8
movq %r14, 0xa58f9(%rip)     # 0xca4f0
movq $-0x1, %r13
movq %r13, 0xa58bb(%rip)     # 0xca4c0
movq %r14, 0xa58bc(%rip)     # 0xca4c8
movl $0x1, %r15d
movl %r15d, 0xa58df(%rip)    # 0xca4f8
leaq 0x70137(%rip), %rdi     # 0x94d57
callq 0x29b31
movq %rax, 0xa53c4(%rip)     # 0xc9ff0
leaq 0x70137(%rip), %rdi     # 0x94d6a
callq 0x29b31
movq %rax, 0xa58f1(%rip)     # 0xca530
leaq 0x7012d(%rip), %rdi     # 0x94d73
callq 0x29b31
movq %rax, 0xa582e(%rip)     # 0xca480
movq %r14, 0xa538f(%rip)     # 0xc9fe8
movabsq $0x100000001, %rbp      # imm = 0x100000001
movq %rbp, 0xa58ce(%rip)     # 0xca538
movl %r15d, 0xa58f3(%rip)    # 0xca564
movl %r15d, 0xa5368(%rip)    # 0xc9fe0
movl %r14d, 0xa5ae1(%rip)    # 0xca760
movl $0x2710, 0xa5a3b(%rip)  # imm = 0x2710
movl %r14d, 0xa5a48(%rip)    # 0xca6d8
movq %r14, 0xa5a31(%rip)     # 0xca6c8
movabsq $0x500000005, %rax      # imm = 0x500000005
movq %rax, 0xa5a28(%rip)     # 0xca6d0
movl $0x200, %eax            # imm = 0x200
movq %rax, 0xa5a4c(%rip)     # 0xca700
movl $0x40, %ecx
movq %rcx, 0xa5a48(%rip)     # 0xca708
movq %rax, 0xa5a49(%rip)     # 0xca710
movq %rcx, 0xa5a4a(%rip)     # 0xca718
movq %rax, 0xa5a4b(%rip)     # 0xca720
movl $0x80, %eax
movq %rax, 0xa5a47(%rip)     # 0xca728
movq %rcx, 0xa5a48(%rip)     # 0xca730
movq $0xbb8, 0xa5a45(%rip) # imm = 0xBB8
movl %r14d, 0xa52e2(%rip)    # 0xc9fdc
movl %ebx, 0xa58a0(%rip)     # 0xca5a0
movl $0x3c, 0xa58fa(%rip)    # 0xca604
movabsq $0xa00000000, %rax      # imm = 0xA00000000
movq %rax, 0xa58c5(%rip)     # 0xca5e0
movl %r14d, 0xa5a42(%rip)    # 0xca764
movq $0x3a98, 0xa5a3b(%rip) # imm = 0x3A98
movl %r15d, 0xa5a4c(%rip)    # 0xca780
leaq 0x70047(%rip), %rdi     # 0x94d82
callq 0x29b31
movq %rax, 0xa5a29(%rip)     # 0xca770
movq $0x1388, 0xa5a56(%rip) # imm = 0x1388
pxor %xmm0, %xmm0
movdqu %xmm0, 0xa5a32(%rip)    # 0xca790
movl %r14d, 0xa5a5b(%rip)    # 0xca7c0
leaq 0xa4ce4(%rip), %rdi     # 0xc9a50
xorl %esi, %esi
callq 0x2217b
movq %rax, 0xa5516(%rip)     # 0xca290
movq $0x200000, 0xa5533(%rip) # imm = 0x200000
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1f2f0
imulq $0xf4240, (%rbx), %rax  # imm = 0xF4240
addq 0x8(%rbx), %rax
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x12, %rdx
addl %eax, %edx
andl $0xffffff, %edx         # imm = 0xFFFFFF
movzbl 0xa5215(%rip), %eax     # 0xc9fdb
shll $0x18, %eax
orl %edx, %eax
movl %eax, 0xa5207(%rip)     # 0xc9fd8
xorl %eax, %eax
callq 0x43822
movl $0xe10, %edi            # imm = 0xE10
movl $0x1, %esi
callq 0x437cc
movl $0x12c, %edi            # imm = 0x12C
movl $0x64, %esi
callq 0x437cc
movl $0x3c, %edi
movl $0x2710, %esi           # imm = 0x2710
callq 0x437cc
pxor %xmm0, %xmm0
movdqu %xmm0, 0xa57df(%rip)    # 0xca5f0
movl $0x18eb, 0xa57e5(%rip)  # imm = 0x18EB
movdqu %xmm0, 0xa57e5(%rip)    # 0xca608
movq %r13, 0xa586e(%rip)     # 0xca698
movl %r14d, 0xa57eb(%rip)    # 0xca61c
movl $0x5, 0xa57dd(%rip)     # 0xca618
movq %rbp, 0xa580e(%rip)     # 0xca650
movq %r14, 0xa580f(%rip)     # 0xca658
movq %r12, 0xa5810(%rip)     # 0xca660
movq %r14, 0xa5741(%rip)     # 0xca598
movq %r14, 0xa574a(%rip)     # 0xca5a8
movq $0x100000, 0xa5747(%rip) # imm = 0x100000
movdqu %xmm0, 0xa5747(%rip)    # 0xca5b8
movq %r14, 0xa5750(%rip)     # 0xca5c8
movq $0xe10, 0xa574d(%rip) # imm = 0xE10
xorl %edi, %edi
callq 0x1fc50
movq %rax, 0xa5747(%rip)     # 0xca5d8
leaq 0xa5598(%rip), %rdi     # 0xca430
leaq 0xa4c21(%rip), %rsi     # 0xc9ac0
movl $0x9, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq %r14, 0xb9582(%rip)     # 0xde430
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
movq %rax, 0xb9579(%rip)     # 0xde438
movabsq $-0x10000000000000, %rax # imm = 0xFFF0000000000000
movq %rax, 0xb9570(%rip)     # 0xde440
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
movq %rax, 0xb9567(%rip)     # 0xde448
leaq 0xa4a78(%rip), %rbx     # 0xc9960
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2217b
movq %rax, 0xa50c7(%rip)     # 0xc9fc0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2217b
movq %rax, 0xa50be(%rip)     # 0xc9fc8
callq 0x24fbe
leaq 0x6f5c7(%rip), %rdi     # 0x944dd
callq 0x25119
movq %rax, 0xa539e(%rip)     # 0xca2c0
leaq 0x6f664(%rip), %rdi     # 0x9458d
callq 0x25119
movq %rax, 0xa5393(%rip)     # 0xca2c8
leaq 0x6f3eb(%rip), %rdi     # 0x94327
callq 0x25119
movq %rax, 0xa5388(%rip)     # 0xca2d0
leaq 0x6f3e3(%rip), %rdi     # 0x94332
callq 0x25119
movq %rax, 0xa537d(%rip)     # 0xca2d8
leaq 0x6f3b8(%rip), %rdi     # 0x9431a
callq 0x25119
movq %rax, 0xa5372(%rip)     # 0xca2e0
movq $0x2710, 0xa53e7(%rip) # imm = 0x2710
movl $0x80, %eax
movq %rax, 0xa53e3(%rip)     # 0xca368
leaq 0x6fe01(%rip), %rax     # 0x94d8d
movq %rax, 0xa5835(%rip)     # 0xca7c8
leaq 0x6fe09(%rip), %rax     # 0x94da3
movq %rax, 0xa582f(%rip)     # 0xca7d0
movq %r14, 0xa5830(%rip)     # 0xca7d8
movl %r14d, 0xa5831(%rip)    # 0xca7e0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq