#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_ttl(unsigned int, int);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int load_ttl_from_redis() {
  log_func(2, "Loading TTL from redis.");
  char keys[65536][64];
  unsigned int daddr;
  char dip[16];
  int count = scan_match("ttl:*", keys, 65536);
  for (int i = 0; i < count; i++) {
    sscanf(keys[i], "ttl:%u", &daddr);
    ip2str(daddr, dip);
    int ttl = get_int(keys[i]);
    set_ttl(daddr, ttl);
  }
  log_func(3, "%d records loaded.", count);
  return count;
}


x86 assembly (clang, -O0):
<load_ttl_from_redis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400030,%rsp
mov    $0x2,%edi
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1060 <log_func@plt>
lea    -0x400000(%rbp),%rsi
lea    0xe8c(%rip),%rdi
mov    $0x10000,%edx
call   1040 <scan_match@plt>
mov    %eax,-0x400024(%rbp)
movl   $0x0,-0x400028(%rbp)
mov    -0x400028(%rbp),%eax
cmp    -0x400024(%rbp),%eax
jge    1237 <load_ttl_from_redis+0xd7>
movslq -0x400028(%rbp),%rax
lea    -0x400000(%rbp),%rdi
shl    $0x6,%rax
add    %rax,%rdi
lea    0xe4a(%rip),%rsi
lea    -0x400004(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x400004(%rbp),%edi
lea    -0x400020(%rbp),%rsi
call   1030 <ip2str@plt>
movslq -0x400028(%rbp),%rax
lea    -0x400000(%rbp),%rdi
shl    $0x6,%rax
add    %rax,%rdi
call   1070 <get_int@plt>
mov    %eax,-0x40002c(%rbp)
mov    -0x400004(%rbp),%edi
mov    -0x40002c(%rbp),%esi
call   1080 <set_ttl@plt>
mov    -0x400028(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x400028(%rbp)
jmp    11a6 <load_ttl_from_redis+0x46>
mov    -0x400024(%rbp),%edx
mov    $0x3,%edi
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   1060 <log_func@plt>
mov    -0x400024(%rbp),%eax
add    $0x400030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_ttl_from_redis>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400028,%rsp
lea    0xe88(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1060 <log_func@plt>
lea    0xe8d(%rip),%rdi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x10000,%edx
call   1040 <scan_match@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    11f7 <load_ttl_from_redis+0x97>
mov    %r14d,%ebp
lea    0xe70(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <sscanf@plt>
mov    0xc(%rsp),%edi
mov    %r13,%rsi
call   1030 <ip2str@plt>
mov    %rbx,%rdi
call   1070 <get_int@plt>
mov    0xc(%rsp),%edi
mov    %eax,%esi
call   1080 <set_ttl@plt>
add    $0x40,%rbx
add    $0xffffffffffffffff,%rbp
jne    11c0 <load_ttl_from_redis+0x60>
lea    0xe27(%rip),%rsi
mov    $0x3,%edi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <log_func@plt>
mov    %r14d,%eax
add    $0x400028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Loading TTL from redis.\00"
@.str.1 = [6 x i8] c"ttl:*\00"
@.str.2 = [7 x i8] c"ttl:%u\00"
@.str.3 = [19 x i8] c"%d records loaded.\00"
define i32 @load_ttl_from_redis() {
%1 = alloca [65536 x [64 x i8]]
%2 = alloca i32
%3 = alloca [16 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = call i32 (i32, i8*, ...) @log_func(i32 2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [65536 x [64 x i8]], [65536 x [64 x i8]]* %1, i64 0, i64 0
%9 = bitcast [64 x i8]* %8 to i8**
%10 = call i32 @scan_match(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %9, i32 65536)
store i32 %10, i32* %4
store i32 0, i32* %5
br label %11
11: ; preds = %32, %0
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %35
15: ; preds = %11
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [65536 x [64 x i8]], [65536 x [64 x i8]]* %1, i64 0, i64 %17
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %18, i64 0, i64 0
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%21 = load i32, i32* %2
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%23 = call i32 @ip2str(i32 %21, i8* %22)
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [65536 x [64 x i8]], [65536 x [64 x i8]]* %1, i64 0, i64 %25
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %26, i64 0, i64 0
%28 = call i32 @get_int(i8* %27)
store i32 %28, i32* %6
%29 = load i32, i32* %2
%30 = load i32, i32* %6
%31 = call i32 @set_ttl(i32 %29, i32 %30)
br label %32
32: ; preds = %15
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %11
35: ; preds = %11
%36 = load i32, i32* %4
%37 = call i32 (i32, i8*, ...) @log_func(i32 3, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@.str = [24 x i8] c"Loading TTL from redis.\00"
@.str.1 = [6 x i8] c"ttl:*\00"
@.str.2 = [7 x i8] c"ttl:%u\00"
@.str.3 = [19 x i8] c"%d records loaded.\00"
define i32 @load_ttl_from_redis() {
%1 = alloca [65536 x [64 x i8]]
%2 = alloca i32
%3 = alloca [16 x i8]
%4 = tail call i32 (i32, i8*, ...) @log_func(i32 2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [65536 x [64 x i8]], [65536 x [64 x i8]]* %1, i64 0, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%8 = bitcast [65536 x [64 x i8]]* %1 to i8**
%9 = call i32 @scan_match(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %8, i32 65536)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = zext i32 %9 to i64
br label %15
13: ; preds = %15, %0
%14 = call i32 (i32, i8*, ...) @log_func(i32 3, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %9)
ret i32 %9
15: ; preds = %11, %15
%16 = phi i64 [ 0, %11 ], [ %24, %15 ]
%17 = getelementptr inbounds [65536 x [64 x i8]], [65536 x [64 x i8]]* %1, i64 0, i64 %16, i64 0
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%19 = load i32, i32* %2
%20 = call i32 @ip2str(i32 %19, i8* %7)
%21 = call i32 @get_int(i8* %17)
%22 = load i32, i32* %2
%23 = call i32 @set_ttl(i32 %22, i32 %21)
%24 = add nuw nsw i64 %16, 1
%25 = icmp eq i64 %24, %12
br i1 %25, label %13, label %15
}