#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 *);
char *malloc(int);
int /*<<< orphan*/ my_puterr(char *);
char **my_str_to_wordtab(char *, char);
char *path(char **);
char **read_path(char **env) {
  char *str;
  char **tab;
  if ((str = malloc(sizeof(char) * 4096)) == NULL)
    return (0);
  if ((str = path(env)) == 0) {
    my_puterr("No PATH detected\n");
    return (0);
  } else
    tab = my_str_to_wordtab(str, ':');
  free(str);
  return (tab);
}


x86 assembly (clang, -O0):
<read_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x1000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1181 <read_path+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <read_path+0x84>
mov    -0x10(%rbp),%rdi
call   1060 <path@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b1 <read_path+0x61>
lea    0xe61(%rip),%rdi
call   1050 <my_puterr@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <read_path+0x84>
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <my_str_to_wordtab@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_path>:
push   %r14
push   %rbx
push   %rax
call   1060 <path@plt>
test   %rax,%rax
je     116e <read_path+0x2e>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x3a,%esi
call   1040 <my_str_to_wordtab@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
jmp    117c <read_path+0x3c>
lea    0xe8b(%rip),%rdi
call   1050 <my_puterr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"No PATH detected\0A\00"
define i8** @read_path(i8** %0) {
%2 = alloca i8**
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8**
store i8** %0, i8*** %3
%6 = call i8* @malloc(i32 4096)
store i8* %6, i8** %4
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i8** null, i8*** %2
br label %22
9: ; preds = %1
%10 = load i8**, i8*** %3
%11 = call i8* @path(i8** %10)
store i8* %11, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @my_puterr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8** null, i8*** %2
br label %22
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = call i8** @my_str_to_wordtab(i8* %16, i8 signext 58)
store i8** %17, i8*** %5
br label %18
18: ; preds = %15
%19 = load i8*, i8** %4
%20 = call i32 @free(i8* %19)
%21 = load i8**, i8*** %5
store i8** %21, i8*** %2
br label %22
22: ; preds = %18, %13, %8
%23 = load i8**, i8*** %2
ret i8** %23
}

LLVM IR (-O2):
@.str = [18 x i8] c"No PATH detected\0A\00"
define i8** @read_path(i8** %0) {
%2 = tail call i8* @path(i8** %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @my_puterr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %9
6: ; preds = %1
%7 = tail call i8** @my_str_to_wordtab(i8* %2, i8 signext 58)
%8 = tail call i32 @free(i8* %2)
br label %9
9: ; preds = %6, %4
%10 = phi i8** [ null, %4 ], [ %7, %6 ]
ret i8** %10
}