#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*/ free(char *);
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, *result2;
  if ((key[0] == '@') && strchr(key, ':'))
    return strdup(key);
  result = malloc(strlen(key) + 1);
  if (!result)
    return NULL;
  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 if (strncmp(key, "space", 5) == 0) {
      strcat(result, " ");
      key += 5;
    } else {
      strncat(result, key, 1);
      key++;
    }
  }
  result2 = strdup(result);
  free(result);
  return result2;
}


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    11c6 <gui_key_get_internal_code+0x46>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     11c6 <gui_key_get_internal_code+0x46>
mov    -0x10(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1351 <gui_key_get_internal_code+0x1d1>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f7 <gui_key_get_internal_code+0x77>
movq   $0x0,-0x8(%rbp)
jmp    1351 <gui_key_get_internal_code+0x1d1>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1333 <gui_key_get_internal_code+0x1b3>
mov    -0x10(%rbp),%rdi
lea    0xdea(%rip),%rsi
mov    $0x6,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1246 <gui_key_get_internal_code+0xc6>
mov    -0x18(%rbp),%rdi
lea    0xdd2(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdba(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1286 <gui_key_get_internal_code+0x106>
mov    -0x18(%rbp),%rdi
lea    0xda1(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
jmp    132e <gui_key_get_internal_code+0x1ae>
mov    -0x10(%rbp),%rdi
lea    0xd83(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12c6 <gui_key_get_internal_code+0x146>
mov    -0x18(%rbp),%rdi
lea    0xd6a(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
jmp    1329 <gui_key_get_internal_code+0x1a9>
mov    -0x10(%rbp),%rdi
lea    0xd4b(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1306 <gui_key_get_internal_code+0x186>
mov    -0x18(%rbp),%rdi
lea    0xd32(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
jmp    1324 <gui_key_get_internal_code+0x1a4>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1070 <strncat@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1329 <gui_key_get_internal_code+0x1a9>
jmp    132e <gui_key_get_internal_code+0x1ae>
jmp    11fe <gui_key_get_internal_code+0x7e>
mov    -0x18(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%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    11bb <gui_key_get_internal_code+0x3b>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11bb <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    10a0 <strdup@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     12f3 <gui_key_get_internal_code+0x173>
mov    %rax,%r14
movb   $0x0,(%rax)
cmpb   $0x0,(%rbx)
je     12db <gui_key_get_internal_code+0x15b>
lea    0xe15(%rip),%r15
lea    0xe19(%rip),%r13
lea    0xe1b(%rip),%r12
lea    0xe1c(%rip),%rbp
jmp    1232 <gui_key_get_internal_code+0xb2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
lea    0xdf7(%rip),%rsi
call   1090 <strcat@plt>
mov    $0x5,%eax
cmpb   $0x0,(%rbx,%rax,1)
lea    (%rbx,%rax,1),%rbx
je     12db <gui_key_get_internal_code+0x15b>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x6,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    125a <gui_key_get_internal_code+0xda>
mov    %r14,%rdi
lea    0xdb6(%rip),%rsi
call   1090 <strcat@plt>
add    $0x6,%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1210 <gui_key_get_internal_code+0x90>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     12c0 <gui_key_get_internal_code+0x140>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
mov    %r14,%rdi
test   %rax,%rax
je     12cf <gui_key_get_internal_code+0x14f>
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <strncat@plt>
mov    $0x1,%eax
jmp    1224 <gui_key_get_internal_code+0xa4>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
lea    0xd50(%rip),%rsi
jmp    121a <gui_key_get_internal_code+0x9a>
lea    0xd4c(%rip),%rsi
jmp    121a <gui_key_get_internal_code+0x9a>
mov    %r14,%rdi
call   10a0 <strdup@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
jmp    12f5 <gui_key_get_internal_code+0x175>
xor    %eax,%eax
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"
@.str.6 = [6 x i8] c"space\00"
@.str.7 = [2 x i8] c" \00"
define i8* @gui_key_get_internal_code(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 64
br i1 %10, label %11, label %18
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i64 @strchr(i8* %12, i8 signext 58)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = call i8* @strdup(i8* %16)
store i8* %17, i8** %2
br label %85
18: ; preds = %11, %1
%19 = load i8*, i8** %3
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %20, 1
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %18
store i8* null, i8** %2
br label %85
26: ; preds = %18
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 0, i8* %28
br label %29
29: ; preds = %78, %26
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
br i1 %33, label %34, label %79
34: ; preds = %29
%35 = load i8*, i8** %3
%36 = call i64 @strncmp(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i8*, i8** %4
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 6
store i8* %42, i8** %3
br label %43
43: ; preds = %38, %34
%44 = load i8*, i8** %3
%45 = call i64 @strncmp(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i8*, i8** %4
%49 = call i32 @strcat(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%50 = load i8*, i8** %3
%51 = getelementptr inbounds i8, i8* %50, i64 5
store i8* %51, i8** %3
br label %78
52: ; preds = %43
%53 = load i8*, i8** %3
%54 = call i64 @strncmp(i8* %53, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = load i8*, i8** %4
%58 = call i32 @strcat(i8* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%59 = load i8*, i8** %3
%60 = getelementptr inbounds i8, i8* %59, i64 5
store i8* %60, i8** %3
br label %77
61: ; preds = %52
%62 = load i8*, i8** %3
%63 = call i64 @strncmp(i8* %62, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 5)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %61
%66 = load i8*, i8** %4
%67 = call i32 @strcat(i8* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%68 = load i8*, i8** %3
%69 = getelementptr inbounds i8, i8* %68, i64 5
store i8* %69, i8** %3
br label %76
70: ; preds = %61
%71 = load i8*, i8** %4
%72 = load i8*, i8** %3
%73 = call i32 @strncat(i8* %71, i8* %72, i32 1)
%74 = load i8*, i8** %3
%75 = getelementptr inbounds i8, i8* %74, i32 1
store i8* %75, i8** %3
br label %76
76: ; preds = %70, %65
br label %77
77: ; preds = %76, %56
br label %78
78: ; preds = %77, %47
br label %29
79: ; preds = %29
%80 = load i8*, i8** %4
%81 = call i8* @strdup(i8* %80)
store i8* %81, i8** %5
%82 = load i8*, i8** %4
%83 = call i32 @free(i8* %82)
%84 = load i8*, i8** %5
store i8* %84, i8** %2
br label %85
85: ; preds = %79, %25, %15
%86 = load i8*, i8** %2
ret i8* %86
}

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"
@.str.6 = [6 x i8] c"space\00"
@.str.7 = [2 x i8] c" \00"
define noalias 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 %50
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 %50, 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 %47, label %17
17: ; preds = %14, %42
%18 = phi i8* [ %44, %42 ], [ %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 %42
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 %42
35: ; preds = %30
%36 = tail call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 5)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = tail call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %42
40: ; preds = %35
%41 = tail call i32 @strncat(i8* %12, i8* %25, i32 1)
br label %42
42: ; preds = %33, %40, %38, %28
%43 = phi i64 [ 5, %33 ], [ 1, %40 ], [ 5, %38 ], [ 5, %28 ]
%44 = getelementptr inbounds i8, i8* %25, i64 %43
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 0
br i1 %46, label %47, label %17
47: ; preds = %42, %14
%48 = tail call i8* @strdup(i8* %12)
%49 = tail call i32 @free(i8* %12)
br label %50
50: ; preds = %9, %47, %7
%51 = phi i8* [ %8, %7 ], [ %48, %47 ], [ null, %9 ]
ret i8* %51
}