#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int get_int(char *);
int /*<<< orphan*/ ip2str(unsigned int, char *);
int /*<<< orphan*/ log_func(int, char *, ...);
int scan_match(char *, char **, int);
int /*<<< orphan*/ set_fail1(unsigned int, int, int);
int /*<<< orphan*/ set_fail2(unsigned int, int, int);
int /*<<< orphan*/ set_succ(unsigned int, int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *, unsigned int *, char *);
scalar_t__ strcmp(char *, char *);
void load_historical_result_from_redis() {
  log_func(2, "Loading historical results from redis.");
  char keys[65536][64];
  int sid;
  unsigned int daddr;
  char dip[16];
  char res[16];
  int count = scan_match("strategy:stats:*", keys, 65536);
  for (int i = 0; i < count; i++) {
    sscanf(keys[i], "strategy:stats:%d:%u:%s", &sid, &daddr, res);
    ip2str(daddr, dip);
    int val = get_int(keys[i]);
    log_func(4, "IP: %s. SID: %d. %s: %d", dip, sid, res, val);
    if (strcmp(res, "succ") == 0) {
      set_succ(daddr, sid, val);
    } else if (strcmp(res, "fail1") == 0) {
      set_fail1(daddr, sid, val);
    } else if (strcmp(res, "fail2a") == 0 || strcmp(res, "fail2b") == 0) {
      set_fail2(daddr, sid, val);
    } else {
      log_func(0, "Unexpected result. IP: %s. SID: %d. Result: %s", dip, sid,
               res);
    }
  }
  log_func(3, "%d records loaded.", count);
}


