#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ ffpmsg(char *);
int /*<<< orphan*/ *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *same_path(char *pixname, const char *hdrname) {
  int len;
  char *newpixname;
  newpixname = (char *)calloc(2 * 255 + 1, sizeof(char));
  if (newpixname == NULL) {
    ffpmsg("iraffits same_path: Cannot alloc memory for newpixname");
    return (NULL);
  }
  if (strncmp(pixname, "HDR$", 4) == 0) {
    (void)strncpy(newpixname, hdrname, 255);
    len = strlen(newpixname);
    while ((len > 0) && (newpixname[len - 1] != '/'))
      len--;
    newpixname[len] = '\0';
    (void)strncat(newpixname, &pixname[4], 255);
  } else if (strchr(pixname, '/') == NULL && strchr(pixname, '$') == NULL) {
    (void)strncpy(newpixname, hdrname, 255);
    len = strlen(newpixname);
    while ((len > 0) && (newpixname[len - 1] != '/'))
      len--;
    newpixname[len] = '\0';
    (void)strncat(newpixname, pixname, 255);
  } else if (strncmp(pixname, "HDR", 3) == 0) {
    (void)strncpy(newpixname, hdrname, 255);
    len = strlen(newpixname);
    newpixname[len - 3] = 'p';
    newpixname[len - 2] = 'i';
    newpixname[len - 1] = 'x';
  }
  return (newpixname);
}


