#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 *change_path(char *, char const *, char const *, int);
char *strchr(char *, char);
void change_env_vars(char **environ, const char *old_dir, const char *new_dir) {
  for (char **env = environ; *env; ++env) {
    const char *equals = strchr(*env, '=');
    if (equals) {
      *env = change_path(*env, old_dir, new_dir, equals - *env + 1);
    }
  }
}


x86 assembly (clang, -O0):
<change_env_vars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11b2 <change_env_vars+0x92>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     119c <change_env_vars+0x7c>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%ecx
call   1040 <change_path@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    11a1 <change_env_vars+0x81>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    113c <change_env_vars+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_env_vars>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%r12
test   %r12,%r12
je     117a <change_env_vars+0x5a>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
add    $0x8,%rbx
jmp    114c <change_env_vars+0x2c>
nop
mov    (%rbx),%r12
add    $0x8,%rbx
test   %r12,%r12
je     117a <change_env_vars+0x5a>
mov    %r12,%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1140 <change_env_vars+0x20>
sub    %r12d,%eax
add    $0x1,%eax
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %eax,%ecx
call   1040 <change_path@plt>
mov    %rax,-0x8(%rbx)
jmp    1140 <change_env_vars+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @change_env_vars(i8** %0, i8* %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8**, i8*** %4
store i8** %9, i8*** %7
br label %10
10: ; preds = %36, %3
%11 = load i8**, i8*** %7
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %39
14: ; preds = %10
%15 = load i8**, i8*** %7
%16 = load i8*, i8** %15
%17 = call i8* @strchr(i8* %16, i8 signext 61)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %35
20: ; preds = %14
%21 = load i8**, i8*** %7
%22 = load i8*, i8** %21
%23 = load i8*, i8** %5
%24 = load i8*, i8** %6
%25 = load i8*, i8** %8
%26 = load i8**, i8*** %7
%27 = load i8*, i8** %26
%28 = ptrtoint i8* %25 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = add nsw i64 %30, 1
%32 = trunc i64 %31 to i32
%33 = call i8* @change_path(i8* %22, i8* %23, i8* %24, i32 %32)
%34 = load i8**, i8*** %7
store i8* %33, i8** %34
br label %35
35: ; preds = %20, %14
br label %36
36: ; preds = %35
%37 = load i8**, i8*** %7
%38 = getelementptr inbounds i8*, i8** %37, i32 1
store i8** %38, i8*** %7
br label %10
39: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @change_env_vars(i8** nocapture %0, i8* %1, i8* %2) {
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %19, %3
ret void
7: ; preds = %3, %19
%8 = phi i8* [ %21, %19 ], [ %4, %3 ]
%9 = phi i8** [ %20, %19 ], [ %0, %3 ]
%10 = tail call i8* @strchr(i8* %8, i8 signext 61)
%11 = icmp eq i8* %10, null
br i1 %11, label %19, label %12
12: ; preds = %7
%13 = ptrtoint i8* %10 to i64
%14 = ptrtoint i8* %8 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = add i32 %16, 1
%18 = tail call i8* @change_path(i8* %8, i8* %1, i8* %2, i32 %17)
store i8* %18, i8** %9
br label %19
19: ; preds = %12, %7
%20 = getelementptr inbounds i8*, i8** %9, i64 1
%21 = load i8*, i8** %20
%22 = icmp eq i8* %21, null
br i1 %22, label %6, label %7
}