#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 */
char *FileConcat(char *, char *);
char *FileDirname(char *);
char *FileTail(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char *, char *);
char *FileSameDirectory(char *file1, char *file2) {
  char *path;
  char *tail;
  char *result;
  int seems_ok = 1;
  path = FileDirname(file1);
  tail = FileTail(file2, 0);
  if (strcmp(file2, tail) != 0)
    seems_ok = 0;
  result = FileConcat(path, tail);
  if (!seems_ok && strcmp(result, file2) != 0) {
    free(result);
    result = NULL;
  }
  free(path);
  free(tail);
  return result;
}


x86 assembly (clang, -O0):
<FileSameDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <FileDirname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1070 <FileTail@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11a1 <FileSameDirectory+0x51>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <FileConcat@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11e4 <FileSameDirectory+0x94>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11e4 <FileSameDirectory+0x94>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileSameDirectory>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r13
call   1060 <FileDirname@plt>
mov    %rax,%r14
mov    %r13,%rdi
xor    %esi,%esi
call   1070 <FileTail@plt>
mov    %rax,%r15
mov    %r13,%rdi
mov    %rax,%rsi
call   1050 <strcmp@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <FileConcat@plt>
mov    %rax,%r12
test   %rbx,%rbx
je     11ad <FileSameDirectory+0x5d>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ad <FileSameDirectory+0x5d>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %r12d,%r12d
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @FileSameDirectory(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 1, i32* %8
%9 = load i8*, i8** %3
%10 = call i8* @FileDirname(i8* %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %4
%12 = call i8* @FileTail(i8* %11, i32 0)
store i8* %12, i8** %6
%13 = load i8*, i8** %4
%14 = load i8*, i8** %6
%15 = call i64 @strcmp(i8* %13, i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 0, i32* %8
br label %18
18: ; preds = %17, %2
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = call i8* @FileConcat(i8* %19, i8* %20)
store i8* %21, i8** %7
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 0
br i1 %23, label %32, label %24
24: ; preds = %18
%25 = load i8*, i8** %7
%26 = load i8*, i8** %4
%27 = call i64 @strcmp(i8* %25, i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i8*, i8** %7
%31 = call i32 @free(i8* %30)
store i8* null, i8** %7
br label %32
32: ; preds = %29, %24, %18
%33 = load i8*, i8** %5
%34 = call i32 @free(i8* %33)
%35 = load i8*, i8** %6
%36 = call i32 @free(i8* %35)
%37 = load i8*, i8** %7
ret i8* %37
}

LLVM IR (-O2):
define i8* @FileSameDirectory(i8* %0, i8* %1) {
%3 = tail call i8* @FileDirname(i8* %0)
%4 = tail call i8* @FileTail(i8* %1, i32 0)
%5 = tail call i64 @strcmp(i8* %1, i8* %4)
%6 = icmp eq i64 %5, 0
%7 = tail call i8* @FileConcat(i8* %3, i8* %4)
br i1 %6, label %13, label %8
8: ; preds = %2
%9 = tail call i64 @strcmp(i8* %7, i8* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @free(i8* %7)
br label %13
13: ; preds = %11, %8, %2
%14 = phi i8* [ %7, %2 ], [ null, %11 ], [ %7, %8 ]
%15 = tail call i32 @free(i8* %3)
%16 = tail call i32 @free(i8* %4)
ret i8* %14
}