#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*/ *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *same_path(char *pixname, char *hdrname) {
  int len;
  char *newpixname;
  newpixname = (char *)calloc(255, sizeof(char));
  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,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xff,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    122e <same_path+0xce>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x21(%rbp)
jle    11e9 <same_path+0x89>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11f9 <same_path+0x99>
jmp    1207 <same_path+0xa7>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11c0 <same_path+0x60>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x4,%rsi
mov    $0xff,%edx
call   1070 <strncat@plt>
jmp    1360 <same_path+0x200>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
jne    12e6 <same_path+0x186>
mov    -0x8(%rbp),%rdi
mov    $0x24,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
jne    12e6 <same_path+0x186>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x22(%rbp)
jle    12a5 <same_path+0x145>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    12b5 <same_path+0x155>
jmp    12c3 <same_path+0x163>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    127c <same_path+0x11c>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0xff,%edx
call   1070 <strncat@plt>
jmp    135b <same_path+0x1fb>
mov    -0x8(%rbp),%rdi
lea    0xd14(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1356 <same_path+0x1f6>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x70,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x69,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x78,(%rax,%rcx,1)
jmp    135b <same_path+0x1fb>
jmp    1360 <same_path+0x200>
mov    -0x20(%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    $0xff,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
lea    0xe7c(%rip),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11ff <same_path+0x9f>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
jne    11be <same_path+0x5e>
mov    %r14,%rdi
mov    $0x24,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     125b <same_path+0xfb>
lea    0xe40(%rip),%rsi
mov    %r14,%rdi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1252 <same_path+0xf2>
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    1252 <same_path+0xf2>
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
test   %edx,%edx
jle    1237 <same_path+0xd7>
lea    -0x1(%rdx),%rax
cmpb   $0x2f,-0x1(%rbx,%rdx,1)
mov    %rax,%rdx
jne    1220 <same_path+0xc0>
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   1070 <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    1297 <same_path+0x137>
lea    -0x1(%rdx),%rax
cmpb   $0x2f,-0x1(%rbx,%rdx,1)
mov    %rax,%rdx
jne    1280 <same_path+0x120>
add    $0x1,%eax
mov    %eax,%ecx
movslq %ecx,%rax
movb   $0x0,(%rbx,%rax,1)
jmp    1242 <same_path+0xe2>

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

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