x86 assembly (clang, -O0):
<same_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x1ff,%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b7 <same_path+0x47>
lea    0xe5b(%rip),%rdi
call   1060 <ffpmsg@plt>
movq   $0x0,-0x8(%rbp)
jmp    139c <same_path+0x22c>
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1262 <same_path+0xf2>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x29(%rbp)
jle    121d <same_path+0xad>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    122d <same_path+0xbd>
jmp    123b <same_path+0xcb>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f4 <same_path+0x84>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    $0xff,%edx
call   1080 <strncat@plt>
jmp    1394 <same_path+0x224>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
cmp    $0x0,%rax
jne    131a <same_path+0x1aa>
mov    -0x10(%rbp),%rdi
mov    $0x24,%esi
call   1070 <strchr@plt>
cmp    $0x0,%rax
jne    131a <same_path+0x1aa>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x2a(%rbp)
jle    12d9 <same_path+0x169>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    12e9 <same_path+0x179>
jmp    12f7 <same_path+0x187>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    12b0 <same_path+0x140>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xff,%edx
call   1080 <strncat@plt>
jmp    138f <same_path+0x21f>
mov    -0x10(%rbp),%rdi
lea    0xd17(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    138a <same_path+0x21a>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x70,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x69,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x78,(%rax,%rcx,1)
jmp    138f <same_path+0x21f>
jmp    1394 <same_path+0x224>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<same_path>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x1ff,%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
test   %rax,%rax
je     121c <same_path+0xac>
mov    %rax,%rbx
lea    0xe9a(%rip),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     122c <same_path+0xbc>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
test   %rax,%rax
jne    11d7 <same_path+0x67>
mov    %r14,%rdi
mov    $0x24,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     128b <same_path+0x11b>
lea    0xe5e(%rip),%rsi
mov    %r14,%rdi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1282 <same_path+0x112>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movw   $0x6970,-0x3(%rax,%rbx,1)
movb   $0x78,-0x1(%rax,%rbx,1)
jmp    1282 <same_path+0x112>
lea    0xddd(%rip),%rdi
call   1060 <ffpmsg@plt>
xor    %ebx,%ebx
jmp    1282 <same_path+0x112>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%edx
xor    %ecx,%ecx
test   %eax,%eax
cmovs  %eax,%ecx
nopl   (%rax)
test   %edx,%edx
jle    1267 <same_path+0xf7>
lea    -0x1(%rdx),%rax
cmpb   $0x2f,-0x1(%rbx,%rdx,1)
mov    %rax,%rdx
jne    1250 <same_path+0xe0>
add    $0x1,%eax
mov    %eax,%ecx
movslq %ecx,%rax
movb   $0x0,(%rbx,%rax,1)
add    $0x4,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
call   1080 <strncat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%edx
xor    %ecx,%ecx
test   %eax,%eax
cmovs  %eax,%ecx
nopl   0x0(%rax)
test   %edx,%edx
jle    12c7 <same_path+0x157>
lea    -0x1(%rdx),%rax
cmpb   $0x2f,-0x1(%rbx,%rdx,1)
mov    %rax,%rdx
jne    12b0 <same_path+0x140>
add    $0x1,%eax
mov    %eax,%ecx
movslq %ecx,%rax
movb   $0x0,(%rbx,%rax,1)
jmp    1272 <same_path+0x102>

LLVM IR (-O0):
@.str = [55 x i8] c"iraffits same_path: Cannot alloc memory for newpixname\00"
@.str.1 = [5 x i8] c"HDR$\00"
@.str.2 = [4 x i8] c"HDR\00"
define i8* @same_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = call i64 @calloc(i32 511, i32 1)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @ffpmsg(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %118
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %50
18: ; preds = %14
%19 = load i8*, i8** %7
%20 = load i8*, i8** %5
%21 = call i32 @strncpy(i8* %19, i8* %20, i32 255)
%22 = load i8*, i8** %7
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %6
br label %24
24: ; preds = %38, %18
%25 = load i32, i32* %6
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i8*, i8** %7
%29 = load i32, i32* %6
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 47
br label %36
36: ; preds = %27, %24
%37 = phi i1 [ false, %24 ], [ %35, %27 ]
br i1 %37, label %38, label %41
38: ; preds = %36
%39 = load i32, i32* %6
%40 = add nsw i32 %39, -1
store i32 %40, i32* %6
br label %24
41: ; preds = %36
%42 = load i8*, i8** %7
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = load i8*, i8** %7
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i64 4
%49 = call i32 @strncat(i8* %46, i8* %48, i32 255)
br label %116
50: ; preds = %14
%51 = load i8*, i8** %4
%52 = call i32* @strchr(i8* %51, i8 signext 47)
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %89
54: ; preds = %50
%55 = load i8*, i8** %4
%56 = call i32* @strchr(i8* %55, i8 signext 36)
%57 = icmp eq i32* %56, null
br i1 %57, label %58, label %89
58: ; preds = %54
%59 = load i8*, i8** %7
%60 = load i8*, i8** %5
%61 = call i32 @strncpy(i8* %59, i8* %60, i32 255)
%62 = load i8*, i8** %7
%63 = call i32 @strlen(i8* %62)
store i32 %63, i32* %6
br label %64
64: ; preds = %78, %58
%65 = load i32, i32* %6
%66 = icmp sgt i32 %65, 0
br i1 %66, label %67, label %76
67: ; preds = %64
%68 = load i8*, i8** %7
%69 = load i32, i32* %6
%70 = sub nsw i32 %69, 1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %68, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 47
br label %76
76: ; preds = %67, %64
%77 = phi i1 [ false, %64 ], [ %75, %67 ]
br i1 %77, label %78, label %81
78: ; preds = %76
%79 = load i32, i32* %6
%80 = add nsw i32 %79, -1
store i32 %80, i32* %6
br label %64
81: ; preds = %76
%82 = load i8*, i8** %7
%83 = load i32, i32* %6
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %82, i64 %84
store i8 0, i8* %85
%86 = load i8*, i8** %7
%87 = load i8*, i8** %4
%88 = call i32 @strncat(i8* %86, i8* %87, i32 255)
br label %115
89: ; preds = %54, %50
%90 = load i8*, i8** %4
%91 = call i64 @strncmp(i8* %90, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %114
93: ; preds = %89
%94 = load i8*, i8** %7
%95 = load i8*, i8** %5
%96 = call i32 @strncpy(i8* %94, i8* %95, i32 255)
%97 = load i8*, i8** %7
%98 = call i32 @strlen(i8* %97)
store i32 %98, i32* %6
%99 = load i8*, i8** %7
%100 = load i32, i32* %6
%101 = sub nsw i32 %100, 3
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %99, i64 %102
store i8 112, i8* %103
%104 = load i8*, i8** %7
%105 = load i32, i32* %6
%106 = sub nsw i32 %105, 2
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i8, i8* %104, i64 %107
store i8 105, i8* %108
%109 = load i8*, i8** %7
%110 = load i32, i32* %6
%111 = sub nsw i32 %110, 1
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8, i8* %109, i64 %112
store i8 120, i8* %113
br label %114
114: ; preds = %93, %89
br label %115
115: ; preds = %114, %81
br label %116
116: ; preds = %115, %41
%117 = load i8*, i8** %7
store i8* %117, i8** %3
br label %118
118: ; preds = %116, %12
%119 = load i8*, i8** %3
ret i8* %119
}

LLVM IR (-O2):
@.str = [55 x i8] c"iraffits same_path: Cannot alloc memory for newpixname\00"
@.str.1 = [5 x i8] c"HDR$\00"
@.str.2 = [4 x i8] c"HDR\00"
define i8* @same_path(i8* %0, i8* %1) {
%3 = tail call i64 @calloc(i32 511, i32 1)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
br label %75
8: ; preds = %2
%9 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %33
11: ; preds = %8
%12 = tail call i32 @strncpy(i8* %4, i8* %1, i32 255)
%13 = tail call i32 @strlen(i8* %4)
%14 = zext i32 %13 to i64
%15 = call i32 @llvm.smin.i32(i32 %13, i32 0)
br label %16
16: ; preds = %20, %11
%17 = phi i64 [ %21, %20 ], [ %14, %11 ]
%18 = trunc i64 %17 to i32
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = add nsw i64 %17, -1
%22 = getelementptr inbounds i8, i8* %4, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 47
br i1 %24, label %25, label %16
25: ; preds = %20
%26 = trunc i64 %17 to i32
br label %27
27: ; preds = %16, %25
%28 = phi i32 [ %26, %25 ], [ %15, %16 ]
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %4, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds i8, i8* %0, i64 4
%32 = tail call i32 @strncat(i8* %4, i8* %31, i32 255)
br label %75
33: ; preds = %8
%34 = tail call i32* @strchr(i8* %0, i8 signext 47)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %60
36: ; preds = %33
%37 = tail call i32* @strchr(i8* %0, i8 signext 36)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %60
39: ; preds = %36
%40 = tail call i32 @strncpy(i8* %4, i8* %1, i32 255)
%41 = tail call i32 @strlen(i8* %4)
%42 = zext i32 %41 to i64
%43 = call i32 @llvm.smin.i32(i32 %41, i32 0)
br label %44
44: ; preds = %48, %39
%45 = phi i64 [ %49, %48 ], [ %42, %39 ]
%46 = trunc i64 %45 to i32
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %44
%49 = add nsw i64 %45, -1
%50 = getelementptr inbounds i8, i8* %4, i64 %49
%51 = load i8, i8* %50
%52 = icmp eq i8 %51, 47
br i1 %52, label %53, label %44
53: ; preds = %48
%54 = trunc i64 %45 to i32
br label %55
55: ; preds = %44, %53
%56 = phi i32 [ %54, %53 ], [ %43, %44 ]
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %4, i64 %57
store i8 0, i8* %58
%59 = tail call i32 @strncat(i8* %4, i8* %0, i32 255)
br label %75
60: ; preds = %36, %33
%61 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %75
63: ; preds = %60
%64 = tail call i32 @strncpy(i8* %4, i8* %1, i32 255)
%65 = tail call i32 @strlen(i8* %4)
%66 = add nsw i32 %65, -3
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %4, i64 %67
store i8 112, i8* %68
%69 = add nsw i32 %65, -2
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %4, i64 %70
store i8 105, i8* %71
%72 = add nsw i32 %65, -1
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %4, i64 %73
store i8 120, i8* %74
br label %75
75: ; preds = %27, %60, %63, %55, %6
%76 = phi i8* [ null, %6 ], [ %4, %55 ], [ %4, %63 ], [ %4, %60 ], [ %4, %27 ]
ret i8* %76
}