#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*/ add(char const *, int);
char *getenv(char *);
char *strchr(char const *, char);
int strlen(char const *);
void loader_add_dirs_from_env() {
  const char *rosepath = getenv("ROSEPATH");
  if (rosepath) {
    const char *start, *end;
    for (start = rosepath, end = strchr(rosepath, ':'); end;
         start = end + 1, end = strchr(start, ':')) {
      add(start, end - start);
    }
    add(start, strlen(start));
  }
}


x86 assembly (clang, -O0):
<loader_add_dirs_from_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11dd <loader_add_dirs_from_env+0x9d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c1 <loader_add_dirs_from_env+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1040 <add@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x18(%rbp)
jmp    117d <loader_add_dirs_from_env+0x3d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1040 <add@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loader_add_dirs_from_env>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11b2 <loader_add_dirs_from_env+0x72>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1199 <loader_add_dirs_from_env+0x59>
mov    %rax,%r14
nopl   (%rax)
mov    %r14d,%esi
sub    %ebx,%esi
mov    %rbx,%rdi
call   1040 <add@plt>
mov    %r14,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1170 <loader_add_dirs_from_env+0x30>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <add@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"ROSEPATH\00"
define void @loader_add_dirs_from_env() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %33
7: ; preds = %0
%8 = load i8*, i8** %1
store i8* %8, i8** %2
%9 = load i8*, i8** %1
%10 = call i8* @strchr(i8* %9, i8 signext 58)
store i8* %10, i8** %3
br label %11
11: ; preds = %23, %7
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = load i8*, i8** %2
%16 = load i8*, i8** %3
%17 = load i8*, i8** %2
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = call i32 @add(i8* %15, i32 %21)
br label %23
23: ; preds = %14
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %2
%26 = load i8*, i8** %2
%27 = call i8* @strchr(i8* %26, i8 signext 58)
store i8* %27, i8** %3
br label %11
28: ; preds = %11
%29 = load i8*, i8** %2
%30 = load i8*, i8** %2
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @add(i8* %29, i32 %31)
br label %33
33: ; preds = %28, %0
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"ROSEPATH\00"
define void @loader_add_dirs_from_env() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %21, label %3
3: ; preds = %0
%4 = tail call i8* @strchr(i8* %1, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %17, label %6
6: ; preds = %3, %6
%7 = phi i8* [ %15, %6 ], [ %4, %3 ]
%8 = phi i8* [ %14, %6 ], [ %1, %3 ]
%9 = ptrtoint i8* %7 to i64
%10 = ptrtoint i8* %8 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = tail call i32 @add(i8* %8, i32 %12)
%14 = getelementptr inbounds i8, i8* %7, i64 1
%15 = tail call i8* @strchr(i8* %14, i8 signext 58)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %6
17: ; preds = %6, %3
%18 = phi i8* [ %1, %3 ], [ %14, %6 ]
%19 = tail call i32 @strlen(i8* %18)
%20 = tail call i32 @add(i8* %18, i32 %19)
br label %21
21: ; preds = %17, %0
ret void
}