#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 */
typedef int /*<<< orphan*/ versions;

/* Variables and functions */
#define DTLS1_2_VERSION 134
#define DTLS1_VERSION 133
#define SSL3_VERSION 132
#define TLS1_1_VERSION 131
#define TLS1_2_VERSION 130
#define TLS1_3_VERSION 129
#define TLS1_VERSION 128
scalar_t__ strcmp(char const *, char const *);
int protocol_from_string(const char *value) {
  struct protocol_versions {
    const char *name;
    int version;
  };
  static const struct protocol_versions versions[] = {
      {"ssl3", SSL3_VERSION},      {"tls1", TLS1_VERSION},
      {"tls1.1", TLS1_1_VERSION},  {"tls1.2", TLS1_2_VERSION},
      {"tls1.3", TLS1_3_VERSION},  {"dtls1", DTLS1_VERSION},
      {"dtls1.2", DTLS1_2_VERSION}};
  size_t i;
  size_t n = (sizeof(versions) / sizeof((versions)[0]));
  for (i = 0; i < n; i++)
    if (strcmp(versions[i].name, value) == 0)
      return versions[i].version;
  return -1;
}


x86 assembly (clang, -O0):
<protocol_from_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x7,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1195 <protocol_from_string+0x85>
mov    -0x18(%rbp),%rcx
lea    0x2c6b(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    117f <protocol_from_string+0x6f>
mov    -0x18(%rbp),%rcx
lea    0x2c43(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <protocol_from_string+0x8c>
jmp    1184 <protocol_from_string+0x74>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    112c <protocol_from_string+0x1c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<protocol_from_string>:
push   %rbx
mov    %rdi,%rbx
lea    0xee5(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11b3 <protocol_from_string+0xa3>
lea    0xee1(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11b7 <protocol_from_string+0xa7>
lea    0xebe(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11be <protocol_from_string+0xae>
lea    0xebf(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11c5 <protocol_from_string+0xb5>
lea    0xe9d(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11cc <protocol_from_string+0xbc>
lea    0xe90(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11d3 <protocol_from_string+0xc3>
lea    0xe82(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11e7 <protocol_from_string+0xd7>
mov    $0x6,%eax
jmp    11d8 <protocol_from_string+0xc8>
xor    %eax,%eax
jmp    11d8 <protocol_from_string+0xc8>
mov    $0x1,%eax
jmp    11d8 <protocol_from_string+0xc8>
mov    $0x2,%eax
jmp    11d8 <protocol_from_string+0xc8>
mov    $0x3,%eax
jmp    11d8 <protocol_from_string+0xc8>
mov    $0x4,%eax
jmp    11d8 <protocol_from_string+0xc8>
mov    $0x5,%eax
shl    $0x4,%rax
lea    0x2bcd(%rip),%rcx
mov    0x8(%rax,%rcx,1),%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.protocol_versions = type { i8*, i32 }
@protocol_from_string.versions = internal constant [7 x %struct.protocol_versions] [%struct.protocol_versions { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 132 }, %struct.protocol_versions { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i32 128 }, %struct.protocol_versions { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i32 131 }, %struct.protocol_versions { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i32 130 }, %struct.protocol_versions { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i32 129 }, %struct.protocol_versions { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i32 0, i32 0), i32 133 }, %struct.protocol_versions { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i32 0, i32 0), i32 134 }]
@.str = [5 x i8] c"ssl3\00"
@.str.1 = [5 x i8] c"tls1\00"
@.str.2 = [7 x i8] c"tls1.1\00"
@.str.3 = [7 x i8] c"tls1.2\00"
@.str.4 = [7 x i8] c"tls1.3\00"
@.str.5 = [6 x i8] c"dtls1\00"
@.str.6 = [8 x i8] c"dtls1.2\00"
define i32 @protocol_from_string(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 7, i64* %5
store i64 0, i64* %4
br label %6
6: ; preds = %24, %1
%7 = load i64, i64* %4
%8 = load i64, i64* %5
%9 = icmp ult i64 %7, %8
br i1 %9, label %10, label %27
10: ; preds = %6
%11 = load i64, i64* %4
%12 = getelementptr inbounds [7 x %struct.protocol_versions], [7 x %struct.protocol_versions]* @protocol_from_string.versions, i64 0, i64 %11
%13 = getelementptr inbounds %struct.protocol_versions, %struct.protocol_versions* %12, i32 0, i32 0
%14 = load i8*, i8** %13
%15 = load i8*, i8** %3
%16 = call i64 @strcmp(i8* %14, i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %10
%19 = load i64, i64* %4
%20 = getelementptr inbounds [7 x %struct.protocol_versions], [7 x %struct.protocol_versions]* @protocol_from_string.versions, i64 0, i64 %19
%21 = getelementptr inbounds %struct.protocol_versions, %struct.protocol_versions* %20, i32 0, i32 1
%22 = load i32, i32* %21
store i32 %22, i32* %2
br label %28
23: ; preds = %10
br label %24
24: ; preds = %23
%25 = load i64, i64* %4
%26 = add i64 %25, 1
store i64 %26, i64* %4
br label %6
27: ; preds = %6
store i32 -1, i32* %2
br label %28
28: ; preds = %27, %18
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
%struct.protocol_versions = type { i8*, i32 }
@protocol_from_string.versions = internal unnamed_addr constant [7 x %struct.protocol_versions] [%struct.protocol_versions { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 132 }, %struct.protocol_versions { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i32 128 }, %struct.protocol_versions { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i32 131 }, %struct.protocol_versions { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i32 130 }, %struct.protocol_versions { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i32 129 }, %struct.protocol_versions { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i32 0, i32 0), i32 133 }, %struct.protocol_versions { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i32 0, i32 0), i32 134 }]
@.str = [5 x i8] c"ssl3\00"
@.str.1 = [5 x i8] c"tls1\00"
@.str.2 = [7 x i8] c"tls1.1\00"
@.str.3 = [7 x i8] c"tls1.2\00"
@.str.4 = [7 x i8] c"tls1.3\00"
@.str.5 = [6 x i8] c"dtls1\00"
@.str.6 = [8 x i8] c"dtls1.2\00"
define i32 @protocol_from_string(i8* %0) {
%2 = tail call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %23, %20, %17, %14, %11, %8, %1
%5 = phi i64 [ 0, %1 ], [ 1, %8 ], [ 2, %11 ], [ 3, %14 ], [ 4, %17 ], [ 5, %20 ], [ 6, %23 ]
%6 = getelementptr inbounds [7 x %struct.protocol_versions], [7 x %struct.protocol_versions]* @protocol_from_string.versions, i64 0, i64 %5, i32 1
%7 = load i32, i32* %6
br label %26
8: ; preds = %1
%9 = tail call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %4, label %11
11: ; preds = %8
%12 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %4, label %14
14: ; preds = %11
%15 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %4, label %17
17: ; preds = %14
%18 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %4, label %20
20: ; preds = %17
%21 = tail call i64 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%22 = icmp eq i64 %21, 0
br i1 %22, label %4, label %23
23: ; preds = %20
%24 = tail call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %4, label %26
26: ; preds = %23, %4
%27 = phi i32 [ %7, %4 ], [ -1, %23 ]
ret i32 %27
}