#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(char *);
int /*<<< orphan*/ getenv(char const *);
int /*<<< orphan*/ lt_debugprintf(char *, int, char *, int /*<<< orphan*/,
                                  int /*<<< orphan*/);
char *lt_extend_str(int /*<<< orphan*/, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ lt_setenv(char const *, char *);
int /*<<< orphan*/ nonnull(char const *);
size_t strlen(char *);
void lt_update_exe_path(const char *name, const char *value) {
  lt_debugprintf("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/ikdekker/stage/refs/heads/"
                 "master/lib/cpputest-3.8/.libs/lt-CppUTestTests.c",
                 666,
                 "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
                 nonnull(name), nonnull(value));
  if (name && *name && value && *value) {
    char *new_value = lt_extend_str(getenv(name), value, 0);
    size_t len = strlen(new_value);
    while ((len > 0) && ((new_value[len - 1]) == ':')) {
      new_value[--len] = '\0';
    }
    lt_setenv(name, new_value);
    do {
      if (new_value) {
        free(new_value);
        new_value = 0;
      }
    } while (0);
  }
}


x86 assembly (clang, -O0):
<lt_update_exe_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <nonnull@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <nonnull@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%r8d
lea    0xe5e(%rip),%rdi
mov    $0x29a,%esi
lea    0xef7(%rip),%rdx
call   1080 <lt_debugprintf@plt>
cmpq   $0x0,-0x8(%rbp)
je     1299 <lt_update_exe_path+0x129>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1299 <lt_update_exe_path+0x129>
cmpq   $0x0,-0x10(%rbp)
je     1299 <lt_update_exe_path+0x129>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1299 <lt_update_exe_path+0x129>
mov    -0x8(%rbp),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1090 <lt_extend_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x25(%rbp)
jbe    1239 <lt_update_exe_path+0xc9>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
sete   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1249 <lt_update_exe_path+0xd9>
jmp    1266 <lt_update_exe_path+0xf6>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x20(%rbp)
movb   $0x0,-0x1(%rax,%rcx,1)
jmp    1210 <lt_update_exe_path+0xa0>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <lt_setenv@plt>
cmpq   $0x0,-0x18(%rbp)
je     128f <lt_update_exe_path+0x11f>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
jmp    1294 <lt_update_exe_path+0x124>
jmp    1299 <lt_update_exe_path+0x129>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lt_update_exe_path>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
call   1070 <nonnull@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <nonnull@plt>
lea    0xe70(%rip),%rdi
lea    0xf0e(%rip),%rdx
mov    $0x29a,%esi
mov    %ebp,%ecx
mov    %eax,%r8d
call   1080 <lt_debugprintf@plt>
test   %r14,%r14
je     121b <lt_update_exe_path+0xab>
test   %rbx,%rbx
je     121b <lt_update_exe_path+0xab>
cmpb   $0x0,(%r14)
je     121b <lt_update_exe_path+0xab>
cmpb   $0x0,(%rbx)
je     121b <lt_update_exe_path+0xab>
mov    %r14,%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1090 <lt_extend_str@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
test   %rax,%rax
je     11ff <lt_update_exe_path+0x8f>
nop
cmpb   $0x3a,-0x1(%rbx,%rax,1)
jne    11f2 <lt_update_exe_path+0x82>
movb   $0x0,-0x1(%rbx,%rax,1)
add    $0xffffffffffffffff,%rax
jne    11e0 <lt_update_exe_path+0x70>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <lt_setenv@plt>
jmp    120f <lt_update_exe_path+0x9f>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <lt_setenv@plt>
test   %rbx,%rbx
je     121b <lt_update_exe_path+0xab>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <free@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [165 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ikdekker/stage/refs/heads/master/lib/cpputest-3.8/.libs/lt-CppUTestTests.c\00"
@.str.1 = [56 x i8] c"(lt_update_exe_path) modifying '%s' by prepending '%s'\0A\00"
define void @lt_update_exe_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @nonnull(i8* %7)
%9 = load i8*, i8** %4
%10 = call i32 @nonnull(i8* %9)
%11 = call i32 @lt_debugprintf(i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str, i64 0, i64 0), i32 666, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %10)
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %64
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %64
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %64
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %64
27: ; preds = %22
%28 = load i8*, i8** %3
%29 = call i32 @getenv(i8* %28)
%30 = load i8*, i8** %4
%31 = call i8* @lt_extend_str(i32 %29, i8* %30, i32 0)
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = call i64 @strlen(i8* %32)
store i64 %33, i64* %6
br label %34
34: ; preds = %47, %27
%35 = load i64, i64* %6
%36 = icmp ugt i64 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %34
%38 = load i8*, i8** %5
%39 = load i64, i64* %6
%40 = sub i64 %39, 1
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 58
br label %45
45: ; preds = %37, %34
%46 = phi i1 [ false, %34 ], [ %44, %37 ]
br i1 %46, label %47, label %52
47: ; preds = %45
%48 = load i8*, i8** %5
%49 = load i64, i64* %6
%50 = add i64 %49, -1
store i64 %50, i64* %6
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
br label %34
52: ; preds = %45
%53 = load i8*, i8** %3
%54 = load i8*, i8** %5
%55 = call i32 @lt_setenv(i8* %53, i8* %54)
br label %56
56: ; preds = %52
%57 = load i8*, i8** %5
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i8*, i8** %5
%61 = call i32 @free(i8* %60)
store i8* null, i8** %5
br label %62
62: ; preds = %59, %56
br label %63
63: ; preds = %62
br label %64
64: ; preds = %63, %22, %19, %14, %2
ret void
}

