#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
scalar_t__ strncmp(char *, char *, int);
int has_daophot_header(FILE *stream) {
  char *header1stline =
      " NL    NX    NY  LOWBAD HIGHBAD  THRESH     AP1  PH/ADU  RNOISE    FRAD";
  char buffer[BUFSIZ];
  long position;
  if ((position = ftell(stream)) != -1L) {
    rewind(stream);
    fgets(buffer, BUFSIZ, stream);
    fseek(stream, position, SEEK_SET);
    if (strncmp(buffer, header1stline, (71)) == 0)
      return 1;
    else
      return 0;
  } else
    return -1;
}


x86 assembly (clang, -O0):
<has_daophot_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x30(%rbp)
cmp    $0xffffffffffffffff,%rax
je     1221 <has_daophot_header+0xd1>
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x40(%rbp),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x47,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    120e <has_daophot_header+0xbe>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    122f <has_daophot_header+0xdf>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    122f <has_daophot_header+0xdf>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_daophot_header>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    0x2e7b(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
call   1060 <ftell@plt>
cmp    $0xffffffffffffffff,%rax
je     11d4 <has_daophot_header+0x84>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <rewind@plt>
mov    (%r12),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <fgets@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <fseek@plt>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
mov    $0x47,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    11d9 <has_daophot_header+0x89>
mov    $0xffffffff,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [72 x i8] c" NL NX NY LOWBAD HIGHBAD THRESH AP1 PH/ADU RNOISE FRAD\00"
@BUFSIZ = global i32 0
@SEEK_SET = global i32 0
define i32 @has_daophot_header(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %3
store i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i8** %4
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = load i32*, i32** %3
%14 = call i64 @ftell(i32* %13)
store i64 %14, i64* %7
%15 = icmp ne i64 %14, -1
br i1 %15, label %16, label %31
16: ; preds = %1
%17 = load i32*, i32** %3
%18 = call i32 @rewind(i32* %17)
%19 = load i32, i32* @BUFSIZ
%20 = load i32*, i32** %3
%21 = call i32 @fgets(i8* %12, i32 %19, i32* %20)
%22 = load i32*, i32** %3
%23 = load i64, i64* %7
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %22, i64 %23, i32 %24)
%26 = load i8*, i8** %4
%27 = call i64 @strncmp(i8* %12, i8* %26, i32 71)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %16
store i32 1, i32* %2
store i32 1, i32* %8
br label %32
30: ; preds = %16
store i32 0, i32* %2
store i32 1, i32* %8
br label %32
31: ; preds = %1
store i32 -1, i32* %2
store i32 1, i32* %8
br label %32
32: ; preds = %31, %30, %29
%33 = load i8*, i8** %5
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [72 x i8] c" NL NX NY LOWBAD HIGHBAD THRESH AP1 PH/ADU RNOISE FRAD\00"
@BUFSIZ = global i32 0
@SEEK_SET = global i32 0
define i32 @has_daophot_header(i32* nocapture %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i64 @ftell(i32* %0)
%6 = icmp eq i64 %5, -1
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = tail call i32 @rewind(i32* %0)
%9 = load i32, i32* @BUFSIZ
%10 = call i32 @fgets(i8* %4, i32 %9, i32* %0)
%11 = load i32, i32* @SEEK_SET
%12 = call i32 @fseek(i32* %0, i64 %5, i32 %11)
%13 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i32 71)
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %1, %7
%17 = phi i32 [ %15, %7 ], [ -1, %1 ]
ret i32 %17
}