#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 *);
int /*<<< orphan*/ printf(char *, char *);
char *strdup(int /*<<< orphan*/);
int main(int argc, char **argv) {
  char *path = strdup(getenv("PATH"));
  char *save = path;
  while (*path) {
    char *p = path;
    while (*p && *p != ':')
      *p++;
    if (*p == 0) {
      printf("%s\n", path);
      break;
    }
    *p = 0;
    printf("%s\n", path);
    path = p + 1;
  }
  free(save);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     121d <main+0xdd>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     11af <main+0x6f>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11bf <main+0x7f>
jmp    11d0 <main+0x90>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    118a <main+0x4a>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11f5 <main+0xb5>
mov    -0x18(%rbp),%rsi
lea    0xe1a(%rip),%rdi
call   1050 <printf@plt>
jmp    121d <main+0xdd>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rsi
lea    0xdfe(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1175 <main+0x35>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
call   1060 <strdup@plt>
mov    %rax,%r15
mov    (%rax),%al
test   %al,%al
je     11c3 <main+0x83>
lea    0xe9d(%rip),%r14
mov    %r15,%rsi
lea    0x1(%rsi),%rbx
test   %al,%al
je     11b7 <main+0x77>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x3a,%al
je     11a0 <main+0x60>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1180 <main+0x40>
jmp    11b7 <main+0x77>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,-0x1(%rbx)
mov    %r14,%rdi
call   1050 <printf@plt>
mov    (%rbx),%al
mov    %rbx,%rsi
test   %al,%al
jne    116b <main+0x2b>
jmp    11c3 <main+0x83>
lea    0xe47(%rip),%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1040 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = call i8* @strdup(i32 %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
store i8* %11, i8** %7
br label %12
12: ; preds = %42, %2
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %48
16: ; preds = %12
%17 = load i8*, i8** %6
store i8* %17, i8** %8
br label %18
18: ; preds = %30, %16
%19 = load i8*, i8** %8
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i8*, i8** %8
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 58
br label %28
28: ; preds = %23, %18
%29 = phi i1 [ false, %18 ], [ %27, %23 ]
br i1 %29, label %30, label %34
30: ; preds = %28
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %8
%33 = load i8, i8* %31
br label %18
34: ; preds = %28
%35 = load i8*, i8** %8
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = load i8*, i8** %6
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %40)
br label %48
42: ; preds = %34
%43 = load i8*, i8** %8
store i8 0, i8* %43
%44 = load i8*, i8** %6
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = load i8*, i8** %8
%47 = getelementptr inbounds i8, i8* %46, i64 1
store i8* %47, i8** %6
br label %12
48: ; preds = %39, %12
%49 = load i8*, i8** %7
%50 = call i32 @free(i8* %49)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @strdup(i32 %3)
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %23, label %7
7: ; preds = %2, %18
%8 = phi i8 [ %21, %18 ], [ %5, %2 ]
%9 = phi i8* [ %20, %18 ], [ %4, %2 ]
br label %10
10: ; preds = %7, %13
%11 = phi i8 [ %15, %13 ], [ %8, %7 ]
%12 = phi i8* [ %14, %13 ], [ %9, %7 ]
switch i8 %11, label %13 [
i8 0, label %16
i8 58, label %18
]
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %12, i64 1
%15 = load i8, i8* %14
br label %10
16: ; preds = %10
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %23
18: ; preds = %10
store i8 0, i8* %12
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%20 = getelementptr inbounds i8, i8* %12, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %7
23: ; preds = %18, %2, %16
%24 = tail call i32 @free(i8* %4)
ret i32 0
}