#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_key_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, "\x01[[", 3) == 0) {
        strcat(result, "meta2-");
        key += 3;
      }
      if (strncmp(key, "\x01[\x01G", 4) == 0) {
        strcat(result, "mod4-");
        key += 4;
      }
      if (strncmp(key, "\x01[", 2) == 0) {
        strcat(result, "meta-");
        key += 2;
      } else if ((key[0] == '\x01') && (key[1])) {
        strcat(result, "ctrl-");
        key++;
      } else {
        strncat(result, key, 1);
        key++;
      }
    }
  }
  return result;
}


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    1174 <gui_key_get_expanded_name+0x24>
movq   $0x0,-0x8(%rbp)
jmp    12d8 <gui_key_get_expanded_name+0x188>
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     12d0 <gui_key_get_expanded_name+0x180>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     12cb <gui_key_get_expanded_name+0x17b>
mov    -0x10(%rbp),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11e6 <gui_key_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    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1221 <gui_key_get_expanded_name+0xd1>
mov    -0x18(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdea(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1261 <gui_key_get_expanded_name+0x111>
mov    -0x18(%rbp),%rdi
lea    0xdce(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    12c6 <gui_key_get_expanded_name+0x176>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x1,%eax
jne    12a3 <gui_key_get_expanded_name+0x153>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     12a3 <gui_key_get_expanded_name+0x153>
mov    -0x18(%rbp),%rdi
lea    0xd92(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    12c1 <gui_key_get_expanded_name+0x171>
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    12c6 <gui_key_get_expanded_name+0x176>
jmp    119e <gui_key_get_expanded_name+0x4e>
jmp    12d0 <gui_key_get_expanded_name+0x180>
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_expanded_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1274 <gui_key_get_expanded_name+0x124>
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    (%rax,%rax,4),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1274 <gui_key_get_expanded_name+0x124>
mov    %rax,%r14
movb   $0x0,(%rax)
cmpb   $0x0,(%rbx)
je     1277 <gui_key_get_expanded_name+0x127>
lea    0xe6a(%rip),%r15
lea    0xe6e(%rip),%r13
lea    0xe72(%rip),%r12
lea    0xe6e(%rip),%rbp
jmp    11cd <gui_key_get_expanded_name+0x7d>
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
add    $0x1,%rbx
cmpb   $0x0,(%rbx)
je     1277 <gui_key_get_expanded_name+0x127>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11f5 <gui_key_get_expanded_name+0xa5>
mov    %r14,%rdi
lea    0xe18(%rip),%rsi
call   1070 <strcat@plt>
add    $0x3,%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    121d <gui_key_get_expanded_name+0xcd>
mov    %r14,%rdi
lea    0xdfc(%rip),%rsi
call   1070 <strcat@plt>
add    $0x4,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1260 <gui_key_get_expanded_name+0x110>
cmpb   $0x1,(%rbx)
jne    11b0 <gui_key_get_expanded_name+0x60>
cmpb   $0x0,0x1(%rbx)
je     11b0 <gui_key_get_expanded_name+0x60>
add    $0x1,%rbx
mov    %r14,%rdi
lea    0xdcc(%rip),%rsi
call   1070 <strcat@plt>
jmp    11c4 <gui_key_get_expanded_name+0x74>
nopl   (%rax)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1070 <strcat@plt>
add    $0x2,%rbx
jmp    11c4 <gui_key_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"\01[[\00"
@.str.1 = [7 x i8] c"meta2-\00"
@.str.2 = [5 x i8] c"\01[\01G\00"
@.str.3 = [6 x i8] c"mod4-\00"
@.str.4 = [3 x i8] c"\01[\00"
@.str.5 = [6 x i8] c"meta-\00"
@.str.6 = [6 x i8] c"ctrl-\00"
define i8* @gui_key_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 %79
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 %77
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 = %75, %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 %76
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 ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%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 4
store i8* %41, i8** %3
br label %42
42: ; preds = %37, %33
%43 = load i8*, i8** %3
%44 = call i64 @strncmp(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %42
%47 = load i8*, i8** %4
%48 = call i32 @strcat(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i64 2
store i8* %50, i8** %3
br label %75
51: ; preds = %42
%52 = load i8*, i8** %3
%53 = getelementptr inbounds i8, i8* %52, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 1
br i1 %56, label %57, label %68
57: ; preds = %51
%58 = load i8*, i8** %3
%59 = getelementptr inbounds i8, i8* %58, i64 1
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %68
63: ; preds = %57
%64 = load i8*, i8** %4
%65 = call i32 @strcat(i8* %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%66 = load i8*, i8** %3
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %3
br label %74
68: ; preds = %57, %51
%69 = load i8*, i8** %4
%70 = load i8*, i8** %3
%71 = call i32 @strncat(i8* %69, i8* %70, i32 1)
%72 = load i8*, i8** %3
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %3
br label %74
74: ; preds = %68, %63
br label %75
75: ; preds = %74, %46
br label %19
76: ; preds = %19
br label %77
77: ; preds = %76, %8
%78 = load i8*, i8** %4
store i8* %78, i8** %2
br label %79
79: ; preds = %77, %7
%80 = load i8*, i8** %2
ret i8* %80
}

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