#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 *);
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 *);
int 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/paulcdejean/AeonTick/refs/"
                 "heads/master/libtermkey-0.17/.libs/lt-demo-glib.c",
                 663,
                 "(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);
    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    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <nonnull@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <nonnull@plt>
mov    -0x20(%rbp),%ecx
mov    %eax,%r8d
lea    0xe5e(%rip),%rdi
mov    $0x297,%esi
lea    0xef8(%rip),%rdx
call   1080 <lt_debugprintf@plt>
cmpq   $0x0,-0x8(%rbp)
je     129e <lt_update_exe_path+0x12e>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     129e <lt_update_exe_path+0x12e>
cmpq   $0x0,-0x10(%rbp)
je     129e <lt_update_exe_path+0x12e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     129e <lt_update_exe_path+0x12e>
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    %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,-0x21(%rbp)
jle    1245 <lt_update_exe_path+0xd5>
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,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1255 <lt_update_exe_path+0xe5>
jmp    126b <lt_update_exe_path+0xfb>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    120f <lt_update_exe_path+0x9f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <lt_setenv@plt>
cmpq   $0x0,-0x18(%rbp)
je     1294 <lt_update_exe_path+0x124>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
jmp    1299 <lt_update_exe_path+0x129>
jmp    129e <lt_update_exe_path+0x12e>
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    0xf0f(%rip),%rdx
mov    $0x297,%esi
mov    %ebp,%ecx
mov    %eax,%r8d
call   1080 <lt_debugprintf@plt>
test   %r14,%r14
je     1232 <lt_update_exe_path+0xc2>
test   %rbx,%rbx
je     1232 <lt_update_exe_path+0xc2>
cmpb   $0x0,(%r14)
je     1232 <lt_update_exe_path+0xc2>
cmpb   $0x0,(%rbx)
je     1232 <lt_update_exe_path+0xc2>
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>
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    1216 <lt_update_exe_path+0xa6>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%eax
cmpb   $0x3a,(%rbx,%rax,1)
jne    1209 <lt_update_exe_path+0x99>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jg     11f0 <lt_update_exe_path+0x80>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <lt_setenv@plt>
jmp    1226 <lt_update_exe_path+0xb6>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <lt_setenv@plt>
test   %rbx,%rbx
je     1232 <lt_update_exe_path+0xc2>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <free@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [166 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/paulcdejean/AeonTick/refs/heads/master/libtermkey-0.17/.libs/lt-demo-glib.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 i32
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 ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 663, 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 %67
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 %67
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %67
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 %67
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 i32 @strlen(i8* %32)
store i32 %33, i32* %6
br label %34
34: ; preds = %49, %27
%35 = load i8*, i8** %5
%36 = call i32 @strlen(i8* %35)
store i32 %36, i32* %6
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %47
38: ; preds = %34
%39 = load i8*, i8** %5
%40 = load i32, i32* %6
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 58
br label %47
47: ; preds = %38, %34
%48 = phi i1 [ false, %34 ], [ %46, %38 ]
br i1 %48, label %49, label %55
49: ; preds = %47
%50 = load i8*, i8** %5
%51 = load i32, i32* %6
%52 = sub nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %50, i64 %53
store i8 0, i8* %54
br label %34
55: ; preds = %47
%56 = load i8*, i8** %3
%57 = load i8*, i8** %5
%58 = call i32 @lt_setenv(i8* %56, i8* %57)
br label %59
59: ; preds = %55
%60 = load i8*, i8** %5
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load i8*, i8** %5
%64 = call i32 @free(i8* %63)
store i8* null, i8** %5
br label %65
65: ; preds = %62, %59
br label %66
66: ; preds = %65
br label %67
67: ; preds = %66, %22, %19, %14, %2
ret void
}

LLVM IR (-O2):
@.str = [166 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/paulcdejean/AeonTick/refs/heads/master/libtermkey-0.17/.libs/lt-demo-glib.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 ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 663, 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 %38, 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 %38
12: ; preds = %7
%13 = load i8, i8* %1
%14 = icmp eq i8 %13, 0
br i1 %14, label %38, 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 i32 @strlen(i8* %17)
%19 = tail call i32 @strlen(i8* %17)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %15, %28
%22 = phi i32 [ %29, %28 ], [ %19, %15 ]
%23 = add nsw i32 %22, -1
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %17, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 58
br i1 %27, label %28, label %34
28: ; preds = %21
store i8 0, i8* %25
%29 = tail call i32 @strlen(i8* %17)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %21, label %34
31: ; preds = %15
%32 = tail call i32 @lt_setenv(i8* %0, i8* %17)
%33 = icmp eq i8* %17, null
br i1 %33, label %38, label %36
34: ; preds = %28, %21
%35 = tail call i32 @lt_setenv(i8* %0, i8* %17)
br label %36
36: ; preds = %34, %31
%37 = tail call i32 @free(i8* %17)
br label %38
38: ; preds = %31, %36, %12, %7, %2
ret void
}