#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *qfits_getkey(const char *line) {
  static char key[81];
  int i;
  if (line == NULL) {
    return NULL;
  }
  if (!strncmp(line, "        ", 8)) {
    strcpy(key, "        ");
    return key;
  }
  if (!strncmp(line, "HISTORY ", 8)) {
    strcpy(key, "HISTORY");
    return key;
  }
  if (!strncmp(line, "COMMENT ", 8)) {
    strcpy(key, "COMMENT");
    return key;
  }
  if (!strncmp(line, "END ", 4)) {
    strcpy(key, "END");
    return key;
  }
  memset(key, 0, 81);
  i = 0;
  while (line[i] != '=' && i < 80)
    i++;
  if (i >= 80) {
    return NULL;
  }
  i--;
  while (line[i] == ' ' && i >= 0)
    i--;
  if (i <= 0) {
    return NULL;
  }
  i++;
  strncpy(key, line, i);
  key[i + 1] = (char)0;
  return key;
}


x86 assembly (clang, -O0):
<qfits_getkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <qfits_getkey+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1378 <qfits_getkey+0x238>
mov    -0x10(%rbp),%rdi
lea    0xe91(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    11a5 <qfits_getkey+0x65>
lea    0x2ec7(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1050 <strcpy@plt>
lea    0x2eb4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1378 <qfits_getkey+0x238>
mov    -0x10(%rbp),%rdi
lea    0xe59(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    11e6 <qfits_getkey+0xa6>
lea    0x2e86(%rip),%rdi
lea    0xe41(%rip),%rsi
call   1050 <strcpy@plt>
lea    0x2e73(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1378 <qfits_getkey+0x238>
mov    -0x10(%rbp),%rdi
lea    0xe29(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1227 <qfits_getkey+0xe7>
lea    0x2e45(%rip),%rdi
lea    0xe11(%rip),%rsi
call   1050 <strcpy@plt>
lea    0x2e32(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1378 <qfits_getkey+0x238>
mov    -0x10(%rbp),%rdi
lea    0xdf9(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1268 <qfits_getkey+0x128>
lea    0x2e04(%rip),%rdi
lea    0xddd(%rip),%rsi
call   1050 <strcpy@plt>
lea    0x2df1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1378 <qfits_getkey+0x238>
lea    0x2de1(%rip),%rdi
xor    %esi,%esi
mov    $0x51,%edx
call   1060 <memset@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x3d,%ecx
mov    %al,-0x15(%rbp)
je     12a6 <qfits_getkey+0x166>
cmpl   $0x50,-0x14(%rbp)
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    12b6 <qfits_getkey+0x176>
jmp    12c4 <qfits_getkey+0x184>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1282 <qfits_getkey+0x142>
cmpl   $0x50,-0x14(%rbp)
jl     12db <qfits_getkey+0x19b>
movq   $0x0,-0x8(%rbp)
jmp    1378 <qfits_getkey+0x238>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x16(%rbp)
jne    1308 <qfits_getkey+0x1c8>
cmpl   $0x0,-0x14(%rbp)
setge  %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
test   $0x1,%al
jne    1318 <qfits_getkey+0x1d8>
jmp    1326 <qfits_getkey+0x1e6>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    12e4 <qfits_getkey+0x1a4>
cmpl   $0x0,-0x14(%rbp)
jg     133d <qfits_getkey+0x1fd>
movq   $0x0,-0x8(%rbp)
jmp    1378 <qfits_getkey+0x238>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0x2cfc(%rip),%rdi
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2ce7(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2cdc(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qfits_getkey>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     121a <qfits_getkey+0xda>
mov    %rdi,%r15
lea    0xea8(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     121f <qfits_getkey+0xdf>
lea    0xe98(%rip),%rsi
mov    %r15,%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     122f <qfits_getkey+0xef>
lea    0xe8d(%rip),%rsi
mov    %r15,%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     123f <qfits_getkey+0xff>
lea    0xe82(%rip),%rsi
mov    %r15,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
lea    0x2e93(%rip),%r14
test   %eax,%eax
je     124f <qfits_getkey+0x10f>
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x51,%edx
call   1060 <memset@plt>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%rbx),%rax
cmpb   $0x3d,(%r15,%rbx,1)
je     11f4 <qfits_getkey+0xb4>
cmp    $0x50,%rbx
mov    %rax,%rbx
jb     11e0 <qfits_getkey+0xa0>
lea    -0x1(%rax),%ecx
cmp    $0x4f,%ecx
ja     121a <qfits_getkey+0xda>
nopl   0x0(%rax)
lea    -0x1(%rax),%rbx
cmpb   $0x20,-0x2(%r15,%rax,1)
jne    1215 <qfits_getkey+0xd5>
cmp    $0x1,%rax
mov    %rbx,%rax
jne    1200 <qfits_getkey+0xc0>
cmp    $0x2,%ebx
jae    1267 <qfits_getkey+0x127>
xor    %r14d,%r14d
jmp    125e <qfits_getkey+0x11e>
lea    0x2e2a(%rip),%r14
lea    0xdd3(%rip),%rsi
jmp    1256 <qfits_getkey+0x116>
lea    0x2e1a(%rip),%r14
lea    0xdd5(%rip),%rsi
jmp    1256 <qfits_getkey+0x116>
lea    0x2e0a(%rip),%r14
lea    0xdd6(%rip),%rsi
jmp    1256 <qfits_getkey+0x116>
lea    0xdda(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcpy@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
add    $0x1,%ebx
movb   $0x0,(%rbx,%r14,1)
jmp    125e <qfits_getkey+0x11e>

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

LLVM IR (-O2):
@qfits_getkey.key = internal global [81 x i8] zeroinitializer
@.str = [9 x i8] c" \00"
@.str.1 = [9 x i8] c"HISTORY \00"
@.str.2 = [8 x i8] c"HISTORY\00"
@.str.3 = [9 x i8] c"COMMENT \00"
@.str.4 = [8 x i8] c"COMMENT\00"
@.str.5 = [5 x i8] c"END \00"
@.str.6 = [4 x i8] c"END\00"
define i8* @qfits_getkey(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %52, label %3
3: ; preds = %1
%4 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @strcpy(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_getkey.key, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %52
8: ; preds = %3
%9 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @strcpy(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_getkey.key, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %52
13: ; preds = %8
%14 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @strcpy(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_getkey.key, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %52
18: ; preds = %13
%19 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @strcpy(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_getkey.key, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %52
23: ; preds = %18
%24 = tail call i32 @memset(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_getkey.key, i64 0, i64 0), i32 0, i32 81)
br label %25
25: ; preds = %25, %23
%26 = phi i64 [ %32, %25 ], [ 0, %23 ]
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = load i8, i8* %27
%29 = icmp ne i8 %28, 61
%30 = icmp ult i64 %26, 80
%31 = select i1 %29, i1 %30, i1 false
%32 = add nuw nsw i64 %26, 1
br i1 %31, label %25, label %33
33: ; preds = %25
%34 = trunc i64 %26 to i32
%35 = icmp ugt i32 %34, 79
br i1 %35, label %52, label %36
36: ; preds = %33, %36
%37 = phi i64 [ %38, %36 ], [ %26, %33 ]
%38 = add nsw i64 %37, -1
%39 = getelementptr inbounds i8, i8* %0, i64 %38
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 32
%42 = icmp ne i64 %37, 0
%43 = select i1 %41, i1 %42, i1 false
br i1 %43, label %36, label %44
44: ; preds = %36
%45 = trunc i64 %37 to i32
%46 = icmp ult i32 %45, 2
br i1 %46, label %52, label %47
47: ; preds = %44
%48 = tail call i32 @strncpy(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_getkey.key, i64 0, i64 0), i8* %0, i32 %45)
%49 = add nuw i64 %37, 1
%50 = and i64 %49, 4294967295
%51 = getelementptr inbounds [81 x i8], [81 x i8]* @qfits_getkey.key, i64 0, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %44, %33, %1, %47, %21, %16, %11, %6
%53 = phi i8* [ getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_getkey.key, i64 0, i64 0), %47 ], [ getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_getkey.key, i64 0, i64 0), %21 ], [ getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_getkey.key, i64 0, i64 0), %16 ], [ getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_getkey.key, i64 0, i64 0), %11 ], [ getelementptr inbounds ([81 x i8], [81 x i8]* @qfits_getkey.key, i64 0, i64 0), %6 ], [ null, %1 ], [ null, %33 ], [ null, %44 ]
ret i8* %53
}