#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 *basename(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ is_null_or_empty(char const *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ portable_snprintf(char *, size_t, char const *, char const *,
                                     char *, char *, char const *);
char *strdup(char const *);
size_t strlen(char const *);
char *get_standard_path(char *path, const char *dir, const char *ext,
                        const char *name) {
  static const char *format = "%s%s%s.%s";
  static const char *ex = ".exe";
  static char a[] = " ";
  size_t n, m;
  char *s, *p;
  const char *q;
  s = strdup(name);
  p = basename(s);
  q = dir;
  if (path)
    n = 0x100;
  else {
    n = strlen(format) + strlen(q) + strlen(p) + strlen(ext);
    path = (char *)malloc(n);
  }
  a[0] = is_null_or_empty(q) ? '\0' : '/';
  portable_snprintf(path, n, format, q, a, p, ext);
  free(s);
  return path;
}


x86 assembly (clang, -O0):
<get_standard_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <basename@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11c2 <get_standard_path+0x52>
movq   $0x100,-0x28(%rbp)
jmp    1224 <get_standard_path+0xb4>
mov    0x2e8f(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x60(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x48(%rbp),%rdi
call   1090 <is_null_or_empty@plt>
mov    %rax,%rdx
mov    $0x2f,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %al,0x2e24(%rip)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2e05(%rip),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r9
mov    -0x18(%rbp),%rax
lea    0x2e02(%rip),%r8
mov    %rax,(%rsp)
call   1060 <portable_snprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_standard_path>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbx
mov    %rcx,%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <basename@plt>
mov    %rax,%r12
mov    $0x100,%ebp
test   %rbx,%rbx
jne    11d7 <get_standard_path+0x67>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
add    %rbx,%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %rax,%rbp
add    $0x9,%rbp
mov    %rbp,%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1090 <is_null_or_empty@plt>
xor    %ecx,%ecx
test   %rax,%rax
mov    $0x2f,%eax
cmovne %ecx,%eax
mov    %al,0x2e66(%rip)
lea    0x2e5f(%rip),%r8
mov    %r15,(%rsp)
lea    0xdfc(%rip),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13,%rcx
mov    %r12,%r9
call   1060 <portable_snprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@get_standard_path.format = internal global i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0)
@.str = [10 x i8] c"%s%s%s.%s\00"
@get_standard_path.ex = internal global i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0)
@.str.1 = [5 x i8] c".exe\00"
@get_standard_path.a = internal global [2 x i8] c" \00"
define i8* @get_standard_path(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%14 = load i8*, i8** %8
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %11
%16 = load i8*, i8** %11
%17 = call i8* @basename(i8* %16)
store i8* %17, i8** %12
%18 = load i8*, i8** %6
store i8* %18, i8** %13
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %4
store i64 256, i64* %9
br label %37
22: ; preds = %4
%23 = load i8*, i8** @get_standard_path.format
%24 = call i64 @strlen(i8* %23)
%25 = load i8*, i8** %13
%26 = call i64 @strlen(i8* %25)
%27 = add i64 %24, %26
%28 = load i8*, i8** %12
%29 = call i64 @strlen(i8* %28)
%30 = add i64 %27, %29
%31 = load i8*, i8** %7
%32 = call i64 @strlen(i8* %31)
%33 = add i64 %30, %32
store i64 %33, i64* %9
%34 = load i64, i64* %9
%35 = call i64 @malloc(i64 %34)
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %5
br label %37
37: ; preds = %22, %21
%38 = load i8*, i8** %13
%39 = call i64 @is_null_or_empty(i8* %38)
%40 = icmp ne i64 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 0, i32 47
%43 = trunc i32 %42 to i8
store i8 %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @get_standard_path.a, i64 0, i64 0)
%44 = load i8*, i8** %5
%45 = load i64, i64* %9
%46 = load i8*, i8** @get_standard_path.format
%47 = load i8*, i8** %13
%48 = load i8*, i8** %12
%49 = load i8*, i8** %7
%50 = call i32 @portable_snprintf(i8* %44, i64 %45, i8* %46, i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @get_standard_path.a, i64 0, i64 0), i8* %48, i8* %49)
%51 = load i8*, i8** %11
%52 = call i32 @free(i8* %51)
%53 = load i8*, i8** %5
ret i8* %53
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s%s%s.%s\00"
@get_standard_path.a = internal global [2 x i8] c" \00"
define i8* @get_standard_path(i8* %0, i8* %1, i8* %2, i8* nocapture %3) {
%5 = tail call i8* @strdup(i8* %3)
%6 = tail call i8* @basename(i8* %5)
%7 = icmp eq i8* %0, null
br i1 %7, label %8, label %17
8: ; preds = %4
%9 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%10 = add i64 %9, 9
%11 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%12 = add i64 %10, %11
%13 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%14 = add i64 %12, %13
%15 = tail call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
br label %17
17: ; preds = %4, %8
%18 = phi i64 [ %14, %8 ], [ 256, %4 ]
%19 = phi i8* [ %16, %8 ], [ %0, %4 ]
%20 = tail call i64 @is_null_or_empty(i8* %1)
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i8 47, i8 0
store i8 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @get_standard_path.a, i64 0, i64 0)
%23 = tail call i32 @portable_snprintf(i8* %19, i64 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @get_standard_path.a, i64 0, i64 0), i8* %6, i8* %2)
%24 = tail call i32 @free(i8* %5)
ret i8* %19
}