#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 *);
scalar_t__ strncmp(char *, char *, int);
unsigned char encodeProto(char *proto, unsigned char info) {
  unsigned char x;
  if (strncmp(proto, "HTTP/1.0\0", 9) == 0) {
    printf("Protocol detected: HTTP/1.0\n");
    x = 1;
  } else if (strncmp(proto, "HTTP/1.1\0", 9) == 0) {
    printf("Protocol detected: HTTP/1.1\n");
    x = 2;
  } else if (strncmp(proto, "HTTP/2.0\0", 9) == 0) {
    printf("Protocol detected: HTTP/2.0\n");
    x = 3;
  } else {
    printf("\x1b[31m"
           "Protocol not supported\n"
           "\x1b[0m");
    printByteDebug(info);
    x = 0;
  }
  printf("setting the protocol\n");
  info = (info & 243) | ((x << 2) & ~243);
  return info;
}


x86 assembly (clang, -O0):
<encodeProto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb3(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1176 <encodeProto+0x46>
lea    0xeb6(%rip),%rdi
call   1040 <printf@plt>
movb   $0x1,-0xa(%rbp)
jmp    1201 <encodeProto+0xd1>
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11aa <encodeProto+0x7a>
lea    0xe9f(%rip),%rdi
call   1040 <printf@plt>
movb   $0x2,-0xa(%rbp)
jmp    11fc <encodeProto+0xcc>
mov    -0x8(%rbp),%rdi
lea    0xe5f(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11de <encodeProto+0xae>
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
movb   $0x3,-0xa(%rbp)
jmp    11f7 <encodeProto+0xc7>
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
movzbl -0x9(%rbp),%edi
call   1050 <printByteDebug@plt>
movb   $0x0,-0xa(%rbp)
jmp    11fc <encodeProto+0xcc>
jmp    1201 <encodeProto+0xd1>
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
movzbl -0x9(%rbp),%eax
and    $0xf3,%eax
movzbl -0xa(%rbp),%ecx
shl    $0x2,%ecx
and    $0xffffff0c,%ecx
or     %ecx,%eax
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encodeProto>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xeb1(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11a9 <encodeProto+0x69>
lea    0xea5(%rip),%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11b9 <encodeProto+0x79>
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11c9 <encodeProto+0x89>
lea    0xe87(%rip),%rdi
call   1050 <printf@plt>
movzbl %bpl,%edi
call   1060 <printByteDebug@plt>
xor    %ebx,%ebx
jmp    11d7 <encodeProto+0x97>
lea    0xedc(%rip),%rdi
call   1040 <puts@plt>
mov    $0x4,%bl
jmp    11d7 <encodeProto+0x97>
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
mov    $0x8,%bl
jmp    11d7 <encodeProto+0x97>
lea    0xe84(%rip),%rdi
call   1040 <puts@plt>
mov    $0xc,%bl
lea    0xe61(%rip),%rdi
call   1040 <puts@plt>
and    $0xf3,%bpl
or     %bl,%bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"HTTP/1.0\00\00"
@.str.1 = [29 x i8] c"Protocol detected: HTTP/1.0\0A\00"
@.str.2 = [10 x i8] c"HTTP/1.1\00\00"
@.str.3 = [29 x i8] c"Protocol detected: HTTP/1.1\0A\00"
@.str.4 = [10 x i8] c"HTTP/2.0\00\00"
@.str.5 = [29 x i8] c"Protocol detected: HTTP/2.0\0A\00"
@.str.6 = [33 x i8] c"\1B[31mProtocol not supported\0A\1B[0m\00"
@.str.7 = [22 x i8] c"setting the protocol\0A\00"
define zeroext i8 @encodeProto(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
store i8* %0, i8** %3
store i8 %1, i8* %4
%6 = load i8*, i8** %3
%7 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i8 1, i8* %5
br label %29
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 9)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
store i8 2, i8* %5
br label %28
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 9)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
store i8 3, i8* %5
br label %27
23: ; preds = %17
%24 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
%25 = load i8, i8* %4
%26 = call i32 @printByteDebug(i8 zeroext %25)
store i8 0, i8* %5
br label %27
27: ; preds = %23, %21
br label %28
28: ; preds = %27, %15
br label %29
29: ; preds = %28, %9
%30 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%31 = load i8, i8* %4
%32 = zext i8 %31 to i32
%33 = and i32 %32, 243
%34 = load i8, i8* %5
%35 = zext i8 %34 to i32
%36 = shl i32 %35, 2
%37 = and i32 %36, -244
%38 = or i32 %33, %37
%39 = trunc i32 %38 to i8
store i8 %39, i8* %4
%40 = load i8, i8* %4
ret i8 %40
}

LLVM IR (-O2):
@.str = [10 x i8] c"HTTP/1.0\00\00"
@.str.2 = [10 x i8] c"HTTP/1.1\00\00"
@.str.4 = [10 x i8] c"HTTP/2.0\00\00"
@.str.6 = [33 x i8] c"\1B[31mProtocol not supported\0A\1B[0m\00"
@str = [21 x i8] c"setting the protocol\00"
@str.8 = [28 x i8] c"Protocol detected: HTTP/2.0\00"
@str.9 = [28 x i8] c"Protocol detected: HTTP/1.1\00"
@str.10 = [28 x i8] c"Protocol detected: HTTP/1.0\00"
define zeroext i8 @encodeProto(i8* %0, i8 zeroext %1) {
%3 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.10, i64 0, i64 0))
br label %20
7: ; preds = %2
%8 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 9)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.9, i64 0, i64 0))
br label %20
12: ; preds = %7
%13 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 9)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.8, i64 0, i64 0))
br label %20
17: ; preds = %12
%18 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
%19 = tail call i32 @printByteDebug(i8 zeroext %1)
br label %20
20: ; preds = %10, %17, %15, %5
%21 = phi i8 [ 4, %5 ], [ 8, %10 ], [ 12, %15 ], [ 0, %17 ]
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%23 = and i8 %1, -13
%24 = or i8 %21, %23
ret i8 %24
}