#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 /*<<< orphan*/ cliSendCommand(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ convertToSds(int, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *linenoise(char *);
int /*<<< orphan*/ linenoiseHistoryAdd(char *);
scalar_t__ strcasecmp(char *, char *);
char *strsep(char **, char *);
void repl() {
  int size = 4096, max = size >> 1, argc;
  char *line;
  char **ap, *args[max];
  while ((line = linenoise("redis> ")) != NULL) {
    if (line[0] != '\0') {
      linenoiseHistoryAdd(line);
      argc = 0;
      for (ap = args; (*ap = strsep(&line, " \t")) != NULL;) {
        if (**ap != '\0') {
          if (argc >= max)
            break;
          if (strcasecmp(*ap, "quit") == 0 || strcasecmp(*ap, "exit") == 0)
            exit(0);
          ap++;
          argc++;
        }
      }
      cliSendCommand(argc, convertToSds(argc, args), 1);
    }
    free(line);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<repl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x1000,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    %eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
lea    0xe3b(%rip),%rdi
call   1050 <linenoise@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12cf <repl+0x14f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12c1 <repl+0x141>
mov    -0x18(%rbp),%rdi
call   1070 <linenoiseHistoryAdd@plt>
mov    -0x38(%rbp),%rax
movl   $0x0,-0xc(%rbp)
mov    %rax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1080 <strsep@plt>
mov    -0x20(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
je     12a0 <repl+0x120>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     129b <repl+0x11b>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     1245 <repl+0xc5>
jmp    12a0 <repl+0x120>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xdb8(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     127f <repl+0xff>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xda0(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1286 <repl+0x106>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1200 <repl+0x80>
mov    -0x38(%rbp),%rsi
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <convertToSds@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%esi
mov    $0x1,%edx
call   1090 <cliSendCommand@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    11be <repl+0x3e>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<repl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4018,%rsp
lea    0xe68(%rip),%rdi
call   1050 <linenoise@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     129b <repl+0x11b>
lea    0xe56(%rip),%r15
lea    0x8(%rsp),%rbx
lea    0xe52(%rip),%rbp
jmp    1206 <repl+0x86>
xor    %r14d,%r14d
mov    %r14d,%edi
lea    0x10(%rsp),%rsi
call   1060 <convertToSds@plt>
mov    %r14d,%edi
mov    %eax,%esi
mov    $0x1,%edx
call   1090 <cliSendCommand@plt>
mov    0x8(%rsp),%rax
mov    %rax,%rdi
call   1030 <free@plt>
lea    0xe0d(%rip),%rdi
call   1050 <linenoise@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     129b <repl+0x11b>
cmpb   $0x0,(%rax)
je     11e4 <repl+0x64>
mov    %rax,%rdi
call   1070 <linenoiseHistoryAdd@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strsep@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     11c0 <repl+0x40>
mov    %rax,%r12
xor    %r14d,%r14d
lea    0x10(%rsp),%r13
jmp    1263 <repl+0xe3>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x8,%r13
add    $0x1,%r14d
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strsep@plt>
mov    %rax,%r12
mov    %rax,0x0(%r13)
test   %rax,%rax
je     11c3 <repl+0x43>
cmpb   $0x0,(%r12)
je     1248 <repl+0xc8>
cmp    $0x7ff,%r14d
jg     11c3 <repl+0x43>
mov    %r12,%rdi
lea    0xd8a(%rip),%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     129b <repl+0x11b>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    1240 <repl+0xc0>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"redis> \00"
@.str.1 = [3 x i8] c" \09\00"
@.str.2 = [5 x i8] c"quit\00"
@.str.3 = [5 x i8] c"exit\00"
define void @repl() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 4096, i32* %1
%8 = load i32, i32* %1
%9 = ashr i32 %8, 1
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8*, i64 %11
store i64 %11, i64* %7
br label %14
14: ; preds = %64, %0
%15 = call i8* @linenoise(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %67
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %64
23: ; preds = %17
%24 = load i8*, i8** %4
%25 = call i32 @linenoiseHistoryAdd(i8* %24)
store i32 0, i32* %3
store i8** %13, i8*** %5
br label %26
26: ; preds = %58, %23
%27 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = load i8**, i8*** %5
store i8* %27, i8** %28
%29 = icmp ne i8* %27, null
br i1 %29, label %30, label %59
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = load i8*, i8** %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %58
36: ; preds = %30
%37 = load i32, i32* %3
%38 = load i32, i32* %2
%39 = icmp sge i32 %37, %38
br i1 %39, label %40, label %41
40: ; preds = %36
br label %59
41: ; preds = %36
%42 = load i8**, i8*** %5
%43 = load i8*, i8** %42
%44 = call i64 @strcasecmp(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %51, label %46
46: ; preds = %41
%47 = load i8**, i8*** %5
%48 = load i8*, i8** %47
%49 = call i64 @strcasecmp(i8* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %46, %41
%52 = call i32 @exit(i32 0)
unreachable
53: ; preds = %46
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i32 1
store i8** %55, i8*** %5
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
br label %58
58: ; preds = %53, %30
br label %26
59: ; preds = %40, %26
%60 = load i32, i32* %3
%61 = load i32, i32* %3
%62 = call i32 @convertToSds(i32 %61, i8** %13)
%63 = call i32 @cliSendCommand(i32 %60, i32 %62, i32 1)
br label %64
64: ; preds = %59, %17
%65 = load i8*, i8** %4
%66 = call i32 @free(i8* %65)
br label %14
67: ; preds = %14
%68 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"redis> \00"
@.str.1 = [3 x i8] c" \09\00"
@.str.2 = [5 x i8] c"quit\00"
@.str.3 = [5 x i8] c"exit\00"
define void @repl() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = alloca [2048 x i8*]
%4 = getelementptr inbounds [2048 x i8*], [2048 x i8*]* %3, i64 0, i64 0
%5 = call i8* @linenoise(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %1
%6 = icmp eq i8* %5, null
br i1 %6, label %49, label %7
7: ; preds = %0, %44
%8 = phi i8* [ %47, %44 ], [ %5, %0 ]
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %44, label %11
11: ; preds = %7
%12 = call i32 @linenoiseHistoryAdd(i8* %8)
%13 = call i8* @strsep(i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %4
%14 = icmp eq i8* %13, null
br i1 %14, label %39, label %15
15: ; preds = %11, %34
%16 = phi i8* [ %37, %34 ], [ %13, %11 ]
%17 = phi i32 [ %36, %34 ], [ 0, %11 ]
%18 = phi i8** [ %35, %34 ], [ %4, %11 ]
%19 = load i8, i8* %16
%20 = icmp eq i8 %19, 0
br i1 %20, label %34, label %21
21: ; preds = %15
%22 = icmp sgt i32 %17, 2047
br i1 %22, label %39, label %23
23: ; preds = %21
%24 = call i64 @strcasecmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i64 @strcasecmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26, %23
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %26
%32 = getelementptr inbounds i8*, i8** %18, i64 1
%33 = add nsw i32 %17, 1
br label %34
34: ; preds = %31, %15
%35 = phi i8** [ %32, %31 ], [ %18, %15 ]
%36 = phi i32 [ %33, %31 ], [ %17, %15 ]
%37 = call i8* @strsep(i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %37, i8** %35
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %15
39: ; preds = %34, %21, %11
%40 = phi i32 [ 0, %11 ], [ %17, %21 ], [ %36, %34 ]
%41 = call i32 @convertToSds(i32 %40, i8** %4)
%42 = call i32 @cliSendCommand(i32 %40, i32 %41, i32 1)
%43 = load i8*, i8** %1
br label %44
44: ; preds = %39, %7
%45 = phi i8* [ %43, %39 ], [ %8, %7 ]
%46 = call i32 @free(i8* %45)
%47 = call i8* @linenoise(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %47, i8** %1
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %7
49: ; preds = %44, %0
%50 = call i32 @exit(i32 0)
unreachable
}