#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 strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ wstrncmp(char *, char *, int);
int fitsfind(char *fitsbuf, char *keyword) {
  char *ptr;
  int i, len;
  len = strlen(keyword);
  for (i = 0; strncmp(ptr = &fitsbuf[80 * i], "END     ", 8); i++)
    if (!wstrncmp(ptr, keyword, len))
      return i;
  if (strncmp(keyword, "END     ", 8))
    return (-1);
  else
    return i;
}


x86 assembly (clang, -O0):
<fitsfind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
imul   $0x50,-0x24(%rbp),%eax
cltq
add    %rax,%rdi
mov    %rdi,-0x20(%rbp)
lea    0xe95(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11b6 <fitsfind+0x86>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1050 <wstrncmp@plt>
cmp    $0x0,%eax
jne    11a3 <fitsfind+0x73>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <fitsfind+0xb7>
jmp    11a8 <fitsfind+0x78>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1153 <fitsfind+0x23>
mov    -0x18(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11e1 <fitsfind+0xb1>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e7 <fitsfind+0xb7>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fitsfind>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0xead(%rip),%rsi
mov    %r13,%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11ab <fitsfind+0x7b>
mov    $0x50,%r12d
mov    %r13,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <wstrncmp@plt>
test   %eax,%eax
je     11c6 <fitsfind+0x96>
mov    %r12d,%ebx
and    $0xfffffff0,%ebx
add    %r13,%rbx
mov    %rbx,%rdi
lea    0xe6b(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
add    $0x1,%ebp
add    $0x50,%r12
test   %rax,%rax
jne    1170 <fitsfind+0x40>
lea    0xe4e(%rip),%rsi
mov    %r14,%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
neg    %rax
sbb    %eax,%eax
or     %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"END \00"
define i32 @fitsfind(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
store i32 0, i32* %7
br label %11
11: ; preds = %28, %2
%12 = load i8*, i8** %4
%13 = load i32, i32* %7
%14 = mul nsw i32 80, %13
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
store i8* %16, i8** %6
%17 = call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %11
%20 = load i8*, i8** %6
%21 = load i8*, i8** %5
%22 = load i32, i32* %8
%23 = call i32 @wstrncmp(i8* %20, i8* %21, i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %19
%26 = load i32, i32* %7
store i32 %26, i32* %3
br label %38
27: ; preds = %19
br label %28
28: ; preds = %27
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %11
31: ; preds = %11
%32 = load i8*, i8** %5
%33 = call i64 @strncmp(i8* %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 -1, i32* %3
br label %38
36: ; preds = %31
%37 = load i32, i32* %7
store i32 %37, i32* %3
br label %38
38: ; preds = %36, %35, %25
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [9 x i8] c"END \00"
define i32 @fitsfind(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%5 = icmp eq i64 %4, 0
br i1 %5, label %20, label %6
6: ; preds = %2, %11
%7 = phi i64 [ %12, %11 ], [ 0, %2 ]
%8 = phi i8* [ %15, %11 ], [ %0, %2 ]
%9 = tail call i32 @wstrncmp(i8* %8, i8* %1, i32 %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %25, label %11
11: ; preds = %6
%12 = add nuw i64 %7, 1
%13 = mul i64 %12, 80
%14 = and i64 %13, 4294967280
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = tail call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %11
%19 = trunc i64 %12 to i32
br label %20
20: ; preds = %18, %2
%21 = phi i32 [ 0, %2 ], [ %19, %18 ]
%22 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%23 = icmp eq i64 %22, 0
%24 = select i1 %23, i32 %21, i32 -1
br label %27
25: ; preds = %6
%26 = trunc i64 %7 to i32
br label %27
27: ; preds = %25, %20
%28 = phi i32 [ %24, %20 ], [ %26, %25 ]
ret i32 %28
}