#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int get_FITS_key(int ncards, char **header, char *keyword, char *value) {
  char lkeyword[8];
  int i;
  if (strlen(keyword) > 8) {
    printf("\n\tWARNING! get_FITS_key(%s): invalid keyword\n", keyword);
    return (-1);
  }
  memcpy(lkeyword, keyword, strlen(keyword));
  for (i = (int)strlen(keyword); i < 8; i++)
    lkeyword[i] = ' ';
  for (i = 0; i < ncards; i++) {
    if (strncmp(header[i], lkeyword, 8) == 0) {
      memcpy(value, header[i] + 10, 70);
      break;
    }
  }
  if (i == ncards)
    return (-1);
  return (i);
}


x86 assembly (clang, -O0):
<get_FITS_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
jle    1185 <get_FITS_key+0x45>
mov    -0x18(%rbp),%rsi
lea    0xe8c(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1265 <get_FITS_key+0x125>
lea    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x8,-0x2c(%rbp)
jge    11da <get_FITS_key+0x9a>
movslq -0x2c(%rbp),%rax
movb   $0x20,-0x28(%rbp,%rax,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b9 <get_FITS_key+0x79>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1247 <get_FITS_key+0x107>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1234 <get_FITS_key+0xf4>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
add    $0xa,%rsi
mov    $0x46,%edx
call   1060 <memcpy@plt>
jmp    1247 <get_FITS_key+0x107>
jmp    1239 <get_FITS_key+0xf9>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e1 <get_FITS_key+0xa1>
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    125f <get_FITS_key+0x11f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1265 <get_FITS_key+0x125>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_FITS_key>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rsi,%r13
mov    %edi,%r15d
mov    %rdx,%rdi
call   1040 <strlen@plt>
cmp    $0x9,%eax
jl     118d <get_FITS_key+0x3d>
lea    0xe85(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
jmp    1229 <get_FITS_key+0xd9>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rsp,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cmp    $0x7,%eax
jg     11cb <get_FITS_key+0x7b>
movslq %eax,%rcx
lea    (%rsp,%rcx,1),%rdi
mov    $0x7,%edx
sub    %eax,%edx
add    $0x1,%rdx
mov    $0x20,%esi
call   1060 <memset@plt>
test   %r15d,%r15d
jle    1204 <get_FITS_key+0xb4>
mov    %r15d,%ebx
xor    %ebp,%ebp
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbp,8),%rdi
mov    %r12,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1208 <get_FITS_key+0xb8>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11e0 <get_FITS_key+0x90>
mov    %ebx,%ebp
jmp    121e <get_FITS_key+0xce>
xor    %ebp,%ebp
jmp    121e <get_FITS_key+0xce>
mov    0x0(%r13,%rbp,8),%rsi
add    $0xa,%rsi
mov    %r14,%rdi
mov    $0x46,%edx
call   1070 <memcpy@plt>
cmp    %r15d,%ebp
mov    $0xffffffff,%eax
cmovne %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"\0A\09WARNING! get_FITS_key(%s): invalid keyword\0A\00"
define i32 @get_FITS_key(i32 %0, i8** %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [8 x i8]
%11 = alloca i32
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%12 = load i8*, i8** %8
%13 = call i32 @strlen(i8* %12)
%14 = icmp sgt i32 %13, 8
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i8*, i8** %8
%17 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 -1, i32* %5
br label %70
18: ; preds = %4
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%20 = load i8*, i8** %8
%21 = load i8*, i8** %8
%22 = call i32 @strlen(i8* %21)
%23 = call i32 @memcpy(i8* %19, i8* %20, i32 %22)
%24 = load i8*, i8** %8
%25 = call i32 @strlen(i8* %24)
store i32 %25, i32* %11
br label %26
26: ; preds = %33, %18
%27 = load i32, i32* %11
%28 = icmp slt i32 %27, 8
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 %31
store i8 32, i8* %32
br label %33
33: ; preds = %29
%34 = load i32, i32* %11
%35 = add nsw i32 %34, 1
store i32 %35, i32* %11
br label %26
36: ; preds = %26
store i32 0, i32* %11
br label %37
37: ; preds = %60, %36
%38 = load i32, i32* %11
%39 = load i32, i32* %6
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %63
41: ; preds = %37
%42 = load i8**, i8*** %7
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
%47 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%48 = call i64 @strncmp(i8* %46, i8* %47, i32 8)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %59
50: ; preds = %41
%51 = load i8*, i8** %9
%52 = load i8**, i8*** %7
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = getelementptr inbounds i8, i8* %56, i64 10
%58 = call i32 @memcpy(i8* %51, i8* %57, i32 70)
br label %63
59: ; preds = %41
br label %60
60: ; preds = %59
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 1
store i32 %62, i32* %11
br label %37
63: ; preds = %50, %37
%64 = load i32, i32* %11
%65 = load i32, i32* %6
%66 = icmp eq i32 %64, %65
br i1 %66, label %67, label %68
67: ; preds = %63
store i32 -1, i32* %5
br label %70
68: ; preds = %63
%69 = load i32, i32* %11
store i32 %69, i32* %5
br label %70
70: ; preds = %68, %67, %15
%71 = load i32, i32* %5
ret i32 %71
}

LLVM IR (-O2):
@.str = [46 x i8] c"\0A\09WARNING! get_FITS_key(%s): invalid keyword\0A\00"
define i32 @get_FITS_key(i32 %0, i8** nocapture %1, i8* %2, i8* %3) {
%5 = alloca [8 x i8]
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @strlen(i8* %2)
%8 = icmp sgt i32 %7, 8
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %46
11: ; preds = %4
%12 = tail call i32 @strlen(i8* %2)
%13 = call i32 @memcpy(i8* %6, i8* %2, i32 %12)
%14 = call i32 @strlen(i8* %2)
%15 = icmp slt i32 %14, 8
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = sext i32 %14 to i64
%18 = getelementptr [8 x i8], [8 x i8]* %5, i64 0, i64 %17
%19 = sub i32 7, %14
%20 = zext i32 %19 to i64
%21 = add nuw nsw i64 %20, 1
br label %22
22: ; preds = %16, %11
%23 = icmp sgt i32 %0, 0
br i1 %23, label %24, label %42
24: ; preds = %22
%25 = zext i32 %0 to i64
br label %26
26: ; preds = %24, %39
%27 = phi i64 [ 0, %24 ], [ %40, %39 ]
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = load i8*, i8** %28
%30 = call i64 @strncmp(i8* %29, i8* %6, i32 8)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %26
%33 = trunc i64 %27 to i32
%34 = and i64 %27, 4294967295
%35 = getelementptr inbounds i8*, i8** %1, i64 %34
%36 = load i8*, i8** %35
%37 = getelementptr inbounds i8, i8* %36, i64 10
%38 = call i32 @memcpy(i8* %3, i8* %37, i32 70)
br label %42
39: ; preds = %26
%40 = add nuw nsw i64 %27, 1
%41 = icmp eq i64 %40, %25
br i1 %41, label %42, label %26
42: ; preds = %39, %22, %32
%43 = phi i32 [ %33, %32 ], [ 0, %22 ], [ %0, %39 ]
%44 = icmp eq i32 %43, %0
%45 = select i1 %44, i32 -1, i32 %43
br label %46
46: ; preds = %42, %9
%47 = phi i32 [ -1, %9 ], [ %45, %42 ]
ret i32 %47
}