// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
leaq 0xa343c(%rip), %rdi     # 0xc7000
pushq $0x28
popq %rsi
callq 0x2e796
andq $0x0, 0xa33d4(%rip)     # 0xc6fa8
pushq $0xa
popq %rbp
movl %ebp, 0xa33d3(%rip)     # 0xc6fb0
movb $0x0, 0xa3444(%rip)     # 0xc7028
movl $0x40, 0xa340a(%rip)    # 0xc6ff8
movabsq $0x1ff000018eb, %rax    # imm = 0x1FF000018EB
movq %rax, 0xa3431(%rip)     # 0xc7030
andl $0x0, 0xa34b2(%rip)     # 0xc70b8
andq $0x0, 0xa34b2(%rip)     # 0xc70c0
andl $0x0, 0xa34b3(%rip)     # 0xc70c8
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0xa34e6(%rip)     # 0xc710c
movl $0x10, 0xa37f8(%rip)    # 0xc7428
movdqa 0x66598(%rip), %xmm0    # 0x8a1d0
movdqu %xmm0, 0xa37cc(%rip)    # 0xc740c
movq $0x40000000, 0xa37d5(%rip) # imm = 0x40000000
andq $0x0, 0xa38cd(%rip)     # 0xc7520
andl $0x0, 0xa363e(%rip)     # 0xc7298
leaq 0x696b0(%rip), %rdi     # 0x8d311
callq 0x28407
movq %rax, 0xa390b(%rip)     # 0xc7578
andl $0x0, 0xa390c(%rip)     # 0xc7580
leaq 0x67096(%rip), %rdi     # 0x8ad11
callq 0x28407
movq %rax, 0xa3901(%rip)     # 0xc7588
movl $0x80, 0xa38ff(%rip)    # 0xc7590
andl $0x0, 0xa3794(%rip)     # 0xc742c
movabsq $0x200000000, %rax      # imm = 0x200000000
movq %rax, 0xa37cf(%rip)     # 0xc7478
movabsq $0x6400000000, %r15     # imm = 0x6400000000
movq %r15, 0xa37ce(%rip)     # 0xc7488
movq $0x4000000, 0xa37cb(%rip) # imm = 0x4000000
andq $0x0, 0xa37cb(%rip)     # 0xc7498
andl $0x0, 0xa37d4(%rip)     # 0xc74a8
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x1fc50
movq %rax, 0xa37eb(%rip)     # 0xc74d0
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xa37e7(%rip)    # 0xc74d8
andl $0x0, 0xa37f0(%rip)     # 0xc74e8
andq $0x0, 0xa37f0(%rip)     # 0xc74f0
orq $-0x1, 0xa37b8(%rip)    # 0xc74c0
andq $0x0, 0xa37b8(%rip)     # 0xc74c8
pushq $0x1
popq %rbx
movl %ebx, 0xa37df(%rip)     # 0xc74f8
leaq 0x66ff7(%rip), %rdi     # 0x8ad17
callq 0x28407
movq %rax, 0xa32c4(%rip)     # 0xc6ff0
leaq 0x66ff7(%rip), %rdi     # 0x8ad2a
callq 0x28407
movq %rax, 0xa37f1(%rip)     # 0xc7530
leaq 0x66fed(%rip), %rdi     # 0x8ad33
callq 0x28407
movq %rax, 0xa372e(%rip)     # 0xc7480
andq $0x0, 0xa328e(%rip)     # 0xc6fe8
movabsq $0x100000001, %r12      # imm = 0x100000001
movq %r12, 0xa37cd(%rip)     # 0xc7538
movl %ebx, 0xa37f3(%rip)     # 0xc7564
movl %ebx, 0xa3269(%rip)     # 0xc6fe0
andl $0x0, 0xa39e2(%rip)     # 0xc7760
movl $0x2710, 0xa393c(%rip)  # imm = 0x2710
andl $0x0, 0xa3949(%rip)     # 0xc76d8
andq $0x0, 0xa3931(%rip)     # 0xc76c8
movabsq $0x500000005, %rax      # imm = 0x500000005
movq %rax, 0xa3928(%rip)     # 0xc76d0
movl $0x200, %eax            # imm = 0x200
movq %rax, 0xa394c(%rip)     # 0xc7700
pushq $0x40
popq %rcx
movq %rcx, 0xa394a(%rip)     # 0xc7708
movq %rax, 0xa394b(%rip)     # 0xc7710
movq %rcx, 0xa394c(%rip)     # 0xc7718
movq %rax, 0xa394d(%rip)     # 0xc7720
movl $0x80, %eax
movq %rax, 0xa3949(%rip)     # 0xc7728
movq %rcx, 0xa394a(%rip)     # 0xc7730
movq $0xbb8, 0xa3947(%rip) # imm = 0xBB8
andl $0x0, 0xa31e4(%rip)     # 0xc6fdc
movl %ebp, 0xa37a2(%rip)     # 0xc75a0
movl $0x3c, 0xa37fc(%rip)    # 0xc7604
movabsq $0xa00000000, %rax      # imm = 0xA00000000
movq %rax, 0xa37c7(%rip)     # 0xc75e0
andl $0x0, 0xa3944(%rip)     # 0xc7764
movq $0x3a98, 0xa393d(%rip) # imm = 0x3A98
movl %ebx, 0xa394f(%rip)     # 0xc7780
leaq 0x66f0a(%rip), %rdi     # 0x8ad42
callq 0x28407
movq %rax, 0xa392c(%rip)     # 0xc7770
movq $0x1388, 0xa3959(%rip) # imm = 0x1388
pxor %xmm0, %xmm0
movdqu %xmm0, 0xa3935(%rip)    # 0xc7790
andl $0x0, 0xa395e(%rip)     # 0xc77c0
leaq 0xa2be7(%rip), %rdi     # 0xc6a50
xorl %esi, %esi
callq 0x216f0
movq %rax, 0xa3419(%rip)     # 0xc7290
movq $0x200000, 0xa3436(%rip) # imm = 0x200000
callq 0x22d04
movzbl 0xa314d(%rip), %ecx     # 0xc6fdb
shll $0x18, %ecx
orl %eax, %ecx
movl %ecx, 0xa313f(%rip)     # 0xc6fd8
xorl %eax, %eax
callq 0x405e4
movl $0xe10, %edi            # imm = 0xE10
movl %ebx, %esi
callq 0x4058e
pushq $0x64
popq %rsi
movl $0x12c, %edi            # imm = 0x12C
callq 0x4058e
pushq $0x3c
popq %rdi
movl $0x2710, %esi           # imm = 0x2710
callq 0x4058e
pxor %xmm0, %xmm0
movdqu %xmm0, 0xa371e(%rip)    # 0xc75f0
movl $0x18eb, 0xa3724(%rip)  # imm = 0x18EB
movdqu %xmm0, 0xa3724(%rip)    # 0xc7608
orq $-0x1, 0xa37ac(%rip)    # 0xc7698
andl $0x0, 0xa3729(%rip)     # 0xc761c
movl $0x5, 0xa371b(%rip)     # 0xc7618
movq %r12, 0xa374c(%rip)     # 0xc7650
andq $0x0, 0xa374c(%rip)     # 0xc7658
movq %r15, 0xa374d(%rip)     # 0xc7660
andq $0x0, 0xa367d(%rip)     # 0xc7598
andq $0x0, 0xa3685(%rip)     # 0xc75a8
movq $0x100000, 0xa3682(%rip) # imm = 0x100000
movdqu %xmm0, 0xa3682(%rip)    # 0xc75b8
andq $0x0, 0xa368a(%rip)     # 0xc75c8
movq $0xe10, 0xa3687(%rip) # imm = 0xE10
xorl %edi, %edi
callq 0x1fc50
movq %rax, 0xa3681(%rip)     # 0xc75d8
leaq 0xa304a(%rip), %rax     # 0xc6fa8
leaq 0xa2b5b(%rip), %rcx     # 0xc6ac0
cmpq $0x48, %r14
je 0x23f8e
movq 0x10(%rcx,%r14), %rdx
movq %rdx, 0x498(%r14,%rax)
movdqu (%rcx,%r14), %xmm0
movdqu %xmm0, 0x488(%r14,%rax)
addq $0x18, %r14
jmp 0x23f65
andq $0x0, 0xb749a(%rip)     # 0xdb430
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
movq %rax, 0xb7491(%rip)     # 0xdb438
movabsq $-0x10000000000000, %rax # imm = 0xFFF0000000000000
movq %rax, 0xb7488(%rip)     # 0xdb440
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
movq %rax, 0xb747f(%rip)     # 0xdb448
leaq 0xa2990(%rip), %rbx     # 0xc6960
movq %rbx, %rdi
xorl %esi, %esi
callq 0x216f0
movq %rax, 0xa2fdf(%rip)     # 0xc6fc0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x216f0
movq %rax, 0xa2fd6(%rip)     # 0xc6fc8
callq 0x240a0
leaq 0x6649f(%rip), %rdi     # 0x8a49d
callq 0x2421a
movq %rax, 0xa32b6(%rip)     # 0xc72c0
leaq 0x6653c(%rip), %rdi     # 0x8a54d
callq 0x2421a
movq %rax, 0xa32ab(%rip)     # 0xc72c8
leaq 0x662c3(%rip), %rdi     # 0x8a2e7
callq 0x2421a
movq %rax, 0xa32a0(%rip)     # 0xc72d0
leaq 0x662bb(%rip), %rdi     # 0x8a2f2
callq 0x2421a
movq %rax, 0xa3295(%rip)     # 0xc72d8
leaq 0x66290(%rip), %rdi     # 0x8a2da
callq 0x2421a
movq %rax, 0xa328a(%rip)     # 0xc72e0
movq $0x2710, 0xa32ff(%rip) # imm = 0x2710
movq $0x80, 0xa32fc(%rip) # 0xc7368
leaq 0x66cda(%rip), %rax     # 0x8ad4d
movq %rax, 0xa374e(%rip)     # 0xc77c8
leaq 0x66ce2(%rip), %rax     # 0x8ad63
movq %rax, 0xa3748(%rip)     # 0xc77d0
andq $0x0, 0xa3748(%rip)     # 0xc77d8
andl $0x0, 0xa3749(%rip)     # 0xc77e0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq