#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 atoi(char *);
int curses_strtokey(char *);
int /*<<< orphan*/ strcmp(char *, char *);
unsigned int strlen(char *);
char toupper(char);
int str2key(char *keystr) {
  if (strlen(keystr) == 0)
    return 0;
  if (strlen(keystr) == 1)
    return keystr[0];
  if (!strcmp(keystr, "space"))
    return ' ';
  if (!strcmp(keystr, "tab"))
    return '\t';
  if (strlen(keystr) == 2 && keystr[0] == '^')
    return (keystr[1] - 'A' + 1);
  if (keystr[0] >= '0' && keystr[0] <= '9')
    return atoi(keystr);
  unsigned i;
  for (i = 0; i < strlen(keystr); i++)
    keystr[i] = toupper(keystr[i]);
  return curses_strtokey(keystr);
}


x86 assembly (clang, -O0):
<str2key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    117a <str2key+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    12a7 <str2key+0x157>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jne    119b <str2key+0x4b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12a7 <str2key+0x157>
mov    -0x10(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11c0 <str2key+0x70>
movl   $0x20,-0x4(%rbp)
jmp    12a7 <str2key+0x157>
mov    -0x10(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11e5 <str2key+0x95>
movl   $0x9,-0x4(%rbp)
jmp    12a7 <str2key+0x157>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jne    121d <str2key+0xcd>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5e,%eax
jne    121d <str2key+0xcd>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x41,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    12a7 <str2key+0x157>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     124e <str2key+0xfe>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     124e <str2key+0xfe>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    12a7 <str2key+0x157>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jae    129b <str2key+0x14b>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <toupper@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1255 <str2key+0x105>
mov    -0x10(%rbp),%rdi
call   1030 <curses_strtokey@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2key>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strlen@plt>
test   %eax,%eax
je     1173 <str2key+0x23>
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jne    1177 <str2key+0x27>
movsbl (%r14),%eax
jmp    11c8 <str2key+0x78>
xor    %eax,%eax
jmp    11c8 <str2key+0x78>
lea    0xe82(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11bc <str2key+0x6c>
lea    0xe75(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11c3 <str2key+0x73>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    (%r14),%cl
cmp    $0x2,%eax
jne    11d0 <str2key+0x80>
cmp    $0x5e,%cl
jne    11d0 <str2key+0x80>
movsbl 0x1(%r14),%eax
add    $0xffffffc0,%eax
jmp    11c8 <str2key+0x78>
mov    $0x20,%eax
jmp    11c8 <str2key+0x78>
mov    $0x9,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
add    $0xd0,%cl
cmp    $0xa,%cl
jae    11e7 <str2key+0x97>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <atoi@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     1221 <str2key+0xd1>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r14,%rbx,1),%edi
call   1040 <toupper@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     1200 <str2key+0xb0>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <curses_strtokey@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"space\00"
@.str.1 = [4 x i8] c"tab\00"
define i32 @str2key(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %83
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
store i32 %17, i32* %2
br label %83
18: ; preds = %9
%19 = load i8*, i8** %3
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %18
store i32 32, i32* %2
br label %83
23: ; preds = %18
%24 = load i8*, i8** %3
%25 = call i32 @strcmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %23
store i32 9, i32* %2
br label %83
28: ; preds = %23
%29 = load i8*, i8** %3
%30 = call i32 @strlen(i8* %29)
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %45
32: ; preds = %28
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 94
br i1 %37, label %38, label %45
38: ; preds = %32
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = sub nsw i32 %42, 65
%44 = add nsw i32 %43, 1
store i32 %44, i32* %2
br label %83
45: ; preds = %32, %28
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp sge i32 %49, 48
br i1 %50, label %51, label %60
51: ; preds = %45
%52 = load i8*, i8** %3
%53 = getelementptr inbounds i8, i8* %52, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp sle i32 %55, 57
br i1 %56, label %57, label %60
57: ; preds = %51
%58 = load i8*, i8** %3
%59 = call i32 @atoi(i8* %58)
store i32 %59, i32* %2
br label %83
60: ; preds = %51, %45
store i32 0, i32* %4
br label %61
61: ; preds = %77, %60
%62 = load i32, i32* %4
%63 = load i8*, i8** %3
%64 = call i32 @strlen(i8* %63)
%65 = icmp ult i32 %62, %64
br i1 %65, label %66, label %80
66: ; preds = %61
%67 = load i8*, i8** %3
%68 = load i32, i32* %4
%69 = zext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
%71 = load i8, i8* %70
%72 = call signext i8 @toupper(i8 signext %71)
%73 = load i8*, i8** %3
%74 = load i32, i32* %4
%75 = zext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
store i8 %72, i8* %76
br label %77
77: ; preds = %66
%78 = load i32, i32* %4
%79 = add i32 %78, 1
store i32 %79, i32* %4
br label %61
80: ; preds = %61
%81 = load i8*, i8** %3
%82 = call i32 @curses_strtokey(i8* %81)
store i32 %82, i32* %2
br label %83
83: ; preds = %80, %57, %38, %27, %22, %13, %8
%84 = load i32, i32* %2
ret i32 %84
}

LLVM IR (-O2):
@.str = [6 x i8] c"space\00"
@.str.1 = [4 x i8] c"tab\00"
define i32 @str2key(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %46, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i8, i8* %0
%9 = sext i8 %8 to i32
br label %46
10: ; preds = %4
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %46, label %13
13: ; preds = %10
%14 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %46, label %16
16: ; preds = %13
%17 = tail call i32 @strlen(i8* %0)
%18 = icmp eq i32 %17, 2
%19 = load i8, i8* %0
%20 = icmp eq i8 %19, 94
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = getelementptr inbounds i8, i8* %0, i64 1
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = add nsw i32 %25, -64
br label %46
27: ; preds = %16
%28 = add i8 %19, -48
%29 = icmp ult i8 %28, 10
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = tail call i32 @strlen(i8* %0)
%32 = icmp eq i32 %31, 0
br i1 %32, label %44, label %35
33: ; preds = %27
%34 = tail call i32 @atoi(i8* %0)
br label %46
35: ; preds = %30, %35
%36 = phi i64 [ %40, %35 ], [ 0, %30 ]
%37 = getelementptr inbounds i8, i8* %0, i64 %36
%38 = load i8, i8* %37
%39 = tail call signext i8 @toupper(i8 signext %38)
store i8 %39, i8* %37
%40 = add nuw nsw i64 %36, 1
%41 = tail call i32 @strlen(i8* %0)
%42 = zext i32 %41 to i64
%43 = icmp ult i64 %40, %42
br i1 %43, label %35, label %44
44: ; preds = %35, %30
%45 = tail call i32 @curses_strtokey(i8* %0)
br label %46
46: ; preds = %13, %10, %1, %44, %33, %22, %7
%47 = phi i32 [ %9, %7 ], [ %26, %22 ], [ %34, %33 ], [ %45, %44 ], [ 0, %1 ], [ 32, %10 ], [ 9, %13 ]
ret i32 %47
}