// File: /workspace/github_c_makefile_star2_O1/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 0xa5724(%rip), %rdi     # 0xca000
movl $0x28, %esi
callq 0x30096
xorl %r14d, %r14d
movq %r14, 0xa56b8(%rip)     # 0xc9fa8
movl $0xa, %ebx
movl %ebx, 0xa56b5(%rip)     # 0xc9fb0
movb $0x0, 0xa5726(%rip)     # 0xca028
movl $0x40, 0xa56ec(%rip)    # 0xc9ff8
movabsq $0x1ff000018eb, %rax    # imm = 0x1FF000018EB
movq %rax, 0xa5713(%rip)     # 0xca030
movl %r14d, 0xa5794(%rip)    # 0xca0b8
movq %r14, 0xa5795(%rip)     # 0xca0c0
movl %r14d, 0xa5796(%rip)    # 0xca0c8
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0xa57c9(%rip)     # 0xca10c
movl $0x10, 0xa5adb(%rip)    # 0xca428
movdqa 0x6f87b(%rip), %xmm0    # 0x941d0
movdqu %xmm0, 0xa5aaf(%rip)    # 0xca40c
movq $0x40000000, 0xa5ab8(%rip) # imm = 0x40000000
movq %r14, 0xa5bb1(%rip)     # 0xca520
movl %r14d, 0xa5922(%rip)    # 0xca298
leaq 0x72964(%rip), %rdi     # 0x972e1
callq 0x29885
movq %rax, 0xa5bef(%rip)     # 0xca578
movl %r14d, 0xa5bf0(%rip)    # 0xca580
leaq 0x7036a(%rip), %rdi     # 0x94d01
callq 0x29885
movq %rax, 0xa5be5(%rip)     # 0xca588
movl $0x80, 0xa5be3(%rip)    # 0xca590
movl %r14d, 0xa5a78(%rip)    # 0xca42c
movabsq $0x200000000, %rax      # imm = 0x200000000
movq %rax, 0xa5ab3(%rip)     # 0xca478
movabsq $0x6400000000, %r12     # imm = 0x6400000000
movq %r12, 0xa5ab2(%rip)     # 0xca488
movq $0x4000000, 0xa5aaf(%rip) # imm = 0x4000000
movq %r14, 0xa5ab0(%rip)     # 0xca498
movl %r14d, 0xa5ab9(%rip)    # 0xca4a8
xorl %edi, %edi
callq 0x1fc50
movq %rax, 0xa5ad3(%rip)     # 0xca4d0
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xa5acf(%rip)    # 0xca4d8
movl %r14d, 0xa5ad8(%rip)    # 0xca4e8
movq %r14, 0xa5ad9(%rip)     # 0xca4f0
movq $-0x1, %r13
movq %r13, 0xa5a9b(%rip)     # 0xca4c0
movq %r14, 0xa5a9c(%rip)     # 0xca4c8
movl $0x1, %r15d
movl %r15d, 0xa5abf(%rip)    # 0xca4f8
leaq 0x702c7(%rip), %rdi     # 0x94d07
callq 0x29885
movq %rax, 0xa55a4(%rip)     # 0xc9ff0
leaq 0x702c7(%rip), %rdi     # 0x94d1a
callq 0x29885
movq %rax, 0xa5ad1(%rip)     # 0xca530
leaq 0x702bd(%rip), %rdi     # 0x94d23
callq 0x29885
movq %rax, 0xa5a0e(%rip)     # 0xca480
movq %r14, 0xa556f(%rip)     # 0xc9fe8
movabsq $0x100000001, %rbp      # imm = 0x100000001
movq %rbp, 0xa5aae(%rip)     # 0xca538
movl %r15d, 0xa5ad3(%rip)    # 0xca564
movl %r15d, 0xa5548(%rip)    # 0xc9fe0
movl %r14d, 0xa5cc1(%rip)    # 0xca760
movl $0x2710, 0xa5c1b(%rip)  # imm = 0x2710
movl %r14d, 0xa5c28(%rip)    # 0xca6d8
movq %r14, 0xa5c11(%rip)     # 0xca6c8
movabsq $0x500000005, %rax      # imm = 0x500000005
movq %rax, 0xa5c08(%rip)     # 0xca6d0
movl $0x200, %eax            # imm = 0x200
movq %rax, 0xa5c2c(%rip)     # 0xca700
movl $0x40, %ecx
movq %rcx, 0xa5c28(%rip)     # 0xca708
movq %rax, 0xa5c29(%rip)     # 0xca710
movq %rcx, 0xa5c2a(%rip)     # 0xca718
movq %rax, 0xa5c2b(%rip)     # 0xca720
movl $0x80, %eax
movq %rax, 0xa5c27(%rip)     # 0xca728
movq %rcx, 0xa5c28(%rip)     # 0xca730
movq $0xbb8, 0xa5c25(%rip) # imm = 0xBB8
movl %r14d, 0xa54c2(%rip)    # 0xc9fdc
movl %ebx, 0xa5a80(%rip)     # 0xca5a0
movl $0x3c, 0xa5ada(%rip)    # 0xca604
movabsq $0xa00000000, %rax      # imm = 0xA00000000
movq %rax, 0xa5aa5(%rip)     # 0xca5e0
movl %r14d, 0xa5c22(%rip)    # 0xca764
movq $0x3a98, 0xa5c1b(%rip) # imm = 0x3A98
movl %r15d, 0xa5c2c(%rip)    # 0xca780
leaq 0x701d7(%rip), %rdi     # 0x94d32
callq 0x29885
movq %rax, 0xa5c09(%rip)     # 0xca770
movq $0x1388, 0xa5c36(%rip) # imm = 0x1388
pxor %xmm0, %xmm0
movdqu %xmm0, 0xa5c12(%rip)    # 0xca790
movl %r14d, 0xa5c3b(%rip)    # 0xca7c0
leaq 0xa4ec4(%rip), %rdi     # 0xc9a50
xorl %esi, %esi
callq 0x21f97
movq %rax, 0xa56f6(%rip)     # 0xca290
movq $0x200000, 0xa5713(%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 0xa53f5(%rip), %eax     # 0xc9fdb
shll $0x18, %eax
orl %edx, %eax
movl %eax, 0xa53e7(%rip)     # 0xc9fd8
xorl %eax, %eax
callq 0x43972
movl $0xe10, %edi            # imm = 0xE10
movl $0x1, %esi
callq 0x4391c
movl $0x12c, %edi            # imm = 0x12C
movl $0x64, %esi
callq 0x4391c
movl $0x3c, %edi
movl $0x2710, %esi           # imm = 0x2710
callq 0x4391c
pxor %xmm0, %xmm0
movdqu %xmm0, 0xa59bf(%rip)    # 0xca5f0
movl $0x18eb, 0xa59c5(%rip)  # imm = 0x18EB
movdqu %xmm0, 0xa59c5(%rip)    # 0xca608
movq %r13, 0xa5a4e(%rip)     # 0xca698
movl %r14d, 0xa59cb(%rip)    # 0xca61c
movl $0x5, 0xa59bd(%rip)     # 0xca618
movq %rbp, 0xa59ee(%rip)     # 0xca650
movq %r14, 0xa59ef(%rip)     # 0xca658
movq %r12, 0xa59f0(%rip)     # 0xca660
movq %r14, 0xa5921(%rip)     # 0xca598
movq %r14, 0xa592a(%rip)     # 0xca5a8
movq $0x100000, 0xa5927(%rip) # imm = 0x100000
movdqu %xmm0, 0xa5927(%rip)    # 0xca5b8
movq %r14, 0xa5930(%rip)     # 0xca5c8
movq $0xe10, 0xa592d(%rip) # imm = 0xE10
xorl %edi, %edi
callq 0x1fc50
movq %rax, 0xa5927(%rip)     # 0xca5d8
leaq 0xa5778(%rip), %rdi     # 0xca430
leaq 0xa4e01(%rip), %rsi     # 0xc9ac0
movl $0x9, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq %r14, 0xb9762(%rip)     # 0xde430
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
movq %rax, 0xb9759(%rip)     # 0xde438
movabsq $-0x10000000000000, %rax # imm = 0xFFF0000000000000
movq %rax, 0xb9750(%rip)     # 0xde440
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
movq %rax, 0xb9747(%rip)     # 0xde448
leaq 0xa4c58(%rip), %rbx     # 0xc9960
movq %rbx, %rdi
xorl %esi, %esi
callq 0x21f97
movq %rax, 0xa52a7(%rip)     # 0xc9fc0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x21f97
movq %rax, 0xa529e(%rip)     # 0xc9fc8
callq 0x24dde
leaq 0x6f757(%rip), %rdi     # 0x9448d
callq 0x24f39
movq %rax, 0xa557e(%rip)     # 0xca2c0
leaq 0x6f7f4(%rip), %rdi     # 0x9453d
callq 0x24f39
movq %rax, 0xa5573(%rip)     # 0xca2c8
leaq 0x6f57b(%rip), %rdi     # 0x942d7
callq 0x24f39
movq %rax, 0xa5568(%rip)     # 0xca2d0
leaq 0x6f573(%rip), %rdi     # 0x942e2
callq 0x24f39
movq %rax, 0xa555d(%rip)     # 0xca2d8
leaq 0x6f548(%rip), %rdi     # 0x942ca
callq 0x24f39
movq %rax, 0xa5552(%rip)     # 0xca2e0
movq $0x2710, 0xa55c7(%rip) # imm = 0x2710
movl $0x80, %eax
movq %rax, 0xa55c3(%rip)     # 0xca368
leaq 0x6ff91(%rip), %rax     # 0x94d3d
movq %rax, 0xa5a15(%rip)     # 0xca7c8
leaq 0x6ff99(%rip), %rax     # 0x94d53
movq %rax, 0xa5a0f(%rip)     # 0xca7d0
movq %r14, 0xa5a10(%rip)     # 0xca7d8
movl %r14d, 0xa5a11(%rip)    # 0xca7e0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq