#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*/ sprintf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
char *expand_hierarch_keyword(char *dotkey, char *hierarchy) {
  char *token;
  char ws[128];
  sprintf(hierarchy, "HIERARCH ESO");
  strcpy(ws, dotkey);
  token = strtok(ws, ".");
  while (token != NULL) {
    strcat(hierarchy, " ");
    strcat(hierarchy, token);
    token = strtok(NULL, ".");
  }
  return hierarchy;
}


x86 assembly (clang, -O0):
<expand_hierarch_keyword>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cb <expand_hierarch_keyword+0x8b>
mov    -0x10(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe50(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    118a <expand_hierarch_keyword+0x4a>
mov    -0x10(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_hierarch_keyword>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r12
mov    %rdi,%rsi
movabs $0x4f534520484352,%rax
mov    %rax,0x5(%r12)
movabs $0x4843524152454948,%rax
52 43 48
mov    %rax,(%r12)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strtok@plt>
test   %rax,%rax
je     11c8 <expand_hierarch_keyword+0x98>
mov    %rax,%rbx
lea    0xe85(%rip),%r14
lea    0xe7c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a0 <expand_hierarch_keyword+0x70>
mov    %r12,%rax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"HIERARCH ESO\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [2 x i8] c" \00"
define i8* @expand_hierarch_keyword(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [128 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%13 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %5
br label %14
14: ; preds = %17, %2
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = call i32 @strcat(i8* %20, i8* %21)
%23 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %23, i8** %5
br label %14
24: ; preds = %14
%25 = load i8*, i8** %4
ret i8* %25
}

LLVM IR (-O2):
@.str = [13 x i8] c"HIERARCH ESO\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [2 x i8] c" \00"
define i8* @expand_hierarch_keyword(i8* %0, i8* returned %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(13) %1, i8* align 1 dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 13, i1 false)
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %2, %8
%9 = phi i8* [ %12, %8 ], [ %6, %2 ]
%10 = call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @strcat(i8* %1, i8* %9)
%12 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %8
14: ; preds = %8, %2
ret i8* %1
}