x86 assembly (clang, -O0):
<load_historical_result_from_redis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400040,%rsp
mov    $0x2,%edi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1090 <log_func@plt>
lea    -0x400000(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x10000,%edx
call   1060 <scan_match@plt>
mov    %eax,-0x400034(%rbp)
movl   $0x0,-0x400038(%rbp)
mov    -0x400038(%rbp),%eax
cmp    -0x400034(%rbp),%eax
jge    138d <load_historical_result_from_redis+0x1fd>
movslq -0x400038(%rbp),%rax
lea    -0x400000(%rbp),%rdi
shl    $0x6,%rax
add    %rax,%rdi
lea    -0x400030(%rbp),%r8
lea    0xe2d(%rip),%rsi
lea    -0x400004(%rbp),%rdx
lea    -0x400008(%rbp),%rcx
call   1080 <sscanf@plt>
mov    -0x400008(%rbp),%edi
lea    -0x400020(%rbp),%rsi
call   1050 <ip2str@plt>
movslq -0x400038(%rbp),%rax
lea    -0x400000(%rbp),%rdi
shl    $0x6,%rax
add    %rax,%rdi
call   10b0 <get_int@plt>
mov    %eax,-0x40003c(%rbp)
lea    -0x400020(%rbp),%rdx
mov    -0x400004(%rbp),%ecx
lea    -0x400030(%rbp),%r8
mov    -0x40003c(%rbp),%r9d
mov    $0x4,%edi
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1090 <log_func@plt>
lea    -0x400030(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12b7 <load_historical_result_from_redis+0x127>
mov    -0x400008(%rbp),%edi
mov    -0x400004(%rbp),%esi
mov    -0x40003c(%rbp),%edx
call   1030 <set_succ@plt>
jmp    1374 <load_historical_result_from_redis+0x1e4>
lea    -0x400030(%rbp),%rdi
lea    0xda8(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12f0 <load_historical_result_from_redis+0x160>
mov    -0x400008(%rbp),%edi
mov    -0x400004(%rbp),%esi
mov    -0x40003c(%rbp),%edx
call   1040 <set_fail1@plt>
jmp    136f <load_historical_result_from_redis+0x1df>
lea    -0x400030(%rbp),%rdi
lea    0xd75(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     132a <load_historical_result_from_redis+0x19a>
lea    -0x400030(%rbp),%rdi
lea    0xd5f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1346 <load_historical_result_from_redis+0x1b6>
mov    -0x400008(%rbp),%edi
mov    -0x400004(%rbp),%esi
mov    -0x40003c(%rbp),%edx
call   10a0 <set_fail2@plt>
jmp    136a <load_historical_result_from_redis+0x1da>
lea    -0x400020(%rbp),%rdx
mov    -0x400004(%rbp),%ecx
lea    -0x400030(%rbp),%r8
xor    %edi,%edi
lea    0xd1e(%rip),%rsi
mov    $0x0,%al
call   1090 <log_func@plt>
jmp    136f <load_historical_result_from_redis+0x1df>
jmp    1374 <load_historical_result_from_redis+0x1e4>
jmp    1379 <load_historical_result_from_redis+0x1e9>
mov    -0x400038(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x400038(%rbp)
jmp    11d6 <load_historical_result_from_redis+0x46>
mov    -0x400034(%rbp),%edx
mov    $0x3,%edi
lea    0xd11(%rip),%rsi
mov    $0x0,%al
call   1090 <log_func@plt>
add    $0x400040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_historical_result_from_redis>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400038,%rsp
lea    0xe58(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1090 <log_func@plt>
lea    0xe6c(%rip),%rdi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x10000,%edx
call   1060 <scan_match@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
jle    1315 <load_historical_result_from_redis+0x185>
mov    0xc(%rsp),%r15d
lea    0x10(%rsp),%rbp
lea    0x20(%rsp),%r14
lea    0xe79(%rip),%r12
jmp    121e <load_historical_result_from_redis+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%esi
mov    %r13d,%edx
call   1030 <set_succ@plt>
add    $0x40,%rbx
add    $0xffffffffffffffff,%r15
je     1315 <load_historical_result_from_redis+0x185>
mov    %rbx,%rdi
lea    0xe10(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbp,%r8
call   1080 <sscanf@plt>
mov    0x8(%rsp),%edi
mov    %r14,%rsi
call   1050 <ip2str@plt>
mov    %rbx,%rdi
call   10b0 <get_int@plt>
mov    %eax,%r13d
mov    0x4(%rsp),%ecx
mov    $0x4,%edi
lea    0xdef(%rip),%rsi
mov    %r14,%rdx
mov    %rbp,%r8
mov    %eax,%r9d
xor    %eax,%eax
call   1090 <log_func@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1200 <load_historical_result_from_redis+0x70>
mov    %rbp,%rdi
lea    0xdde(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1300 <load_historical_result_from_redis+0x170>
mov    %rbp,%rdi
lea    0xdd0(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12e0 <load_historical_result_from_redis+0x150>
mov    %rbp,%rdi
lea    0xdc3(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12e0 <load_historical_result_from_redis+0x150>
mov    0x4(%rsp),%ecx
xor    %edi,%edi
lea    0xdb3(%rip),%rsi
mov    %r14,%rdx
mov    %rbp,%r8
xor    %eax,%eax
call   1090 <log_func@plt>
jmp    1210 <load_historical_result_from_redis+0x80>
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%esi
mov    %r13d,%edx
call   10a0 <set_fail2@plt>
jmp    1210 <load_historical_result_from_redis+0x80>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%esi
mov    %r13d,%edx
call   1040 <set_fail1@plt>
jmp    1210 <load_historical_result_from_redis+0x80>
lea    0xd94(%rip),%rsi
mov    $0x3,%edi
mov    0xc(%rsp),%edx
xor    %eax,%eax
call   1090 <log_func@plt>
add    $0x400038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Loading historical results from redis.\00"
@.str.1 = [17 x i8] c"strategy:stats:*\00"
@.str.2 = [24 x i8] c"strategy:stats:%d:%u:%s\00"
@.str.3 = [24 x i8] c"IP: %s. SID: %d. %s: %d\00"
@.str.4 = [5 x i8] c"succ\00"
@.str.5 = [6 x i8] c"fail1\00"
@.str.6 = [7 x i8] c"fail2a\00"
@.str.7 = [7 x i8] c"fail2b\00"
@.str.8 = [47 x i8] c"Unexpected result. IP: %s. SID: %d. Result: %s\00"
@.str.9 = [19 x i8] c"%d records loaded.\00"
define void @load_historical_result_from_redis() {
%1 = alloca [65536 x [64 x i8]]
%2 = alloca i32
%3 = alloca i32
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = call i32 (i32, i8*, ...) @log_func(i32 2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [65536 x [64 x i8]], [65536 x [64 x i8]]* %1, i64 0, i64 0
%11 = bitcast [64 x i8]* %10 to i8**
%12 = call i32 @scan_match(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %11, i32 65536)
store i32 %12, i32* %6
store i32 0, i32* %7
br label %13
13: ; preds = %75, %0
%14 = load i32, i32* %7
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %78
17: ; preds = %13
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [65536 x [64 x i8]], [65536 x [64 x i8]]* %1, i64 0, i64 %19
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %20, i64 0, i64 0
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%23 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3, i8* %22)
%24 = load i32, i32* %3
%25 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%26 = call i32 @ip2str(i32 %24, i8* %25)
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [65536 x [64 x i8]], [65536 x [64 x i8]]* %1, i64 0, i64 %28
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %29, i64 0, i64 0
%31 = call i32 @get_int(i8* %30)
store i32 %31, i32* %8
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%33 = load i32, i32* %2
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%35 = load i32, i32* %8
%36 = call i32 (i32, i8*, ...) @log_func(i32 4, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %32, i32 %33, i8* %34, i32 %35)
%37 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %17
%41 = load i32, i32* %3
%42 = load i32, i32* %2
%43 = load i32, i32* %8
%44 = call i32 @set_succ(i32 %41, i32 %42, i32 %43)
br label %74
45: ; preds = %17
%46 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %45
%50 = load i32, i32* %3
%51 = load i32, i32* %2
%52 = load i32, i32* %8
%53 = call i32 @set_fail1(i32 %50, i32 %51, i32 %52)
br label %73
54: ; preds = %45
%55 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%56 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %62, label %58
58: ; preds = %54
%59 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %58, %54
%63 = load i32, i32* %3
%64 = load i32, i32* %2
%65 = load i32, i32* %8
%66 = call i32 @set_fail2(i32 %63, i32 %64, i32 %65)
br label %72
67: ; preds = %58
%68 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%69 = load i32, i32* %2
%70 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%71 = call i32 (i32, i8*, ...) @log_func(i32 0, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0), i8* %68, i32 %69, i8* %70)
br label %72
72: ; preds = %67, %62
br label %73
73: ; preds = %72, %49
br label %74
74: ; preds = %73, %40
br label %75
75: ; preds = %74
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
store i32 %77, i32* %7
br label %13
78: ; preds = %13
%79 = load i32, i32* %6
%80 = call i32 (i32, i8*, ...) @log_func(i32 3, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %79)
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"Loading historical results from redis.\00"
@.str.1 = [17 x i8] c"strategy:stats:*\00"
@.str.2 = [24 x i8] c"strategy:stats:%d:%u:%s\00"
@.str.3 = [24 x i8] c"IP: %s. SID: %d. %s: %d\00"
@.str.4 = [5 x i8] c"succ\00"
@.str.5 = [6 x i8] c"fail1\00"
@.str.6 = [7 x i8] c"fail2a\00"
@.str.7 = [7 x i8] c"fail2b\00"
@.str.8 = [47 x i8] c"Unexpected result. IP: %s. SID: %d. Result: %s\00"
@.str.9 = [19 x i8] c"%d records loaded.\00"
define void @load_historical_result_from_redis() {
%1 = alloca [65536 x [64 x i8]]
%2 = alloca i32
%3 = alloca i32
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = tail call i32 (i32, i8*, ...) @log_func(i32 2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [65536 x [64 x i8]], [65536 x [64 x i8]]* %1, i64 0, i64 0, i64 0
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%12 = bitcast [65536 x [64 x i8]]* %1 to i8**
%13 = call i32 @scan_match(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %12, i32 65536)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = zext i32 %13 to i64
br label %19
17: ; preds = %54, %0
%18 = call i32 (i32, i8*, ...) @log_func(i32 3, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %13)
ret void
19: ; preds = %15, %54
%20 = phi i64 [ 0, %15 ], [ %55, %54 ]
%21 = getelementptr inbounds [65536 x [64 x i8]], [65536 x [64 x i8]]* %1, i64 0, i64 %20, i64 0
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3, i8* %11)
%23 = load i32, i32* %3
%24 = call i32 @ip2str(i32 %23, i8* %10)
%25 = call i32 @get_int(i8* %21)
%26 = load i32, i32* %2
%27 = call i32 (i32, i8*, ...) @log_func(i32 4, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %10, i32 %26, i8* %11, i32 %25)
%28 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %19
%31 = load i32, i32* %3
%32 = load i32, i32* %2
%33 = call i32 @set_succ(i32 %31, i32 %32, i32 %25)
br label %54
34: ; preds = %19
%35 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i32, i32* %3
%39 = load i32, i32* %2
%40 = call i32 @set_fail1(i32 %38, i32 %39, i32 %25)
br label %54
41: ; preds = %34
%42 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %44, %41
%48 = load i32, i32* %3
%49 = load i32, i32* %2
%50 = call i32 @set_fail2(i32 %48, i32 %49, i32 %25)
br label %54
51: ; preds = %44
%52 = load i32, i32* %2
%53 = call i32 (i32, i8*, ...) @log_func(i32 0, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0), i8* %10, i32 %52, i8* %11)
br label %54
54: ; preds = %37, %51, %47, %30
%55 = add nuw nsw i64 %20, 1
%56 = icmp eq i64 %55, %16
br i1 %56, label %17, label %19
}