#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *embed_hotkey(char *word, char *key) {
  char *newstr, *pos;
  newstr = (char *)malloc(strlen(word) * 2);
  newstr[0] = 0;
  if (strlen(key) == 1 && (pos = strchr(word, key[0]))) {
    strncpy(newstr, word, pos - word);
    sprintf(newstr + (pos - word), "Rk{%c}", key[0]);
    strcat(newstr, pos + 1);
  } else {
    sprintf(newstr, "%s (Rk{%s})", word, key);
  }
  return newstr;
}


x86 assembly (clang, -O0):
<embed_hotkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    1215 <embed_hotkey+0xb5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1215 <embed_hotkey+0xb5>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%edx
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1070 <strcat@plt>
jmp    122f <embed_hotkey+0xcf>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<embed_hotkey>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    (%rax,%rax,1),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    11e0 <embed_hotkey+0x80>
movsbl (%r14),%esi
mov    %rbx,%rdi
call   1050 <strchr@plt>
test   %rax,%rax
je     11e0 <embed_hotkey+0x80>
mov    %rax,%r12
mov    %rax,%r13
sub    %rbx,%r13
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
add    %r13,%rdi
movsbl (%r14),%edx
lea    0xe38(%rip),%rsi
xor    %eax,%eax
call   1080 <sprintf@plt>
add    $0x1,%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
jmp    11f7 <embed_hotkey+0x97>
lea    0xe20(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"Rk{%c}\00"
@.str.1 = [12 x i8] c"%s (Rk{%s})\00"
define i8* @embed_hotkey(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = mul nsw i32 %8, 2
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 0, i8* %13
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %50
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = call i8* @strchr(i8* %18, i8 signext %21)
store i8* %22, i8** %6
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %50
24: ; preds = %17
%25 = load i8*, i8** %5
%26 = load i8*, i8** %3
%27 = load i8*, i8** %6
%28 = load i8*, i8** %3
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = trunc i64 %31 to i32
%33 = call i32 @strncpy(i8* %25, i8* %26, i32 %32)
%34 = load i8*, i8** %5
%35 = load i8*, i8** %6
%36 = load i8*, i8** %3
%37 = ptrtoint i8* %35 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
%40 = getelementptr inbounds i8, i8* %34, i64 %39
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %44)
%46 = load i8*, i8** %5
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i64 1
%49 = call i32 @strcat(i8* %46, i8* %48)
br label %55
50: ; preds = %17, %2
%51 = load i8*, i8** %5
%52 = load i8*, i8** %3
%53 = load i8*, i8** %4
%54 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %52, i8* %53)
br label %55
55: ; preds = %50, %24
%56 = load i8*, i8** %5
ret i8* %56
}

LLVM IR (-O2):
@.str = [7 x i8] c"Rk{%c}\00"
@.str.1 = [12 x i8] c"%s (Rk{%s})\00"
define i8* @embed_hotkey(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = shl nsw i32 %3, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
store i8 0, i8* %6
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %25
9: ; preds = %2
%10 = load i8, i8* %1
%11 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %25, label %13
13: ; preds = %9
%14 = ptrtoint i8* %11 to i64
%15 = ptrtoint i8* %0 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
%18 = tail call i32 @strncpy(i8* %6, i8* %0, i32 %17)
%19 = getelementptr inbounds i8, i8* %6, i64 %16
%20 = load i8, i8* %1
%21 = sext i8 %20 to i32
%22 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds i8, i8* %11, i64 1
%24 = tail call i32 @strcat(i8* %6, i8* %23)
br label %27
25: ; preds = %9, %2
%26 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %27
27: ; preds = %25, %13
ret i8* %6
}