#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*/ printByteDebug(unsigned char);
int /*<<< orphan*/ printf(char *);
short decodeProto(unsigned char info) {
  unsigned char x;
  if (((info >> 2) & 3) == 1) {
    printf("Protocol detected: HTTP/1.0\n");
    return 1;
  } else if (((info >> 2) & 3) == 2) {
    printf("Protocol detected: HTTP/1.1\n");
    return 2;
  } else if (((info >> 2) & 3) == 3) {
    printf("Protocol detected: HTTP/2.0\n");
    return 3;
  } else {
    printf("Protocol not supported\n");
    printByteDebug(info);
    return -1;
  }
}


x86 assembly (clang, -O0):
<decodeProto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x3(%rbp)
movzbl -0x3(%rbp),%eax
sar    $0x2,%eax
and    $0x3,%eax
cmp    $0x1,%eax
jne    1158 <decodeProto+0x38>
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
movw   $0x1,-0x2(%rbp)
jmp    11c7 <decodeProto+0xa7>
movzbl -0x3(%rbp),%eax
sar    $0x2,%eax
and    $0x3,%eax
cmp    $0x2,%eax
jne    1182 <decodeProto+0x62>
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
movw   $0x2,-0x2(%rbp)
jmp    11c7 <decodeProto+0xa7>
movzbl -0x3(%rbp),%eax
sar    $0x2,%eax
and    $0x3,%eax
cmp    $0x3,%eax
jne    11ac <decodeProto+0x8c>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
movw   $0x3,-0x2(%rbp)
jmp    11c7 <decodeProto+0xa7>
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
movzbl -0x3(%rbp),%edi
call   1040 <printByteDebug@plt>
movw   $0xffff,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decodeProto>:
push   %rbx
mov    %edi,%ebx
mov    %ebx,%eax
shr    $0x2,%al
and    $0x3,%al
cmp    $0x3,%al
je     1148 <decodeProto+0x28>
cmp    $0x2,%al
je     115a <decodeProto+0x3a>
cmp    $0x1,%al
jne    116c <decodeProto+0x4c>
lea    0xf12(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ax
pop    %rbx
ret
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%ax
pop    %rbx
ret
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%ax
pop    %rbx
ret
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
movzbl %bl,%edi
call   1040 <printByteDebug@plt>
mov    $0xffff,%ax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Protocol detected: HTTP/1.0\0A\00"
@.str.1 = [29 x i8] c"Protocol detected: HTTP/1.1\0A\00"
@.str.2 = [29 x i8] c"Protocol detected: HTTP/2.0\0A\00"
@.str.3 = [24 x i8] c"Protocol not supported\0A\00"
define signext i16 @decodeProto(i8 zeroext %0) {
%2 = alloca i16
%3 = alloca i8
%4 = alloca i8
store i8 %0, i8* %3
%5 = load i8, i8* %3
%6 = zext i8 %5 to i32
%7 = ashr i32 %6, 2
%8 = and i32 %7, 3
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i16 1, i16* %2
br label %32
12: ; preds = %1
%13 = load i8, i8* %3
%14 = zext i8 %13 to i32
%15 = ashr i32 %14, 2
%16 = and i32 %15, 3
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i16 2, i16* %2
br label %32
20: ; preds = %12
%21 = load i8, i8* %3
%22 = zext i8 %21 to i32
%23 = ashr i32 %22, 2
%24 = and i32 %23, 3
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i16 3, i16* %2
br label %32
28: ; preds = %20
%29 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%30 = load i8, i8* %3
%31 = call i32 @printByteDebug(i8 zeroext %30)
store i16 -1, i16* %2
br label %32
32: ; preds = %28, %26, %18, %10
%33 = load i16, i16* %2
ret i16 %33
}

LLVM IR (-O2):
@str = [23 x i8] c"Protocol not supported\00"
@str.4 = [28 x i8] c"Protocol detected: HTTP/2.0\00"
@str.5 = [28 x i8] c"Protocol detected: HTTP/1.1\00"
@str.6 = [28 x i8] c"Protocol detected: HTTP/1.0\00"
define signext i16 @decodeProto(i8 zeroext %0) {
%2 = lshr i8 %0, 2
%3 = and i8 %2, 3
switch i8 %3, label %10 [
i8 1, label %4
i8 2, label %6
i8 3, label %8
]
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.6, i64 0, i64 0))
br label %13
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.5, i64 0, i64 0))
br label %13
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.4, i64 0, i64 0))
br label %13
10: ; preds = %1
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @printByteDebug(i8 zeroext %0)
br label %13
13: ; preds = %10, %8, %6, %4
%14 = phi i16 [ 1, %4 ], [ 2, %6 ], [ 3, %8 ], [ -1, %10 ]
ret i16 %14
}