#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 */
int EXIT_FAILURE;
int EXIT_SUCCESS;
char *calloc(scalar_t__, int);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strlen(char const *);
int sh6_modify_path(char *path) {
  const char *path_old;
  char *path_new;
  path_old = getenv("PATH");
  if ((path_new = calloc(strlen(path_old) + strlen(path) + 2, sizeof(char))) ==
      NULL)
    return EXIT_FAILURE;
  strcat(path_new, path);
  strcat(path_new, ":");
  strcat(path_new, path_old);
  setenv("PATH", path_new, 1);
  free(path_new);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<sh6_modify_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c6 <sh6_modify_path+0x66>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    121a <sh6_modify_path+0xba>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rsi
lea    0xe05(%rip),%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sh6_modify_path>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     11ee <sh6_modify_path+0x8e>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
lea    0xe30(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    0x2dec(%rip),%rax
jmp    11f5 <sh6_modify_path+0x95>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"PATH\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c":\00"
@EXIT_SUCCESS = global i32 0
define i32 @sh6_modify_path(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %8, %10
%12 = add nsw i64 %11, 2
%13 = call i8* @calloc(i64 %12, i32 1)
store i8* %13, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %2
br label %31
17: ; preds = %1
%18 = load i8*, i8** %5
%19 = load i8*, i8** %3
%20 = call i32 @strcat(i8* %18, i8* %19)
%21 = load i8*, i8** %5
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = load i8*, i8** %5
%24 = load i8*, i8** %4
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = load i8*, i8** %5
%27 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %26, i32 1)
%28 = load i8*, i8** %5
%29 = call i32 @free(i8* %28)
%30 = load i32, i32* @EXIT_SUCCESS
store i32 %30, i32* %2
br label %31
31: ; preds = %17, %15
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str = [5 x i8] c"PATH\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c":\00"
@EXIT_SUCCESS = global i32 0
define i32 @sh6_modify_path(i8* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add i64 %3, 2
%6 = add i64 %5, %4
%7 = tail call i8* @calloc(i64 %6, i32 1)
%8 = icmp eq i8* %7, null
br i1 %8, label %15, label %9
9: ; preds = %1
%10 = tail call i32 @strcat(i8* %7, i8* %0)
%11 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @strcat(i8* %7, i8* %2)
%13 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %7, i32 1)
%14 = tail call i32 @free(i8* %7)
br label %15
15: ; preds = %1, %9
%16 = phi i32* [ @EXIT_SUCCESS, %9 ], [ @EXIT_FAILURE, %1 ]
%17 = load i32, i32* %16
ret i32 %17
}