#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 *, double);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int replace_keyword(char *fitsheader, double value, const char *key) {
  int i, length, total_length;
  char *temp;
  char char_value[80];
  int key_length = 8;
  char mod_key[8 + 2];
  strcpy(mod_key, key);
  length = strlen(mod_key);
  for (i = length; i < key_length; i++)
    strcat(mod_key, " ");
  strcat(mod_key, "=");
  temp = strstr(fitsheader, mod_key);
  if (temp == NULL)
    return 1;
  temp = strchr(temp, '=');
  if (temp == NULL)
    return 1;
  if (*(++temp) == ' ')
    temp++;
  sprintf(char_value, "%9.8f", value);
  total_length = strlen(char_value);
  strncpy(temp, char_value, total_length);
  temp += total_length;
  while (*(temp) != ' ') {
    *(temp++) = ' ';
  }
  return 0;
}


x86 assembly (clang, -O0):
<replace_keyword>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movl   $0x8,-0x94(%rbp)
lea    -0x9e(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x9e(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x94(%rbp),%eax
jge    11e7 <replace_keyword+0x77>
lea    -0x9e(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b7 <replace_keyword+0x47>
lea    -0x9e(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x9e(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1225 <replace_keyword+0xb5>
movl   $0x1,-0x4(%rbp)
jmp    12ef <replace_keyword+0x17f>
mov    -0x38(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    124e <replace_keyword+0xde>
movl   $0x1,-0x4(%rbp)
jmp    12ef <replace_keyword+0x17f>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x20,%eax
jne    1276 <replace_keyword+0x106>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
lea    -0x90(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xd7b(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     12e8 <replace_keyword+0x178>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x20,(%rax)
jmp    12c1 <replace_keyword+0x151>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_keyword>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
movsd  %xmm0,0x18(%rsp)
mov    %rdi,%r14
lea    0xe(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x7,%eax
jg     11bf <replace_keyword+0x4f>
mov    %eax,%ebp
add    $0xfffffff8,%ebp
lea    0xe57(%rip),%r15
lea    0xe(%rsp),%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
inc    %ebp
jne    11b0 <replace_keyword+0x40>
lea    0xe3c(%rip),%rsi
lea    0xe(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strstr@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     125d <replace_keyword+0xed>
mov    %rax,%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     125d <replace_keyword+0xed>
lea    0x1(%rax),%rcx
mov    %rax,%rbx
add    $0x2,%rbx
cmpb   $0x20,0x1(%rax)
cmovne %rcx,%rbx
lea    0xdf0(%rip),%rsi
lea    0x20(%rsp),%r14
mov    %r14,%rdi
movsd  0x18(%rsp),%xmm0
call   1080 <sprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
xor    %ebp,%ebp
cmpb   $0x20,(%rbx,%rax,1)
je     125d <replace_keyword+0xed>
add    %rbx,%rax
add    $0x1,%rax
movb   $0x20,-0x1(%rax)
cmpb   $0x20,(%rax)
lea    0x1(%rax),%rax
jne    1250 <replace_keyword+0xe0>
mov    %ebp,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"=\00"
@.str.2 = [6 x i8] c"%9.8f\00"
define i32 @replace_keyword(i8* %0, double %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca double
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca [80 x i8]
%13 = alloca i32
%14 = alloca [10 x i8]
store i8* %0, i8** %5
store double %1, double* %6
store i8* %2, i8** %7
store i32 8, i32* %13
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %14, i64 0, i64 0
%16 = load i8*, i8** %7
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %14, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %9
%20 = load i32, i32* %9
store i32 %20, i32* %8
br label %21
21: ; preds = %28, %3
%22 = load i32, i32* %8
%23 = load i32, i32* %13
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %14, i64 0, i64 0
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %25
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %21
31: ; preds = %21
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %14, i64 0, i64 0
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%34 = load i8*, i8** %5
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %14, i64 0, i64 0
%36 = call i8* @strstr(i8* %34, i8* %35)
store i8* %36, i8** %11
%37 = load i8*, i8** %11
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %40
39: ; preds = %31
store i32 1, i32* %4
br label %78
40: ; preds = %31
%41 = load i8*, i8** %11
%42 = call i8* @strchr(i8* %41, i8 signext 61)
store i8* %42, i8** %11
%43 = load i8*, i8** %11
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %46
45: ; preds = %40
store i32 1, i32* %4
br label %78
46: ; preds = %40
%47 = load i8*, i8** %11
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %11
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 32
br i1 %51, label %52, label %55
52: ; preds = %46
%53 = load i8*, i8** %11
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %11
br label %55
55: ; preds = %52, %46
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%57 = load double, double* %6
%58 = call i32 @sprintf(i8* %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %57)
%59 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%60 = call i32 @strlen(i8* %59)
store i32 %60, i32* %10
%61 = load i8*, i8** %11
%62 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%63 = load i32, i32* %10
%64 = call i32 @strncpy(i8* %61, i8* %62, i32 %63)
%65 = load i32, i32* %10
%66 = load i8*, i8** %11
%67 = sext i32 %65 to i64
%68 = getelementptr inbounds i8, i8* %66, i64 %67
store i8* %68, i8** %11
br label %69
69: ; preds = %74, %55
%70 = load i8*, i8** %11
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp ne i32 %72, 32
br i1 %73, label %74, label %77
74: ; preds = %69
%75 = load i8*, i8** %11
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %11
store i8 32, i8* %75
br label %69
77: ; preds = %69
store i32 0, i32* %4
br label %78
78: ; preds = %77, %45, %39
%79 = load i32, i32* %4
ret i32 %79
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"=\00"
@.str.2 = [6 x i8] c"%9.8f\00"
define i32 @replace_keyword(i8* %0, double %1, i8* %2) {
%4 = alloca [80 x i8]
%5 = alloca [10 x i8]
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%8 = call i32 @strcpy(i8* %7, i8* %2)
%9 = call i32 @strlen(i8* %7)
%10 = icmp slt i32 %9, 8
br i1 %10, label %11, label %16
11: ; preds = %3, %11
%12 = phi i32 [ %14, %11 ], [ %9, %3 ]
%13 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = add i32 %12, 1
%15 = icmp eq i32 %14, 8
br i1 %15, label %16, label %11
16: ; preds = %11, %3
%17 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = call i8* @strstr(i8* dereferenceable(1) %0, i8* %7)
%19 = icmp eq i8* %18, null
br i1 %19, label %41, label %20
20: ; preds = %16
%21 = call i8* @strchr(i8* %18, i8 signext 61)
%22 = icmp eq i8* %21, null
br i1 %22, label %41, label %23
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %21, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 32
%27 = getelementptr inbounds i8, i8* %21, i64 2
%28 = select i1 %26, i8* %27, i8* %24
%29 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %1)
%30 = call i32 @strlen(i8* %6)
%31 = call i32 @strncpy(i8* %28, i8* %6, i32 %30)
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 32
br i1 %35, label %41, label %36
36: ; preds = %23, %36
%37 = phi i8* [ %38, %36 ], [ %33, %23 ]
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8 32, i8* %37
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 32
br i1 %40, label %41, label %36
41: ; preds = %36, %23, %20, %16
%42 = phi i32 [ 1, %16 ], [ 1, %20 ], [ 0, %23 ], [ 0, %36 ]
ret i32 %42
}