LLVM IR (-O2):
@.str = [165 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ikdekker/stage/refs/heads/master/lib/cpputest-3.8/.libs/lt-CppUTestTests.c\00"
@.str.1 = [56 x i8] c"(lt_update_exe_path) modifying '%s' by prepending '%s'\0A\00"
define void @lt_update_exe_path(i8* %0, i8* %1) {
%3 = tail call i32 @nonnull(i8* %0)
%4 = tail call i32 @nonnull(i8* %1)
%5 = tail call i32 @lt_debugprintf(i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str, i64 0, i64 0), i32 666, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %4)
%6 = icmp eq i8* %0, null
br i1 %6, label %35, label %7
7: ; preds = %2
%8 = load i8, i8* %0
%9 = icmp ne i8 %8, 0
%10 = icmp ne i8* %1, null
%11 = and i1 %10, %9
br i1 %11, label %12, label %35
12: ; preds = %7
%13 = load i8, i8* %1
%14 = icmp eq i8 %13, 0
br i1 %14, label %35, label %15
15: ; preds = %12
%16 = tail call i32 @getenv(i8* %0)
%17 = tail call i8* @lt_extend_str(i32 %16, i8* %1, i32 0)
%18 = tail call i64 @strlen(i8* dereferenceable(1) %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %15, %26
%21 = phi i64 [ %22, %26 ], [ %18, %15 ]
%22 = add i64 %21, -1
%23 = getelementptr inbounds i8, i8* %17, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 58
br i1 %25, label %26, label %31
26: ; preds = %20
store i8 0, i8* %23
%27 = icmp eq i64 %22, 0
br i1 %27, label %31, label %20
28: ; preds = %15
%29 = tail call i32 @lt_setenv(i8* %0, i8* %17)
%30 = icmp eq i8* %17, null
br i1 %30, label %35, label %33
31: ; preds = %26, %20
%32 = tail call i32 @lt_setenv(i8* %0, i8* %17)
br label %33
33: ; preds = %31, %28
%34 = tail call i32 @free(i8* %17)
br label %35
35: ; preds = %28, %33, %12, %7, %2
ret void
}