#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__ emalloc(scalar_t__);
char *get_libexec();
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
scalar_t__ strlen(char *);
char *get_env_path_with_libexecdir(void) {
  char *pathbuf;
  char *path = getenv("PATH");
  char *execdir = get_libexec();
  if (!path)
    return execdir;
  pathbuf = (char *)emalloc(strlen(path) + strlen(execdir) + strlen(":") + 1);
  sprintf(pathbuf, "%s%s%s", path, ":", execdir);
  return pathbuf;
}


x86 assembly (clang, -O0):
<get_env_path_with_libexecdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <get_libexec@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118b <get_env_path_with_libexecdir+0x3b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f6 <get_env_path_with_libexecdir+0xa6>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
lea    0xe4f(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <emalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%r8
lea    0xe25(%rip),%rsi
lea    0xe1c(%rip),%rcx
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_env_path_with_libexecdir>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <get_libexec@plt>
mov    %rax,%rbx
test   %r14,%r14
je     11b5 <get_env_path_with_libexecdir+0x65>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x2,%rdi
call   1060 <emalloc@plt>
mov    %rax,%r15
lea    0xe6a(%rip),%rsi
lea    0xe61(%rip),%rcx
mov    %rax,%rdi
mov    %r14,%rdx
mov    %rbx,%r8
call   1070 <sprintf@plt>
mov    %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [7 x i8] c"%s%s%s\00"
define i8* @get_env_path_with_libexecdir() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %3
%6 = call i8* (...) @get_libexec()
store i8* %6, i8** %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = load i8*, i8** %4
store i8* %10, i8** %1
br label %27
11: ; preds = %0
%12 = load i8*, i8** %3
%13 = call i64 @strlen(i8* %12)
%14 = load i8*, i8** %4
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %13, %15
%17 = call i64 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = add nsw i64 %16, %17
%19 = add nsw i64 %18, 1
%20 = call i64 @emalloc(i64 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %2
%22 = load i8*, i8** %2
%23 = load i8*, i8** %3
%24 = load i8*, i8** %4
%25 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %2
store i8* %26, i8** %1
br label %27
27: ; preds = %11, %9
%28 = load i8*, i8** %1
ret i8* %28
}

LLVM IR (-O2):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [7 x i8] c"%s%s%s\00"
define i8* @get_env_path_with_libexecdir() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* (...) @get_libexec()
%3 = icmp eq i8* %1, null
br i1 %3, label %12, label %4
4: ; preds = %0
%5 = tail call i64 @strlen(i8* %1)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%7 = add i64 %5, 2
%8 = add i64 %7, %6
%9 = tail call i64 @emalloc(i64 %8)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %12
12: ; preds = %0, %4
%13 = phi i8* [ %10, %4 ], [ %2, %0 ]
ret i8* %13
}