#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, "mod4-", 5) == 0) {
        strcat(result, "\x01[\x01G");
        key += 5;
      }
      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    1325 <gui_key_get_internal_code+0x1b5>
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     1310 <gui_key_get_internal_code+0x1a0>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     130b <gui_key_get_internal_code+0x19b>
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    1263 <gui_key_get_internal_code+0xf3>
mov    -0x18(%rbp),%rdi
lea    0xdbf(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xda8(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12a3 <gui_key_get_internal_code+0x133>
mov    -0x18(%rbp),%rdi
lea    0xd8f(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
jmp    1306 <gui_key_get_internal_code+0x196>
mov    -0x10(%rbp),%rdi
lea    0xd71(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12e3 <gui_key_get_internal_code+0x173>
mov    -0x18(%rbp),%rdi
lea    0xd58(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
jmp    1301 <gui_key_get_internal_code+0x191>
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    1306 <gui_key_get_internal_code+0x196>
jmp    11e0 <gui_key_get_internal_code+0x70>
jmp    131d <gui_key_get_internal_code+0x1ad>
movq   $0x0,-0x8(%rbp)
jmp    1325 <gui_key_get_internal_code+0x1b5>
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     12c9 <gui_key_get_internal_code+0x159>
mov    %rax,%r14
movb   $0x0,(%rax)
cmpb   $0x0,(%rbx)
je     12cc <gui_key_get_internal_code+0x15c>
lea    0xe25(%rip),%r15
lea    0xe29(%rip),%r13
lea    0xe2d(%rip),%r12
lea    0xe2f(%rip),%rbp
jmp    1220 <gui_key_get_internal_code+0xb0>
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     12cc <gui_key_get_internal_code+0x15c>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1248 <gui_key_get_internal_code+0xd8>
mov    %r14,%rdi
lea    0xdc8(%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
jne    1270 <gui_key_get_internal_code+0x100>
mov    %r14,%rdi
lea    0xdaa(%rip),%rsi
call   1080 <strcat@plt>
add    $0x5,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12b0 <gui_key_get_internal_code+0x140>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
mov    %r14,%rdi
test   %rax,%rax
jne    1200 <gui_key_get_internal_code+0x90>
lea    0xd7d(%rip),%rsi
jmp    12ba <gui_key_get_internal_code+0x14a>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
lea    0xd62(%rip),%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"mod4-\00"
@.str.3 = [5 x i8] c"\01[\01G\00"
@.str.4 = [6 x i8] c"meta-\00"
@.str.5 = [3 x i8] c"\01[\00"
@.str.6 = [6 x i8] c"ctrl-\00"
@.str.7 = [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 %79
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 %76
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 = %74, %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 %75
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 ([5 x i8], [5 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 %49
49: ; preds = %44, %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 ([3 x i8], [3 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 %74
58: ; preds = %49
%59 = load i8*, i8** %3
%60 = call i64 @strncmp(i8* %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 5)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %58
%63 = load i8*, i8** %4
%64 = call i32 @strcat(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%65 = load i8*, i8** %3
%66 = getelementptr inbounds i8, i8* %65, i64 5
store i8* %66, i8** %3
br label %73
67: ; preds = %58
%68 = load i8*, i8** %4
%69 = load i8*, i8** %3
%70 = call i32 @strncat(i8* %68, i8* %69, i32 1)
%71 = load i8*, i8** %3
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %3
br label %73
73: ; preds = %67, %62
br label %74
74: ; preds = %73, %53
br label %26
75: ; preds = %26
br label %77
76: ; preds = %17
store i8* null, i8** %2
br label %79
77: ; preds = %75
%78 = load i8*, i8** %4
store i8* %78, i8** %2
br label %79
79: ; preds = %77, %76, %14
%80 = load i8*, i8** %2
ret i8* %80
}

LLVM IR (-O2):
@.str = [7 x i8] c"meta2-\00"
@.str.1 = [4 x i8] c"\01[[\00"
@.str.2 = [6 x i8] c"mod4-\00"
@.str.3 = [5 x i8] c"\01[\01G\00"
@.str.4 = [6 x i8] c"meta-\00"
@.str.5 = [3 x i8] c"\01[\00"
@.str.6 = [6 x i8] c"ctrl-\00"
@.str.7 = [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 %49
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 %49, 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 %49, label %17
17: ; preds = %14, %44
%18 = phi i8* [ %46, %44 ], [ %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 %31
28: ; preds = %24
%29 = tail call i32 @strcat(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%30 = getelementptr inbounds i8, i8* %25, i64 5
br label %31
31: ; preds = %28, %24
%32 = phi i8* [ %30, %28 ], [ %25, %24 ]
%33 = tail call i64 @strncmp(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = tail call i32 @strcat(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %44
37: ; preds = %31
%38 = tail call i64 @strncmp(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 5)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = tail call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %44
42: ; preds = %37
%43 = tail call i32 @strncat(i8* %12, i8* %32, i32 1)
br label %44
44: ; preds = %40, %42, %35
%45 = phi i64 [ 5, %40 ], [ 1, %42 ], [ 5, %35 ]
%46 = getelementptr inbounds i8, i8* %32, i64 %45
%47 = load i8, i8* %46
%48 = icmp eq i8 %47, 0
br i1 %48, label %49, label %17
49: ; preds = %44, %14, %9, %7
%50 = phi i8* [ %8, %7 ], [ null, %9 ], [ %12, %14 ], [ %12, %44 ]
ret i8* %50
}