#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 *flu_canopath(char const *);
char *flu_dirname(char const *);
int /*<<< orphan*/ flu_strends(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char *, char *);
char *strrchr(char *, char);
char *flon_path(const char *argv0, const char *dir) {
  if (dir)
    return flu_canopath(dir);
  char *r = NULL;
  char *d = flu_dirname(argv0);
  if (strcmp(d, "bin") == 0) {
    r = flu_canopath(".");
    goto _over;
  }
  if (!flu_strends(d, "/bin")) {
    r = flu_canopath(".");
    goto _over;
  }
  char *s = strrchr(d, '/');
  *s = 0;
  r = flu_canopath(d);
_over:
  free(d);
  return r;
}


x86 assembly (clang, -O0):
<flon_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118d <flon_path+0x2d>
mov    -0x18(%rbp),%rdi
call   1070 <flu_canopath@plt>
mov    %rax,-0x8(%rbp)
jmp    1236 <flon_path+0xd6>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <flu_dirname@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11d1 <flon_path+0x71>
lea    0xe3d(%rip),%rdi
call   1070 <flu_canopath@plt>
mov    %rax,-0x20(%rbp)
jmp    1225 <flon_path+0xc5>
mov    -0x28(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1040 <flu_strends@plt>
cmp    $0x0,%eax
jne    11ff <flon_path+0x9f>
lea    0xe0f(%rip),%rdi
call   1070 <flu_canopath@plt>
mov    %rax,-0x20(%rbp)
jmp    1225 <flon_path+0xc5>
mov    -0x28(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1070 <flu_canopath@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flon_path>:
test   %rsi,%rsi
je     116d <flon_path+0xd>
mov    %rsi,%rdi
jmp    1070 <flu_canopath@plt>
push   %r15
push   %r14
push   %rbx
call   1050 <flu_dirname@plt>
mov    %rax,%r15
lea    0xe82(%rip),%rsi
mov    %rax,%rdi
call   1080 <strcmp@plt>
lea    0xe70(%rip),%r14
test   %rax,%rax
je     11bb <flon_path+0x5b>
lea    0xe66(%rip),%rsi
mov    %r15,%rdi
call   1040 <flu_strends@plt>
test   %eax,%eax
je     11bb <flon_path+0x5b>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
movb   $0x0,(%rax)
mov    %r15,%r14
mov    %r14,%rdi
call   1070 <flu_canopath@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"bin\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [5 x i8] c"/bin\00"
define i8* @flon_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i8* @flu_canopath(i8* %12)
store i8* %13, i8** %3
br label %38
14: ; preds = %2
store i8* null, i8** %6
%15 = load i8*, i8** %4
%16 = call i8* @flu_dirname(i8* %15)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i8* @flu_canopath(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %21, i8** %6
br label %34
22: ; preds = %14
%23 = load i8*, i8** %7
%24 = call i32 @flu_strends(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = call i8* @flu_canopath(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %27, i8** %6
br label %34
28: ; preds = %22
%29 = load i8*, i8** %7
%30 = call i8* @strrchr(i8* %29, i8 signext 47)
store i8* %30, i8** %8
%31 = load i8*, i8** %8
store i8 0, i8* %31
%32 = load i8*, i8** %7
%33 = call i8* @flu_canopath(i8* %32)
store i8* %33, i8** %6
br label %34
34: ; preds = %28, %26, %20
%35 = load i8*, i8** %7
%36 = call i32 @free(i8* %35)
%37 = load i8*, i8** %6
store i8* %37, i8** %3
br label %38
38: ; preds = %34, %11
%39 = load i8*, i8** %3
ret i8* %39
}

LLVM IR (-O2):
@.str = [4 x i8] c"bin\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [5 x i8] c"/bin\00"
define i8* @flon_path(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i8* @flu_canopath(i8* %1)
br label %19
6: ; preds = %2
%7 = tail call i8* @flu_dirname(i8* %0)
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = tail call i32 @flu_strends(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i8* @strrchr(i8* dereferenceable(1) %7, i8 signext 47)
store i8 0, i8* %14
br label %15
15: ; preds = %10, %6, %13
%16 = phi i8* [ %7, %13 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %10 ]
%17 = tail call i8* @flu_canopath(i8* %16)
%18 = tail call i32 @free(i8* %7)
br label %19
19: ; preds = %15, %4
%20 = phi i8* [ %5, %4 ], [ %17, %15 ]
ret i8* %20
}