#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 *extract_colon_unit(char const *, int *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ malloc(scalar_t__);
char *strcpy(int /*<<< orphan*/, char *);
scalar_t__ strlen(char *);
char *get_next_path_element(char const *path_list, int *path_index_pointer) {
  char *path;
  path = extract_colon_unit(path_list, path_index_pointer);
  if (path == 0)
    return (path);
  if (*path == '\0') {
    free(path);
    path = strcpy(malloc(1 + strlen(".")), ("."));
  }
  return (path);
}


x86 assembly (clang, -O0):
<get_next_path_element>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <extract_colon_unit@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1189 <get_next_path_element+0x39>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d4 <get_next_path_element+0x84>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11cc <get_next_path_element+0x7c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xe57(%rip),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %eax,%edi
lea    0xe3d(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_path_element>:
push   %rax
call   1050 <extract_colon_unit@plt>
test   %rax,%rax
je     1152 <get_next_path_element+0x12>
cmpb   $0x0,(%rax)
je     1156 <get_next_path_element+0x16>
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x2,%edi
call   1060 <malloc@plt>
lea    0xe91(%rip),%rsi
mov    %eax,%edi
pop    %rax
jmp    1040 <strcpy@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i8* @get_next_path_element(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
%8 = load i32*, i32** %5
%9 = call i8* @extract_colon_unit(i8* %7, i32* %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i8*, i8** %6
store i8* %13, i8** %3
br label %28
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = load i8*, i8** %6
%21 = call i32 @free(i8* %20)
%22 = call i64 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = add nsw i64 1, %22
%24 = call i32 @malloc(i64 %23)
%25 = call i8* @strcpy(i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %25, i8** %6
br label %26
26: ; preds = %19, %14
%27 = load i8*, i8** %6
store i8* %27, i8** %3
br label %28
28: ; preds = %26, %12
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @get_next_path_element(i8* %0, i32* %1) {
%3 = tail call i8* @extract_colon_unit(i8* %0, i32* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = tail call i32 @free(i8* %3)
%10 = tail call i32 @malloc(i64 2)
%11 = tail call i8* @strcpy(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %5, %8, %2
%13 = phi i8* [ null, %2 ], [ %11, %8 ], [ %3, %5 ]
ret i8* %13
}