#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 /*<<< orphan*/ free(void *);
int /*<<< orphan*/ getenv(char const *);
char *lt_extend_str(int /*<<< orphan*/, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ lt_setenv(char const *, char *);
int strlen(char *);
void lt_update_exe_path(const char *name, const char *value) {

  ;
  if (name && *name && value && *value) {
    char *new_value = lt_extend_str(getenv(name), value, 0);
    int len = strlen(new_value);
    while (((len = strlen(new_value)) > 0) && ((new_value[len - 1]) == ':')) {
      new_value[len - 1] = '\0';
    }
    lt_setenv(name, new_value);
    do {
      if (new_value) {
        free((void *)new_value);
        new_value = 0;
      }
    } while (0);
  }
}


x86 assembly (clang, -O0):
<lt_update_exe_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     124b <lt_update_exe_path+0xfb>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     124b <lt_update_exe_path+0xfb>
cmpq   $0x0,-0x10(%rbp)
je     124b <lt_update_exe_path+0xfb>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     124b <lt_update_exe_path+0xfb>
mov    -0x8(%rbp),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1070 <lt_extend_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
jle    11f2 <lt_update_exe_path+0xa2>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1202 <lt_update_exe_path+0xb2>
jmp    1218 <lt_update_exe_path+0xc8>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11bc <lt_update_exe_path+0x6c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <lt_setenv@plt>
cmpq   $0x0,-0x18(%rbp)
je     1241 <lt_update_exe_path+0xf1>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
jmp    1246 <lt_update_exe_path+0xf6>
jmp    124b <lt_update_exe_path+0xfb>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lt_update_exe_path>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11f5 <lt_update_exe_path+0xa5>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11f5 <lt_update_exe_path+0xa5>
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
je     11f5 <lt_update_exe_path+0xa5>
cmpb   $0x0,(%rbx)
je     11f5 <lt_update_exe_path+0xa5>
mov    %r14,%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1070 <lt_extend_str@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    11d6 <lt_update_exe_path+0x86>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xffffffff,%eax
cmpb   $0x3a,(%rbx,%rax,1)
jne    11c9 <lt_update_exe_path+0x79>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jg     11b0 <lt_update_exe_path+0x60>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <lt_setenv@plt>
jmp    11e6 <lt_update_exe_path+0x96>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <lt_setenv@plt>
test   %rbx,%rbx
je     11f5 <lt_update_exe_path+0xa5>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @lt_update_exe_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %62
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %62
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %62
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %62
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = call i32 @getenv(i8* %23)
%25 = load i8*, i8** %4
%26 = call i8* @lt_extend_str(i32 %24, i8* %25, i32 0)
store i8* %26, i8** %5
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %6
br label %29
29: ; preds = %44, %22
%30 = load i8*, i8** %5
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %6
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = load i8*, i8** %5
%35 = load i32, i32* %6
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 58
br label %42
42: ; preds = %33, %29
%43 = phi i1 [ false, %29 ], [ %41, %33 ]
br i1 %43, label %44, label %50
44: ; preds = %42
%45 = load i8*, i8** %5
%46 = load i32, i32* %6
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
store i8 0, i8* %49
br label %29
50: ; preds = %42
%51 = load i8*, i8** %3
%52 = load i8*, i8** %5
%53 = call i32 @lt_setenv(i8* %51, i8* %52)
br label %54
54: ; preds = %50
%55 = load i8*, i8** %5
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = load i8*, i8** %5
%59 = call i32 @free(i8* %58)
store i8* null, i8** %5
br label %60
60: ; preds = %57, %54
br label %61
61: ; preds = %60
br label %62
62: ; preds = %61, %17, %14, %9, %2
ret void
}

LLVM IR (-O2):
define void @lt_update_exe_path(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %35, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp ne i8 %5, 0
%7 = icmp ne i8* %1, null
%8 = and i1 %7, %6
br i1 %8, label %9, label %35
9: ; preds = %4
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 0
br i1 %11, label %35, label %12
12: ; preds = %9
%13 = tail call i32 @getenv(i8* %0)
%14 = tail call i8* @lt_extend_str(i32 %13, i8* %1, i32 0)
%15 = tail call i32 @strlen(i8* %14)
%16 = tail call i32 @strlen(i8* %14)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %12, %25
%19 = phi i32 [ %26, %25 ], [ %16, %12 ]
%20 = add nsw i32 %19, -1
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %14, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 58
br i1 %24, label %25, label %31
25: ; preds = %18
store i8 0, i8* %22
%26 = tail call i32 @strlen(i8* %14)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %18, label %31
28: ; preds = %12
%29 = tail call i32 @lt_setenv(i8* %0, i8* %14)
%30 = icmp eq i8* %14, null
br i1 %30, label %35, label %33
31: ; preds = %25, %18
%32 = tail call i32 @lt_setenv(i8* %0, i8* %14)
br label %33
33: ; preds = %31, %28
%34 = tail call i32 @free(i8* %14)
br label %35
35: ; preds = %28, %33, %9, %4, %2
ret void
}