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


x86 assembly (clang, -O0):
<gui_key_get_expanded_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1194 <gui_key_get_expanded_name+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1311 <gui_key_get_expanded_name+0x1a1>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
imul   $0x5,%eax,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c4 <gui_key_get_expanded_name+0x54>
movq   $0x0,-0x8(%rbp)
jmp    1311 <gui_key_get_expanded_name+0x1a1>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     12f3 <gui_key_get_expanded_name+0x183>
mov    -0x10(%rbp),%rdi
lea    0xe1d(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1213 <gui_key_get_expanded_name+0xa3>
mov    -0x18(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xded(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1253 <gui_key_get_expanded_name+0xe3>
mov    -0x18(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    12ee <gui_key_get_expanded_name+0x17e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x1,%eax
jne    1295 <gui_key_get_expanded_name+0x125>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1295 <gui_key_get_expanded_name+0x125>
mov    -0x18(%rbp),%rdi
lea    0xd95(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    12e9 <gui_key_get_expanded_name+0x179>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    12c6 <gui_key_get_expanded_name+0x156>
mov    -0x18(%rbp),%rdi
lea    0xd6a(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    12e4 <gui_key_get_expanded_name+0x174>
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    12e9 <gui_key_get_expanded_name+0x179>
jmp    12ee <gui_key_get_expanded_name+0x17e>
jmp    11cb <gui_key_get_expanded_name+0x5b>
mov    -0x18(%rbp),%rdi
call   1090 <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_expanded_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1288 <gui_key_get_expanded_name+0x118>
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    (%rax,%rax,4),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1288 <gui_key_get_expanded_name+0x118>
mov    %rax,%r14
movb   $0x0,(%rax)
cmpb   $0x0,(%rbx)
je     128c <gui_key_get_expanded_name+0x11c>
lea    0xe4a(%rip),%r15
lea    0xe47(%rip),%r12
lea    0xe47(%rip),%r13
lea    0xe43(%rip),%rbp
jmp    11e8 <gui_key_get_expanded_name+0x78>
nopl   (%rax)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1080 <strcat@plt>
add    $0x2,%rbx
cmpb   $0x0,(%rbx)
je     128c <gui_key_get_expanded_name+0x11c>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    120c <gui_key_get_expanded_name+0x9c>
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
add    $0x3,%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11d0 <gui_key_get_expanded_name+0x60>
movzbl (%rbx),%eax
cmp    $0x20,%al
je     1270 <gui_key_get_expanded_name+0x100>
cmp    $0x1,%al
jne    1250 <gui_key_get_expanded_name+0xe0>
cmpb   $0x0,0x1(%rbx)
je     1250 <gui_key_get_expanded_name+0xe0>
add    $0x1,%rbx
mov    %r14,%rdi
lea    0xdd4(%rip),%rsi
call   1080 <strcat@plt>
jmp    11df <gui_key_get_expanded_name+0x6f>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <strncat@plt>
jmp    127f <gui_key_get_expanded_name+0x10f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
lea    0xda0(%rip),%rsi
call   1080 <strcat@plt>
add    $0x1,%rbx
jmp    11df <gui_key_get_expanded_name+0x6f>
xor    %eax,%eax
jmp    12a2 <gui_key_get_expanded_name+0x132>
mov    %r14,%rdi
call   1090 <strdup@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\01[[\00"
@.str.1 = [7 x i8] c"meta2-\00"
@.str.2 = [3 x i8] c"\01[\00"
@.str.3 = [6 x i8] c"meta-\00"
@.str.4 = [6 x i8] c"ctrl-\00"
@.str.5 = [6 x i8] c"space\00"
define i8* @gui_key_get_expanded_name(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 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i8* null, i8** %2
br label %87
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = mul nsw i32 %11, 5
%13 = add nsw i32 %12, 1
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %9
store i8* null, i8** %2
br label %87
18: ; preds = %9
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 0
store i8 0, i8* %20
br label %21
21: ; preds = %80, %18
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = icmp ne i8 %24, 0
br i1 %25, label %26, label %81
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = call i64 @strncmp(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i8*, i8** %4
%32 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 3
store i8* %34, i8** %3
br label %35
35: ; preds = %30, %26
%36 = load i8*, i8** %3
%37 = call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i8*, i8** %4
%41 = call i32 @strcat(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i64 2
store i8* %43, i8** %3
br label %80
44: ; preds = %35
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %61
50: ; preds = %44
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %50
%57 = load i8*, i8** %4
%58 = call i32 @strcat(i8* %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%59 = load i8*, i8** %3
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %3
br label %79
61: ; preds = %50, %44
%62 = load i8*, i8** %3
%63 = getelementptr inbounds i8, i8* %62, i64 0
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 32
br i1 %66, label %67, label %72
67: ; preds = %61
%68 = load i8*, i8** %4
%69 = call i32 @strcat(i8* %68, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%70 = load i8*, i8** %3
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %3
br label %78
72: ; preds = %61
%73 = load i8*, i8** %4
%74 = load i8*, i8** %3
%75 = call i32 @strncat(i8* %73, i8* %74, i32 1)
%76 = load i8*, i8** %3
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %3
br label %78
78: ; preds = %72, %67
br label %79
79: ; preds = %78, %56
br label %80
80: ; preds = %79, %39
br label %21
81: ; preds = %21
%82 = load i8*, i8** %4
%83 = call i8* @strdup(i8* %82)
store i8* %83, i8** %5
%84 = load i8*, i8** %4
%85 = call i32 @free(i8* %84)
%86 = load i8*, i8** %5
store i8* %86, i8** %2
br label %87
87: ; preds = %81, %17, %8
%88 = load i8*, i8** %2
ret i8* %88
}

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