#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 *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strchr(char *, char);
int main() {
  char *env = getenv("PATH");
  printf("%s\n", env);
  printf("--------------------------------------------------\n");
  char *result = env;
  char target = ';';
  while ((result = strchr(result, target)) != NULL) {
    printf("%s\n", result);
    ++result;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movb   $0x3b,-0x19(%rbp)
mov    -0x18(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11b9 <main+0x89>
mov    -0x18(%rbp),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    117b <main+0x4b>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
lea    0xeb6(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x3b,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1191 <main+0x61>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <puts@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x3b,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1170 <main+0x40>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [52 x i8] c"--------------------------------------------------\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
store i32 0, i32* %1
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%9 = load i8*, i8** %2
store i8* %9, i8** %3
store i8 59, i8* %4
br label %10
10: ; preds = %15, %0
%11 = load i8*, i8** %3
%12 = load i8, i8* %4
%13 = call i8* @strchr(i8* %11, i8 signext %12)
store i8* %13, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
br label %10
20: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"PATH\00"
@str = [51 x i8] c"--------------------------------------------------\00"
define i32 @main() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) %1)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%4 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 59)
%5 = icmp eq i8* %4, null
br i1 %5, label %12, label %6
6: ; preds = %0, %6
%7 = phi i8* [ %10, %6 ], [ %4, %0 ]
%8 = tail call i32 @puts(i8* %7)
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext 59)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %6
12: ; preds = %6, %0
ret i32 0
}