#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 *env_get(char *);
int /*<<< orphan*/ env_set(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
scalar_t__ strlen(char const *);
void add_to_path(const char *path) {
  const char *old_path;
  char *new_path;
  old_path = env_get("PATH");
  new_path = malloc(strlen(path) + 1 + strlen(old_path) + 1);
  sprintf(new_path, "%s:%s", path, old_path);
  env_set("PATH", new_path);
  free(new_path);
}


x86 assembly (clang, -O0):
<add_to_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8d(%rip),%rdi
call   1070 <env_get@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe48(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe33(%rip),%rdi
call   1060 <env_set@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_to_path>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xe8e(%rip),%r14
mov    %r14,%rdi
call   1070 <env_get@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe5e(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
call   1080 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <env_set@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [6 x i8] c"%s:%s\00"
define void @add_to_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i8* @env_get(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %3
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = add nsw i64 %7, 1
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %8, %10
%12 = add nsw i64 %11, 1
%13 = call i8* @malloc(i64 %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = load i8*, i8** %2
%16 = load i8*, i8** %3
%17 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16)
%18 = load i8*, i8** %4
%19 = call i32 @env_set(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [6 x i8] c"%s:%s\00"
define void @add_to_path(i8* %0) {
%2 = tail call i8* @env_get(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%5 = add i64 %3, 2
%6 = add i64 %5, %4
%7 = tail call i8* @malloc(i64 %6)
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %2)
%9 = tail call i32 @env_set(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %7)
%10 = tail call i32 @free(i8* %7)
ret void
}