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


x86 assembly (clang, -O0):
<gui_keyboard_get_expanded_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <gui_keyboard_get_expanded_name+0x24>
movq   $0x0,-0x8(%rbp)
jmp    129d <gui_keyboard_get_expanded_name+0x14d>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
imul   $0x5,%eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1295 <gui_keyboard_get_expanded_name+0x145>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1290 <gui_keyboard_get_expanded_name+0x140>
mov    -0x10(%rbp),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11e6 <gui_keyboard_get_expanded_name+0x96>
mov    -0x18(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe1a(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1226 <gui_keyboard_get_expanded_name+0xd6>
mov    -0x18(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    128b <gui_keyboard_get_expanded_name+0x13b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5e,%eax
jne    1268 <gui_keyboard_get_expanded_name+0x118>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1268 <gui_keyboard_get_expanded_name+0x118>
mov    -0x18(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1286 <gui_keyboard_get_expanded_name+0x136>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    128b <gui_keyboard_get_expanded_name+0x13b>
jmp    119e <gui_keyboard_get_expanded_name+0x4e>
jmp    1295 <gui_keyboard_get_expanded_name+0x145>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_keyboard_get_expanded_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1241 <gui_keyboard_get_expanded_name+0xf1>
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    (%rax,%rax,4),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1241 <gui_keyboard_get_expanded_name+0xf1>
mov    %rax,%r14
movb   $0x0,(%rax)
cmpb   $0x0,(%rbx)
je     1244 <gui_keyboard_get_expanded_name+0xf4>
lea    0xe6a(%rip),%r15
lea    0xe67(%rip),%r12
lea    0xe67(%rip),%r13
lea    0xe63(%rip),%rbp
jmp    11c9 <gui_keyboard_get_expanded_name+0x79>
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
add    $0x1,%rbx
cmpb   $0x0,(%rbx)
je     1244 <gui_keyboard_get_expanded_name+0xf4>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11ed <gui_keyboard_get_expanded_name+0x9d>
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
add    $0x3,%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1230 <gui_keyboard_get_expanded_name+0xe0>
cmpb   $0x5e,(%rbx)
jne    11b0 <gui_keyboard_get_expanded_name+0x60>
cmpb   $0x0,0x1(%rbx)
je     11b0 <gui_keyboard_get_expanded_name+0x60>
add    $0x1,%rbx
mov    %r14,%rdi
lea    0xdf9(%rip),%rsi
call   1070 <strcat@plt>
jmp    11c4 <gui_keyboard_get_expanded_name+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1070 <strcat@plt>
add    $0x2,%rbx
jmp    11c4 <gui_keyboard_get_expanded_name+0x74>
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 = [4 x i8] c"^[[\00"
@.str.1 = [7 x i8] c"meta2-\00"
@.str.2 = [3 x i8] c"^[\00"
@.str.3 = [6 x i8] c"meta-\00"
@.str.4 = [6 x i8] c"ctrl-\00"
define i8* @gui_keyboard_get_expanded_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i8* null, i8** %2
br label %70
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = mul nsw i32 %10, 5
%12 = add nsw i32 %11, 1
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %68
16: ; preds = %8
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 0, i8* %18
br label %19
19: ; preds = %66, %16
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %67
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i8*, i8** %4
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 3
store i8* %32, i8** %3
br label %33
33: ; preds = %28, %24
%34 = load i8*, i8** %3
%35 = call i64 @strncmp(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i8*, i8** %4
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i64 2
store i8* %41, i8** %3
br label %66
42: ; preds = %33
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 94
br i1 %47, label %48, label %59
48: ; preds = %42
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %48
%55 = load i8*, i8** %4
%56 = call i32 @strcat(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%57 = load i8*, i8** %3
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %3
br label %65
59: ; preds = %48, %42
%60 = load i8*, i8** %4
%61 = load i8*, i8** %3
%62 = call i32 @strncat(i8* %60, i8* %61, i32 1)
%63 = load i8*, i8** %3
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %3
br label %65
65: ; preds = %59, %54
br label %66
66: ; preds = %65, %37
br label %19
67: ; preds = %19
br label %68
68: ; preds = %67, %8
%69 = load i8*, i8** %4
store i8* %69, i8** %2
br label %70
70: ; preds = %68, %7
%71 = load i8*, i8** %2
ret i8* %71
}

LLVM IR (-O2):
@.str = [4 x i8] c"^[[\00"
@.str.1 = [7 x i8] c"meta2-\00"
@.str.2 = [3 x i8] c"^[\00"
@.str.3 = [6 x i8] c"meta-\00"
@.str.4 = [6 x i8] c"ctrl-\00"
define i8* @gui_keyboard_get_expanded_name(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %42, 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 %42, 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 %42, label %12
12: ; preds = %9, %38
%13 = phi i8* [ %39, %38 ], [ %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 %38
26: ; preds = %19
%27 = load i8, i8* %20
%28 = icmp eq i8 %27, 94
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = getelementptr inbounds i8, i8* %20, i64 1
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %38
35: ; preds = %29, %26
%36 = tail call i32 @strncat(i8* %7, i8* %20, i32 1)
%37 = getelementptr inbounds i8, i8* %20, i64 1
br label %38
38: ; preds = %33, %35, %23
%39 = phi i8* [ %25, %23 ], [ %30, %33 ], [ %37, %35 ]
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
br i1 %41, label %42, label %12
42: ; preds = %38, %9, %3, %1
%43 = phi i8* [ null, %1 ], [ null, %3 ], [ %7, %9 ], [ %7, %38 ]
ret i8* %43
}