#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*/ ffpmsg(char const *);
int /*<<< orphan*/ free(char *);
int head_version(char *);
char *irafgetc(char *, int, int);
char *irafgetc2(char *, int, int);
char *same_path(char *, char const *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int getirafpixname(const char *hdrname, char *irafheader, char *pixfilename,
                   int *status) {
  int imhver;
  char *pixname, *newpixname, *bang;
  imhver = head_version(irafheader);
  if (imhver < 1) {
    ffpmsg("File not valid IRAF image header");
    ffpmsg(hdrname);
    return (*status = 104);
  }
  if (imhver == 2)
    pixname = irafgetc(irafheader, 126, 255);
  else
    pixname = irafgetc2(irafheader, 412, 79);
  if (strncmp(pixname, "HDR", 3) == 0) {
    newpixname = same_path(pixname, hdrname);
    if (newpixname) {
      free(pixname);
      pixname = newpixname;
    }
  }
  if (strchr(pixname, '/') == NULL && strchr(pixname, '$') == NULL) {
    newpixname = same_path(pixname, hdrname);
    if (newpixname) {
      free(pixname);
      pixname = newpixname;
    }
  }
  if ((bang = strchr(pixname, '!')) != NULL)
    strcpy(pixfilename, bang + 1);
  else
    strcpy(pixfilename, pixname);
  free(pixname);
  return (*status);
}


x86 assembly (clang, -O0):
<getirafpixname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <head_version@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jge    11e9 <getirafpixname+0x59>
lea    0xe3b(%rip),%rdi
call   1080 <ffpmsg@plt>
mov    -0x10(%rbp),%rdi
call   1080 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x68,(%rax)
movl   $0x68,-0x4(%rbp)
jmp    132a <getirafpixname+0x19a>
cmpl   $0x2,-0x2c(%rbp)
jne    120f <getirafpixname+0x7f>
mov    -0x18(%rbp),%rdi
mov    $0x7e,%esi
mov    $0xff,%edx
call   10b0 <irafgetc@plt>
mov    %rax,-0x38(%rbp)
jmp    1226 <getirafpixname+0x96>
mov    -0x18(%rbp),%rdi
mov    $0x19c,%esi
mov    $0x4f,%edx
call   10a0 <irafgetc2@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xdf0(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1277 <getirafpixname+0xe7>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <same_path@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1272 <getirafpixname+0xe2>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1277 <getirafpixname+0xe7>
mov    -0x38(%rbp),%rdi
mov    $0x2f,%esi
call   1090 <strchr@plt>
cmp    $0x0,%rax
jne    12d9 <getirafpixname+0x149>
mov    -0x38(%rbp),%rdi
mov    $0x24,%esi
call   1090 <strchr@plt>
cmp    $0x0,%rax
jne    12d9 <getirafpixname+0x149>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <same_path@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12d4 <getirafpixname+0x144>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    12d9 <getirafpixname+0x149>
mov    -0x38(%rbp),%rdi
mov    $0x21,%esi
call   1090 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     130b <getirafpixname+0x17b>
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%rsi
add    $0x1,%rsi
call   1050 <strcpy@plt>
jmp    1318 <getirafpixname+0x188>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getirafpixname>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
call   1060 <head_version@plt>
test   %eax,%eax
jle    11ca <getirafpixname+0x3a>
mov    %rbx,%rdi
cmp    $0x2,%eax
jne    11ef <getirafpixname+0x5f>
mov    $0x7e,%esi
mov    $0xff,%edx
call   10b0 <irafgetc@plt>
jmp    11fe <getirafpixname+0x6e>
lea    0xe2f(%rip),%rdi
call   1080 <ffpmsg@plt>
mov    %r12,%rdi
call   1080 <ffpmsg@plt>
movl   $0x68,(%r15)
mov    $0x68,%eax
jmp    12ae <getirafpixname+0x11e>
mov    $0x19c,%esi
mov    $0x4f,%edx
call   10a0 <irafgetc2@plt>
mov    %rax,%rbx
lea    0xe19(%rip),%rsi
mov    %rax,%rdi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1238 <getirafpixname+0xa8>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <same_path@plt>
test   %rax,%rax
je     1238 <getirafpixname+0xa8>
mov    %rax,%r13
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1090 <strchr@plt>
test   %rax,%rax
jne    127a <getirafpixname+0xea>
mov    %rbx,%rdi
mov    $0x24,%esi
call   1090 <strchr@plt>
test   %rax,%rax
jne    127a <getirafpixname+0xea>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <same_path@plt>
test   %rax,%rax
je     127a <getirafpixname+0xea>
mov    %rax,%r12
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rbx
mov    %rbx,%rdi
mov    $0x21,%esi
call   1090 <strchr@plt>
test   %rax,%rax
je     1298 <getirafpixname+0x108>
add    $0x1,%rax
mov    %r14,%rdi
mov    %rax,%rsi
jmp    129e <getirafpixname+0x10e>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%r15),%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"File not valid IRAF image header\00"
@.str.1 = [4 x i8] c"HDR\00"
define i32 @getirafpixname(i8* %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%14 = load i8*, i8** %7
%15 = call i32 @head_version(i8* %14)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %23
18: ; preds = %4
%19 = call i32 @ffpmsg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%20 = load i8*, i8** %6
%21 = call i32 @ffpmsg(i8* %20)
%22 = load i32*, i32** %9
store i32 104, i32* %22
store i32 104, i32* %5
br label %84
23: ; preds = %4
%24 = load i32, i32* %10
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i8*, i8** %7
%28 = call i8* @irafgetc(i8* %27, i32 126, i32 255)
store i8* %28, i8** %11
br label %32
29: ; preds = %23
%30 = load i8*, i8** %7
%31 = call i8* @irafgetc2(i8* %30, i32 412, i32 79)
store i8* %31, i8** %11
br label %32
32: ; preds = %29, %26
%33 = load i8*, i8** %11
%34 = call i64 @strncmp(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %47
36: ; preds = %32
%37 = load i8*, i8** %11
%38 = load i8*, i8** %6
%39 = call i8* @same_path(i8* %37, i8* %38)
store i8* %39, i8** %12
%40 = load i8*, i8** %12
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %46
42: ; preds = %36
%43 = load i8*, i8** %11
%44 = call i32 @free(i8* %43)
%45 = load i8*, i8** %12
store i8* %45, i8** %11
br label %46
46: ; preds = %42, %36
br label %47
47: ; preds = %46, %32
%48 = load i8*, i8** %11
%49 = call i8* @strchr(i8* %48, i8 signext 47)
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %66
51: ; preds = %47
%52 = load i8*, i8** %11
%53 = call i8* @strchr(i8* %52, i8 signext 36)
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %66
55: ; preds = %51
%56 = load i8*, i8** %11
%57 = load i8*, i8** %6
%58 = call i8* @same_path(i8* %56, i8* %57)
store i8* %58, i8** %12
%59 = load i8*, i8** %12
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %65
61: ; preds = %55
%62 = load i8*, i8** %11
%63 = call i32 @free(i8* %62)
%64 = load i8*, i8** %12
store i8* %64, i8** %11
br label %65
65: ; preds = %61, %55
br label %66
66: ; preds = %65, %51, %47
%67 = load i8*, i8** %11
%68 = call i8* @strchr(i8* %67, i8 signext 33)
store i8* %68, i8** %13
%69 = icmp ne i8* %68, null
br i1 %69, label %70, label %75
70: ; preds = %66
%71 = load i8*, i8** %8
%72 = load i8*, i8** %13
%73 = getelementptr inbounds i8, i8* %72, i64 1
%74 = call i32 @strcpy(i8* %71, i8* %73)
br label %79
75: ; preds = %66
%76 = load i8*, i8** %8
%77 = load i8*, i8** %11
%78 = call i32 @strcpy(i8* %76, i8* %77)
br label %79
79: ; preds = %75, %70
%80 = load i8*, i8** %11
%81 = call i32 @free(i8* %80)
%82 = load i32*, i32** %9
%83 = load i32, i32* %82
store i32 %83, i32* %5
br label %84
84: ; preds = %79, %18
%85 = load i32, i32* %5
ret i32 %85
}

LLVM IR (-O2):
@.str = [33 x i8] c"File not valid IRAF image header\00"
@.str.1 = [4 x i8] c"HDR\00"
define i32 @getirafpixname(i8* %0, i8* %1, i8* %2, i32* nocapture %3) {
%5 = tail call i32 @head_version(i8* %1)
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @ffpmsg(i8* %0)
store i32 104, i32* %3
br label %49
10: ; preds = %4
%11 = icmp eq i32 %5, 2
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i8* @irafgetc(i8* %1, i32 126, i32 255)
br label %16
14: ; preds = %10
%15 = tail call i8* @irafgetc2(i8* %1, i32 412, i32 79)
br label %16
16: ; preds = %14, %12
%17 = phi i8* [ %13, %12 ], [ %15, %14 ]
%18 = tail call i64 @strncmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = tail call i8* @same_path(i8* %17, i8* %0)
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @free(i8* %17)
br label %25
25: ; preds = %20, %23, %16
%26 = phi i8* [ %21, %23 ], [ %17, %20 ], [ %17, %16 ]
%27 = tail call i8* @strchr(i8* dereferenceable(1) %26, i8 signext 47)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = tail call i8* @strchr(i8* dereferenceable(1) %26, i8 signext 36)
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = tail call i8* @same_path(i8* %26, i8* %0)
%34 = icmp eq i8* %33, null
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = tail call i32 @free(i8* %26)
br label %37
37: ; preds = %32, %35, %29, %25
%38 = phi i8* [ %33, %35 ], [ %26, %32 ], [ %26, %29 ], [ %26, %25 ]
%39 = tail call i8* @strchr(i8* dereferenceable(1) %38, i8 signext 33)
%40 = icmp eq i8* %39, null
br i1 %40, label %44, label %41
41: ; preds = %37
%42 = getelementptr inbounds i8, i8* %39, i64 1
%43 = tail call i32 @strcpy(i8* %2, i8* %42)
br label %46
44: ; preds = %37
%45 = tail call i32 @strcpy(i8* %2, i8* %38)
br label %46
46: ; preds = %44, %41
%47 = tail call i32 @free(i8* %38)
%48 = load i32, i32* %3
br label %49
49: ; preds = %46, %7
%50 = phi i32 [ 104, %7 ], [ %48, %46 ]
ret i32 %50
}