#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*/ expkey_strupc(char const *);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *strstr(char const *, char *);
char *strtok(char *, char *);
char *qfits_expand_keyword(const char *keyword) {
  static char expanded[81];
  char ws[81];
  char *token;
  if (keyword == NULL)
    return NULL;
  if (strstr(keyword, ".") == NULL) {
    strcpy(expanded, expkey_strupc(keyword));
    return expanded;
  }
  sprintf(expanded, "HIERARCH ESO");
  strcpy(ws, expkey_strupc(keyword));
  token = strtok(ws, ".");
  while (token != NULL) {
    strcat(expanded, " ");
    strcat(expanded, token);
    token = strtok(NULL, ".");
  }
  return expanded;
}


x86 assembly (clang, -O0):
<qfits_expand_keyword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1187 <qfits_expand_keyword+0x27>
movq   $0x0,-0x8(%rbp)
jmp    125d <qfits_expand_keyword+0xfd>
mov    -0x10(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
jne    11c8 <qfits_expand_keyword+0x68>
mov    -0x10(%rbp),%rdi
call   1080 <expkey_strupc@plt>
mov    %eax,%esi
lea    0x2ead(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2ea1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    125d <qfits_expand_keyword+0xfd>
lea    0x2e91(%rip),%rdi
lea    0xe2c(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <expkey_strupc@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     1252 <qfits_expand_keyword+0xf2>
lea    0x2e43(%rip),%rdi
lea    0xdeb(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x78(%rbp),%rsi
lea    0x2e2c(%rip),%rdi
call   1050 <strcat@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdbc(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x78(%rbp)
jmp    120b <qfits_expand_keyword+0xab>
lea    0x2e07(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qfits_expand_keyword>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
test   %rdi,%rdi
je     120a <qfits_expand_keyword+0xba>
mov    %rdi,%rbx
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     120f <qfits_expand_keyword+0xbf>
movabs $0x4f534520484352,%rax
mov    %rax,0x2eda(%rip)
movabs $0x4843524152454948,%rax
52 43 48
mov    %rax,0x2ec4(%rip)
mov    %rbx,%rdi
call   1070 <expkey_strupc@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     122a <qfits_expand_keyword+0xda>
mov    %rax,%rbx
lea    0x2e91(%rip),%r12
lea    0xe39(%rip),%r14
lea    0xe23(%rip),%r15
nopl   (%rax)
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11e0 <qfits_expand_keyword+0x90>
jmp    1231 <qfits_expand_keyword+0xe1>
xor    %r12d,%r12d
jmp    1231 <qfits_expand_keyword+0xe1>
mov    %rbx,%rdi
call   1070 <expkey_strupc@plt>
lea    0x2e42(%rip),%r12
mov    %r12,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
jmp    1231 <qfits_expand_keyword+0xe1>
lea    0x2e2f(%rip),%r12
mov    %r12,%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@qfits_expand_keyword.expanded = internal global [81 x i8] zeroinitializer
@.str = [2 x i8] c".\00"
@.str.1 = [13 x i8] c"HIERARCH ESO\00"
@.str.2 = [2 x i8] c" \00"
define i8* @qfits_expand_keyword(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [81 x i8]
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* null, i8** %2
br label %34
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32* @strstr(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = call i32 @expkey_strupc(i8* %14)
%16 = call i32 @strcpy(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), i32 %15)
store i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), i8** %2
br label %34
17: ; preds = %9
%18 = call i32 @sprintf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%20 = load i8*, i8** %3
%21 = call i32 @expkey_strupc(i8* %20)
%22 = call i32 @strcpy(i8* %19, i32 %21)
%23 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%24 = call i8* @strtok(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %24, i8** %5
br label %25
25: ; preds = %28, %17
%26 = load i8*, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = call i32 @strcat(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = load i8*, i8** %5
%31 = call i32 @strcat(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), i8* %30)
%32 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %32, i8** %5
br label %25
33: ; preds = %25
store i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), i8** %2
br label %34
34: ; preds = %33, %13, %8
%35 = load i8*, i8** %2
ret i8* %35
}

LLVM IR (-O2):
@qfits_expand_keyword.expanded = internal global [81 x i8] zeroinitializer
@.str = [2 x i8] c".\00"
@.str.1 = [13 x i8] c"HIERARCH ESO\00"
@.str.2 = [2 x i8] c" \00"
define i8* @qfits_expand_keyword(i8* %0) {
%2 = alloca [81 x i8]
%3 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %22, label %5
5: ; preds = %1
%6 = tail call i8* @strchr(i8* %0, i32 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @expkey_strupc(i8* %0)
%10 = tail call i32 @strcpy(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), i32 %9)
br label %22
11: ; preds = %5
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 dereferenceable(13) getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), i8* align 1 dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 13, i1 false)
%12 = tail call i32 @expkey_strupc(i8* %0)
%13 = call i32 @strcpy(i8* %3, i32 %12)
%14 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %22, label %16
16: ; preds = %11, %16
%17 = phi i8* [ %20, %16 ], [ %14, %11 ]
%18 = call i32 @strcat(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @strcat(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), i8* %17)
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %16
22: ; preds = %16, %11, %1, %8
%23 = phi i8* [ getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), %8 ], [ null, %1 ], [ getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), %11 ], [ getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_expand_keyword.expanded, i64 0, i64 0), %16 ]
ret i8* %23
}