#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 strlen(char const *);
int str2cc(const char *p) {
  if (strlen(p) != 2 || p[0] != '^' || p[1] < 'A' || p[1] > '~')
    return (0);
  return (p[1] & 0x1f);
}


x86 assembly (clang, -O0):
<str2cc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jne    1160 <str2cc+0x50>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5e,%eax
jne    1160 <str2cc+0x50>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x41,%eax
jl     1160 <str2cc+0x50>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x7e,%eax
jle    116c <str2cc+0x5c>
movl   $0x0,-0x4(%rbp)
jmp    117a <str2cc+0x6a>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0x1f,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2cc>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
jne    1138 <str2cc+0x28>
cmpb   $0x5e,(%rbx)
jne    1138 <str2cc+0x28>
movzbl 0x1(%rbx),%ecx
lea    -0x7f(%rcx),%edx
cmp    $0xc2,%dl
jb     1138 <str2cc+0x28>
and    $0x1f,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @str2cc(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i32 @strlen(i8* %4)
%6 = icmp ne i32 %5, 2
br i1 %6, label %25, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 94
br i1 %12, label %25, label %13
13: ; preds = %7
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp slt i32 %17, 65
br i1 %18, label %25, label %19
19: ; preds = %13
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp sgt i32 %23, 126
br i1 %24, label %25, label %26
25: ; preds = %19, %13, %7, %1
store i32 0, i32* %2
br label %32
26: ; preds = %19
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = and i32 %30, 31
store i32 %31, i32* %2
br label %32
32: ; preds = %26, %25
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @str2cc(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 2
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 94
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
%10 = add i8 %9, -127
%11 = icmp ult i8 %10, -62
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = and i8 %9, 31
%14 = zext i8 %13 to i32
br label %15
15: ; preds = %1, %4, %7, %12
%16 = phi i32 [ %14, %12 ], [ 0, %7 ], [ 0, %4 ], [ 0, %1 ]
ret i32 %16
}