#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 */
struct pane {
  int dummy;
};

/* Variables and functions */
char const *__strconcat(struct pane *, char *, char const *, char const *, ...);
char *getenv(char *);
char *pane_attr_get(struct pane *, char *);
int strlen(char *);
scalar_t__ strncmp(char const *, char const *, int);
const char *file_normalize(struct pane *p, const char *path,
                           const char *initial_path) {
  int len = strlen(initial_path ?: "");
  char *dir;
  if (!path)
    return ".";
  if (initial_path && strncmp(path, initial_path, len) == 0) {
    if (path[len] == '/' ||
        (path[len] == '~' && (path[len + 1] == '/' || path[len + 1] == 0)))
      path = path + len;
  }
  if (path[0] == '/')
    return path;
  if (path[0] == '~' && (path[1] == '/' || path[1] == 0)) {
    char *home = getenv("HOME");
    if (!home)
      home = "/";
    if (home[strlen(home) - 1] == '/' && path[1] == '/')
      path += 1;
    return __strconcat(p, home, path + 1, NULL);
  }
  dir = pane_attr_get(p, "dirname");
  if (!dir)
    dir = "/";
  if (dir[strlen(dir) - 1] == '/')
    return __strconcat(p, dir, path, NULL);
  return __strconcat(p, dir, "/", path, NULL);
}


