#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 *append_to_expanded(char *, char *const);
char *enclose_in_dquotes(char const *);
int /*<<< orphan*/ free(char *const);
char *shell_like_escape(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ show_error_msg(char *, char *);
char *append_path_to_expanded(char expanded[], int quotes, const char path[]) {
  if (quotes) {
    const char *const dquoted = enclose_in_dquotes(path);
    expanded = append_to_expanded(expanded, dquoted);
  } else {
    char *const escaped = shell_like_escape(path, 0);
    if (escaped == NULL) {
      show_error_msg("Memory Error", "Unable to allocate enough memory");
      free(expanded);
      return NULL;
    }
    expanded = append_to_expanded(expanded, escaped);
    free(escaped);
  }
  return expanded;
}


x86 assembly (clang, -O0):
<append_path_to_expanded>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1190 <append_path_to_expanded+0x40>
mov    -0x20(%rbp),%rdi
call   1060 <enclose_in_dquotes@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <append_to_expanded@plt>
mov    %rax,-0x10(%rbp)
jmp    11ed <append_path_to_expanded+0x9d>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1070 <shell_like_escape@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d3 <append_path_to_expanded+0x83>
lea    0xe4f(%rip),%rdi
lea    0xe55(%rip),%rsi
call   1040 <show_error_msg@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f5 <append_path_to_expanded+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <append_to_expanded@plt>
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_path_to_expanded>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rdx,%rdi
test   %esi,%esi
je     1175 <append_path_to_expanded+0x25>
call   1060 <enclose_in_dquotes@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <append_to_expanded@plt>
xor    %esi,%esi
call   1070 <shell_like_escape@plt>
test   %rax,%rax
je     119f <append_path_to_expanded+0x4f>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <append_to_expanded@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
jmp    11bc <append_path_to_expanded+0x6c>
lea    0xe5a(%rip),%rdi
lea    0xe60(%rip),%rsi
call   1040 <show_error_msg@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Memory Error\00"
@.str.1 = [33 x i8] c"Unable to allocate enough memory\00"
define i8* @append_path_to_expanded(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i8*, i8** %7
%14 = call i8* @enclose_in_dquotes(i8* %13)
store i8* %14, i8** %8
%15 = load i8*, i8** %5
%16 = load i8*, i8** %8
%17 = call i8* @append_to_expanded(i8* %15, i8* %16)
store i8* %17, i8** %5
br label %33
18: ; preds = %3
%19 = load i8*, i8** %7
%20 = call i8* @shell_like_escape(i8* %19, i32 0)
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = call i32 @show_error_msg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %5
%26 = call i32 @free(i8* %25)
store i8* null, i8** %4
br label %35
27: ; preds = %18
%28 = load i8*, i8** %5
%29 = load i8*, i8** %9
%30 = call i8* @append_to_expanded(i8* %28, i8* %29)
store i8* %30, i8** %5
%31 = load i8*, i8** %9
%32 = call i32 @free(i8* %31)
br label %33
33: ; preds = %27, %12
%34 = load i8*, i8** %5
store i8* %34, i8** %4
br label %35
35: ; preds = %33, %23
%36 = load i8*, i8** %4
ret i8* %36
}

LLVM IR (-O2):
@.str = [13 x i8] c"Memory Error\00"
@.str.1 = [33 x i8] c"Unable to allocate enough memory\00"
define i8* @append_path_to_expanded(i8* %0, i32 %1, i8* %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %8, label %5
5: ; preds = %3
%6 = tail call i8* @enclose_in_dquotes(i8* %2)
%7 = tail call i8* @append_to_expanded(i8* %0, i8* %6)
br label %17
8: ; preds = %3
%9 = tail call i8* @shell_like_escape(i8* %2, i32 0)
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i8* @append_to_expanded(i8* %0, i8* %9)
%13 = tail call i32 @free(i8* %9)
br label %17
14: ; preds = %8
%15 = tail call i32 @show_error_msg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @free(i8* %0)
br label %17
17: ; preds = %5, %11, %14
%18 = phi i8* [ null, %14 ], [ %7, %5 ], [ %12, %11 ]
ret i8* %18
}