#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 */
scalar_t__ anetRead(int, char *, int);
int cliReadBulkReply(int);
int cliReadMultiBulkReply(int);
int cliReadSingleLineReply(int, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int cliReadReply(int fd) {
  char type;
  if (anetRead(fd, &type, 1) <= 0)
    exit(1);
  switch (type) {
  case '-':
    printf("(error) ");
    cliReadSingleLineReply(fd, 0);
    return 1;
  case '+':
    return cliReadSingleLineReply(fd, 0);
  case ':':
    printf("(integer) ");
    return cliReadSingleLineReply(fd, 0);
  case '$':
    return cliReadBulkReply(fd);
  case '*':
    return cliReadMultiBulkReply(fd);
  default:
    printf("protocol error, got '%c' as reply type byte\n", type);
    return 1;
  }
}


x86 assembly (clang, -O0):
<cliReadReply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1060 <anetRead@plt>
cmp    $0x0,%rax
jg     1190 <cliReadReply+0x30>
mov    $0x1,%edi
call   1080 <exit@plt>
movsbl -0x9(%rbp),%eax
add    $0xffffffdc,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x16,%eax
ja     1230 <cliReadReply+0xd0>
mov    -0x18(%rbp),%rax
lea    0xe4f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <cliReadSingleLineReply@plt>
movl   $0x1,-0x4(%rbp)
jmp    1249 <cliReadReply+0xe9>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <cliReadSingleLineReply@plt>
mov    %eax,-0x4(%rbp)
jmp    1249 <cliReadReply+0xe9>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <cliReadSingleLineReply@plt>
mov    %eax,-0x4(%rbp)
jmp    1249 <cliReadReply+0xe9>
mov    -0x8(%rbp),%edi
call   1050 <cliReadBulkReply@plt>
mov    %eax,-0x4(%rbp)
jmp    1249 <cliReadReply+0xe9>
mov    -0x8(%rbp),%edi
call   1070 <cliReadMultiBulkReply@plt>
mov    %eax,-0x4(%rbp)
jmp    1249 <cliReadReply+0xe9>
movsbl -0x9(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cliReadReply>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1060 <anetRead@plt>
test   %rax,%rax
jle    11f5 <cliReadReply+0x95>
movsbl 0xf(%rsp),%esi
lea    -0x24(%rsi),%eax
cmp    $0x16,%eax
ja     11a1 <cliReadReply+0x41>
lea    0xe71(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %ebx,%edi
call   1050 <cliReadBulkReply@plt>
jmp    11ef <cliReadReply+0x8f>
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d1 <cliReadReply+0x71>
mov    %ebx,%edi
call   1070 <cliReadMultiBulkReply@plt>
jmp    11ef <cliReadReply+0x8f>
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <cliReadSingleLineReply@plt>
mov    $0x1,%eax
jmp    11ef <cliReadReply+0x8f>
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <cliReadSingleLineReply@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"(error) \00"
@.str.1 = [11 x i8] c"(integer) \00"
@.str.2 = [45 x i8] c"protocol error, got '%c' as reply type byte\0A\00"
define i32 @cliReadReply(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i64 @anetRead(i32 %5, i8* %4, i32 1)
%7 = icmp sle i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
switch i32 %12, label %30 [
i32 45, label %13
i32 43, label %17
i32 58, label %20
i32 36, label %24
i32 42, label %27
]
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %3
%16 = call i32 @cliReadSingleLineReply(i32 %15, i32 0)
store i32 1, i32* %2
br label %34
17: ; preds = %10
%18 = load i32, i32* %3
%19 = call i32 @cliReadSingleLineReply(i32 %18, i32 0)
store i32 %19, i32* %2
br label %34
20: ; preds = %10
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* %3
%23 = call i32 @cliReadSingleLineReply(i32 %22, i32 0)
store i32 %23, i32* %2
br label %34
24: ; preds = %10
%25 = load i32, i32* %3
%26 = call i32 @cliReadBulkReply(i32 %25)
store i32 %26, i32* %2
br label %34
27: ; preds = %10
%28 = load i32, i32* %3
%29 = call i32 @cliReadMultiBulkReply(i32 %28)
store i32 %29, i32* %2
br label %34
30: ; preds = %10
%31 = load i8, i8* %4
%32 = sext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %32)
store i32 1, i32* %2
br label %34
34: ; preds = %30, %27, %24, %20, %17, %13
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [9 x i8] c"(error) \00"
@.str.1 = [11 x i8] c"(integer) \00"
@.str.2 = [45 x i8] c"protocol error, got '%c' as reply type byte\0A\00"
define i32 @cliReadReply(i32 %0) {
%2 = alloca i8
%3 = call i64 @anetRead(i32 %0, i8* %2, i32 1)
%4 = icmp slt i64 %3, 1
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
switch i32 %9, label %22 [
i32 45, label %10
i32 43, label %13
i32 58, label %15
i32 36, label %18
i32 42, label %20
]
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @cliReadSingleLineReply(i32 %0, i32 0)
br label %24
13: ; preds = %7
%14 = call i32 @cliReadSingleLineReply(i32 %0, i32 0)
br label %24
15: ; preds = %7
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @cliReadSingleLineReply(i32 %0, i32 0)
br label %24
18: ; preds = %7
%19 = call i32 @cliReadBulkReply(i32 %0)
br label %24
20: ; preds = %7
%21 = call i32 @cliReadMultiBulkReply(i32 %0)
br label %24
22: ; preds = %7
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %24
24: ; preds = %22, %20, %18, %15, %13, %10
%25 = phi i32 [ 1, %22 ], [ %21, %20 ], [ %19, %18 ], [ %17, %15 ], [ %14, %13 ], [ 1, %10 ]
ret i32 %25
}