#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 */
char *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strchr(char const *, char);
char *strdup(char const *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
scalar_t__ strncmp(char const *, char *, int);
char *gui_key_get_internal_code(const char *key) {
  char *result;
  if ((key[0] == '@') && strchr(key, ':'))
    return strdup(key);
  if ((result = malloc(strlen(key) + 1))) {
    result[0] = '\0';
    while (key[0]) {
      if (strncmp(key, "meta2-", 6) == 0) {
        strcat(result, "\x01[[");
        key += 6;
      }
      if (strncmp(key, "meta-", 5) == 0) {
        strcat(result, "\x01[");
        key += 5;
      } else if (strncmp(key, "ctrl-", 5) == 0) {
        strcat(result, "\x01");
        key += 5;
      } else {
        strncat(result, key, 1);
        key++;
      }
    }
  } else
    return NULL;
  return result;
}


x86 assembly (clang, -O0):
<gui_key_get_internal_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    11b6 <gui_key_get_internal_code+0x46>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     11b6 <gui_key_get_internal_code+0x46>
mov    -0x10(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    12ea <gui_key_get_internal_code+0x17a>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12d5 <gui_key_get_internal_code+0x165>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     12d0 <gui_key_get_internal_code+0x160>
mov    -0x10(%rbp),%rdi
lea    0xe08(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1228 <gui_key_get_internal_code+0xb8>
mov    -0x18(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdd8(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1268 <gui_key_get_internal_code+0xf8>
mov    -0x18(%rbp),%rdi
lea    0xdbf(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
jmp    12cb <gui_key_get_internal_code+0x15b>
mov    -0x10(%rbp),%rdi
lea    0xda1(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12a8 <gui_key_get_internal_code+0x138>
mov    -0x18(%rbp),%rdi
lea    0xd88(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
jmp    12c6 <gui_key_get_internal_code+0x156>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1060 <strncat@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    12cb <gui_key_get_internal_code+0x15b>
jmp    11e0 <gui_key_get_internal_code+0x70>
jmp    12e2 <gui_key_get_internal_code+0x172>
movq   $0x0,-0x8(%rbp)
jmp    12ea <gui_key_get_internal_code+0x17a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_key_get_internal_code>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x40,(%rdi)
jne    11ab <gui_key_get_internal_code+0x3b>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11ab <gui_key_get_internal_code+0x3b>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <strdup@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     1292 <gui_key_get_internal_code+0x122>
mov    %rax,%r14
movb   $0x0,(%rax)
cmpb   $0x0,(%rbx)
je     1295 <gui_key_get_internal_code+0x125>
lea    0xe25(%rip),%r15
lea    0xe29(%rip),%r13
lea    0xe28(%rip),%rbp
lea    0xe24(%rip),%r12
jmp    121c <gui_key_get_internal_code+0xac>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <strncat@plt>
mov    $0x1,%eax
cmpb   $0x0,(%rbx,%rax,1)
lea    (%rbx,%rax,1),%rbx
je     1295 <gui_key_get_internal_code+0x125>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1244 <gui_key_get_internal_code+0xd4>
mov    %r14,%rdi
lea    0xdcc(%rip),%rsi
call   1080 <strcat@plt>
add    $0x6,%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1280 <gui_key_get_internal_code+0x110>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
mov    %r14,%rdi
test   %rax,%rax
jne    1200 <gui_key_get_internal_code+0x90>
lea    0xda2(%rip),%rsi
jmp    1286 <gui_key_get_internal_code+0x116>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1080 <strcat@plt>
mov    $0x5,%eax
jmp    1212 <gui_key_get_internal_code+0xa2>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"meta2-\00"
@.str.1 = [4 x i8] c"\01[[\00"
@.str.2 = [6 x i8] c"meta-\00"
@.str.3 = [3 x i8] c"\01[\00"
@.str.4 = [6 x i8] c"ctrl-\00"
@.str.5 = [2 x i8] c"\01\00"
define i8* @gui_key_get_internal_code(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 64
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i64 @strchr(i8* %11, i8 signext 58)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = call i8* @strdup(i8* %15)
store i8* %16, i8** %2
br label %70
17: ; preds = %10, %1
%18 = load i8*, i8** %3
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %19, 1
%21 = call i8* @malloc(i64 %20)
store i8* %21, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %67
23: ; preds = %17
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 0
store i8 0, i8* %25
br label %26
26: ; preds = %65, %23
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 0
br i1 %30, label %31, label %66
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = call i64 @strncmp(i8* %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = load i8*, i8** %4
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i64 6
store i8* %39, i8** %3
br label %40
40: ; preds = %35, %31
%41 = load i8*, i8** %3
%42 = call i64 @strncmp(i8* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %40
%45 = load i8*, i8** %4
%46 = call i32 @strcat(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%47 = load i8*, i8** %3
%48 = getelementptr inbounds i8, i8* %47, i64 5
store i8* %48, i8** %3
br label %65
49: ; preds = %40
%50 = load i8*, i8** %3
%51 = call i64 @strncmp(i8* %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %49
%54 = load i8*, i8** %4
%55 = call i32 @strcat(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%56 = load i8*, i8** %3
%57 = getelementptr inbounds i8, i8* %56, i64 5
store i8* %57, i8** %3
br label %64
58: ; preds = %49
%59 = load i8*, i8** %4
%60 = load i8*, i8** %3
%61 = call i32 @strncat(i8* %59, i8* %60, i32 1)
%62 = load i8*, i8** %3
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %3
br label %64
64: ; preds = %58, %53
br label %65
65: ; preds = %64, %44
br label %26
66: ; preds = %26
br label %68
67: ; preds = %17
store i8* null, i8** %2
br label %70
68: ; preds = %66
%69 = load i8*, i8** %4
store i8* %69, i8** %2
br label %70
70: ; preds = %68, %67, %14
%71 = load i8*, i8** %2
ret i8* %71
}

LLVM IR (-O2):
@.str = [7 x i8] c"meta2-\00"
@.str.1 = [4 x i8] c"\01[[\00"
@.str.2 = [6 x i8] c"meta-\00"
@.str.3 = [3 x i8] c"\01[\00"
@.str.4 = [6 x i8] c"ctrl-\00"
@.str.5 = [2 x i8] c"\01\00"
define i8* @gui_key_get_internal_code(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 64
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = tail call i64 @strchr(i8* %0, i8 signext 58)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i8* @strdup(i8* %0)
br label %42
9: ; preds = %4, %1
%10 = tail call i64 @strlen(i8* %0)
%11 = add nsw i64 %10, 1
%12 = tail call i8* @malloc(i64 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %42, label %14
14: ; preds = %9
store i8 0, i8* %12
%15 = load i8, i8* %0
%16 = icmp eq i8 %15, 0
br i1 %16, label %42, label %17
17: ; preds = %14, %37
%18 = phi i8* [ %39, %37 ], [ %0, %14 ]
%19 = tail call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = tail call i32 @strcat(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds i8, i8* %18, i64 6
br label %24
24: ; preds = %21, %17
%25 = phi i8* [ %23, %21 ], [ %18, %17 ]
%26 = tail call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = tail call i32 @strcat(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %37
30: ; preds = %24
%31 = tail call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = tail call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %37
35: ; preds = %30
%36 = tail call i32 @strncat(i8* %12, i8* %25, i32 1)
br label %37
37: ; preds = %33, %35, %28
%38 = phi i64 [ 5, %33 ], [ 1, %35 ], [ 5, %28 ]
%39 = getelementptr inbounds i8, i8* %25, i64 %38
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
br i1 %41, label %42, label %17
42: ; preds = %37, %14, %9, %7
%43 = phi i8* [ %8, %7 ], [ null, %9 ], [ %12, %14 ], [ %12, %37 ]
ret i8* %43
}