x86 assembly (clang, -O0):
<file_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     1183 <file_normalize+0x33>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1193 <file_normalize+0x43>
lea    0xe77(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    1193 <file_normalize+0x43>
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ba <file_normalize+0x6a>
lea    0xe4f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13c8 <file_normalize+0x278>
cmpq   $0x0,-0x20(%rbp)
je     1251 <file_normalize+0x101>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1251 <file_normalize+0x101>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     123d <file_normalize+0xed>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jne    124c <file_normalize+0xfc>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     123d <file_normalize+0xed>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    124c <file_normalize+0xfc>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1251 <file_normalize+0x101>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    126e <file_normalize+0x11e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13c8 <file_normalize+0x278>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    1331 <file_normalize+0x1e1>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
je     12a0 <file_normalize+0x150>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1331 <file_normalize+0x1e1>
lea    0xd5b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12c6 <file_normalize+0x176>
lea    0xd45(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    130d <file_normalize+0x1bd>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    130d <file_normalize+0x1bd>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x0,%al
call   1070 <__strconcat@plt>
mov    %rax,-0x8(%rbp)
jmp    13c8 <file_normalize+0x278>
mov    -0x10(%rbp),%rdi
lea    0xccd(%rip),%rsi
call   1060 <pane_attr_get@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    135b <file_normalize+0x20b>
lea    0xcb0(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    13a5 <file_normalize+0x255>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x0,%al
call   1070 <__strconcat@plt>
mov    %rax,-0x8(%rbp)
jmp    13c8 <file_normalize+0x278>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xc4f(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1070 <__strconcat@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_normalize>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r14
test   %rdx,%rdx
lea    0xe96(%rip),%rdi
cmovne %rdx,%rdi
call   1050 <strlen@plt>
test   %r12,%r12
je     1218 <file_normalize+0xc8>
test   %rbx,%rbx
je     11b8 <file_normalize+0x68>
mov    %eax,%ebp
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11b8 <file_normalize+0x68>
movslq %ebp,%rax
mov    (%r12,%rax,1),%cl
cmp    $0x2f,%cl
je     11b5 <file_normalize+0x65>
cmp    $0x7e,%cl
jne    11b8 <file_normalize+0x68>
mov    0x1(%rax,%r12,1),%cl
cmp    $0x2f,%cl
je     11b5 <file_normalize+0x65>
test   %cl,%cl
jne    11b8 <file_normalize+0x68>
add    %rax,%r12
mov    (%r12),%al
cmp    $0x2f,%al
je     121f <file_normalize+0xcf>
cmp    $0x7e,%al
jne    122b <file_normalize+0xdb>
mov    0x1(%r12),%al
cmp    $0x2f,%al
je     11d1 <file_normalize+0x81>
test   %al,%al
jne    122b <file_normalize+0xdb>
lea    0xe2a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe20(%rip),%r15
cmovne %rax,%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r15,1)
jne    120c <file_normalize+0xbc>
lea    0x1(%r12),%rax
cmpb   $0x2f,0x1(%r12)
cmove  %rax,%r12
add    $0x1,%r12
mov    %r14,%rdi
mov    %r15,%rsi
jmp    125f <file_normalize+0x10f>
lea    0xde1(%rip),%r12
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd7(%rip),%rsi
mov    %r14,%rdi
call   1060 <pane_attr_get@plt>
test   %rax,%rax
lea    0xdc3(%rip),%rbx
cmovne %rax,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1273 <file_normalize+0x123>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <__strconcat@plt>
lea    0xd8d(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <__strconcat@plt>

LLVM IR (-O0):
%struct.pane = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c".\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [8 x i8] c"dirname\00"
define i8* @file_normalize(%struct.pane* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca %struct.pane*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store %struct.pane* %0, %struct.pane** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
br label %15
14: ; preds = %3
br label %15
15: ; preds = %14, %13
%16 = phi i8* [ %11, %13 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %14 ]
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %8
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %15
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %152
21: ; preds = %15
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %70
24: ; preds = %21
%25 = load i8*, i8** %6
%26 = load i8*, i8** %7
%27 = load i32, i32* %8
%28 = call i64 @strncmp(i8* %25, i8* %26, i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %70
30: ; preds = %24
%31 = load i8*, i8** %6
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 47
br i1 %37, label %64, label %38
38: ; preds = %30
%39 = load i8*, i8** %6
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 126
br i1 %45, label %46, label %69
46: ; preds = %38
%47 = load i8*, i8** %6
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 47
br i1 %54, label %64, label %55
55: ; preds = %46
%56 = load i8*, i8** %6
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %56, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %69
64: ; preds = %55, %46, %30
%65 = load i8*, i8** %6
%66 = load i32, i32* %8
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
store i8* %68, i8** %6
br label %69
69: ; preds = %64, %55, %38
br label %70
70: ; preds = %69, %24, %21
%71 = load i8*, i8** %6
%72 = getelementptr inbounds i8, i8* %71, i64 0
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 47
br i1 %75, label %76, label %78
76: ; preds = %70
%77 = load i8*, i8** %6
store i8* %77, i8** %4
br label %152
78: ; preds = %70
%79 = load i8*, i8** %6
%80 = getelementptr inbounds i8, i8* %79, i64 0
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp eq i32 %82, 126
br i1 %83, label %84, label %126
84: ; preds = %78
%85 = load i8*, i8** %6
%86 = getelementptr inbounds i8, i8* %85, i64 1
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = icmp eq i32 %88, 47
br i1 %89, label %96, label %90
90: ; preds = %84
%91 = load i8*, i8** %6
%92 = getelementptr inbounds i8, i8* %91, i64 1
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = icmp eq i32 %94, 0
br i1 %95, label %96, label %126
96: ; preds = %90, %84
%97 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %97, i8** %10
%98 = load i8*, i8** %10
%99 = icmp ne i8* %98, null
br i1 %99, label %101, label %100
100: ; preds = %96
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %10
br label %101
101: ; preds = %100, %96
%102 = load i8*, i8** %10
%103 = load i8*, i8** %10
%104 = call i32 @strlen(i8* %103)
%105 = sub nsw i32 %104, 1
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i8, i8* %102, i64 %106
%108 = load i8, i8* %107
%109 = sext i8 %108 to i32
%110 = icmp eq i32 %109, 47
br i1 %110, label %111, label %120
111: ; preds = %101
%112 = load i8*, i8** %6
%113 = getelementptr inbounds i8, i8* %112, i64 1
%114 = load i8, i8* %113
%115 = sext i8 %114 to i32
%116 = icmp eq i32 %115, 47
br i1 %116, label %117, label %120
117: ; preds = %111
%118 = load i8*, i8** %6
%119 = getelementptr inbounds i8, i8* %118, i64 1
store i8* %119, i8** %6
br label %120
120: ; preds = %117, %111, %101
%121 = load %struct.pane*, %struct.pane** %5
%122 = load i8*, i8** %10
%123 = load i8*, i8** %6
%124 = getelementptr inbounds i8, i8* %123, i64 1
%125 = call i8* (%struct.pane*, i8*, i8*, i8*, ...) @__strconcat(%struct.pane* %121, i8* %122, i8* %124, i8* null)
store i8* %125, i8** %4
br label %152
126: ; preds = %90, %78
%127 = load %struct.pane*, %struct.pane** %5
%128 = call i8* @pane_attr_get(%struct.pane* %127, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i8* %128, i8** %9
%129 = load i8*, i8** %9
%130 = icmp ne i8* %129, null
br i1 %130, label %132, label %131
131: ; preds = %126
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %132
132: ; preds = %131, %126
%133 = load i8*, i8** %9
%134 = load i8*, i8** %9
%135 = call i32 @strlen(i8* %134)
%136 = sub nsw i32 %135, 1
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds i8, i8* %133, i64 %137
%139 = load i8, i8* %138
%140 = sext i8 %139 to i32
%141 = icmp eq i32 %140, 47
br i1 %141, label %142, label %147
142: ; preds = %132
%143 = load %struct.pane*, %struct.pane** %5
%144 = load i8*, i8** %9
%145 = load i8*, i8** %6
%146 = call i8* (%struct.pane*, i8*, i8*, i8*, ...) @__strconcat(%struct.pane* %143, i8* %144, i8* %145, i8* null)
store i8* %146, i8** %4
br label %152
147: ; preds = %132
%148 = load %struct.pane*, %struct.pane** %5
%149 = load i8*, i8** %9
%150 = load i8*, i8** %6
%151 = call i8* (%struct.pane*, i8*, i8*, i8*, ...) @__strconcat(%struct.pane* %148, i8* %149, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %150, i8* null)
store i8* %151, i8** %4
br label %152
152: ; preds = %147, %142, %120, %76, %20
%153 = load i8*, i8** %4
ret i8* %153
}

LLVM IR (-O2):
%struct.pane = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c".\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [8 x i8] c"dirname\00"
define i8* @file_normalize(%struct.pane* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %2, null
%5 = select i1 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %2
%6 = tail call i32 @strlen(i8* %5)
%7 = icmp eq i8* %1, null
br i1 %7, label %60, label %8
8: ; preds = %3
br i1 %4, label %22, label %9
9: ; preds = %8
%10 = tail call i64 @strncmp(i8* %1, i8* %2, i32 %6)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = sext i32 %6 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = load i8, i8* %14
switch i8 %15, label %22 [
i8 47, label %21
i8 126, label %16
]
16: ; preds = %12
%17 = add nsw i32 %6, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
switch i8 %20, label %22 [
i8 47, label %21
i8 0, label %21
]
21: ; preds = %16, %16, %12
br label %22
22: ; preds = %16, %12, %21, %9, %8
%23 = phi i8* [ %14, %21 ], [ %1, %9 ], [ %1, %8 ], [ %1, %12 ], [ %1, %16 ]
%24 = load i8, i8* %23
switch i8 %24, label %46 [
i8 47, label %60
i8 126, label %25
]
25: ; preds = %22
%26 = getelementptr inbounds i8, i8* %23, i64 1
%27 = load i8, i8* %26
switch i8 %27, label %46 [
i8 47, label %28
i8 0, label %28
]
28: ; preds = %25, %25
%29 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i8* %29, null
%31 = select i1 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %29
%32 = tail call i32 @strlen(i8* %31)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 47
br i1 %37, label %38, label %42
38: ; preds = %28
%39 = load i8, i8* %26
%40 = icmp eq i8 %39, 47
%41 = select i1 %40, i8* %26, i8* %23
br label %42
42: ; preds = %38, %28
%43 = phi i8* [ %23, %28 ], [ %41, %38 ]
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = tail call i8* (%struct.pane*, i8*, i8*, i8*, ...) @__strconcat(%struct.pane* %0, i8* %31, i8* %44, i8* null)
br label %60
46: ; preds = %25, %22
%47 = tail call i8* @pane_attr_get(%struct.pane* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%48 = icmp eq i8* %47, null
%49 = select i1 %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %47
%50 = tail call i32 @strlen(i8* %49)
%51 = add nsw i32 %50, -1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
%54 = load i8, i8* %53
%55 = icmp eq i8 %54, 47
br i1 %55, label %56, label %58
56: ; preds = %46
%57 = tail call i8* (%struct.pane*, i8*, i8*, i8*, ...) @__strconcat(%struct.pane* %0, i8* %49, i8* %23, i8* null)
br label %60
58: ; preds = %46
%59 = tail call i8* (%struct.pane*, i8*, i8*, i8*, ...) @__strconcat(%struct.pane* %0, i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %23, i8* null)
br label %60
60: ; preds = %22, %3, %58, %56, %42
%61 = phi i8* [ %45, %42 ], [ %57, %56 ], [ %59, %58 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %3 ], [ %23, %22 ]
ret i8* %61
}