#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*/ addtoincludepath(char *);
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *strdup(char *);
char *strsep(char **, char *);
void ensure_m4path(void) {
  static int envpathdone = 0;
  char *envpath;
  char *sweep;
  char *path;
  if (envpathdone)
    return;
  envpathdone = 1;
  envpath = getenv("M4PATH");
  if (!envpath)
    return;
  envpath = strdup(envpath);
  if (!envpath)
    errx(1, "out of memory");
  for (sweep = envpath; (path = strsep(&sweep, ":")) != NULL;)
    addtoincludepath(path);
  free(envpath);
}


x86 assembly (clang, -O0):
<ensure_m4path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
cmpl   $0x0,0x2ee5(%rip)
je     117a <ensure_m4path+0x1a>
jmp    120a <ensure_m4path+0xaa>
movl   $0x1,0x2ed0(%rip)
lea    0xe75(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a4 <ensure_m4path+0x44>
jmp    120a <ensure_m4path+0xaa>
mov    -0x8(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11cd <ensure_m4path+0x6d>
mov    $0x1,%edi
lea    0xe3f(%rip),%rsi
call   1050 <errx@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1060 <strsep@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1201 <ensure_m4path+0xa1>
mov    -0x18(%rbp),%rdi
call   1070 <addtoincludepath@plt>
jmp    11d5 <ensure_m4path+0x75>
mov    -0x8(%rbp),%rdi
call   1040 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ensure_m4path>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmpb   $0x0,0x2ee4(%rip)
jne    1200 <ensure_m4path+0xa0>
movb   $0x1,0x2ed7(%rip)
lea    0xe7c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1200 <ensure_m4path+0xa0>
mov    %rax,%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11af <ensure_m4path+0x4f>
lea    0xe62(%rip),%rsi
mov    $0x1,%edi
call   1050 <errx@plt>
mov    %r14,0x8(%rsp)
lea    0xe5a(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1060 <strsep@plt>
test   %rax,%rax
je     11f8 <ensure_m4path+0x98>
lea    0xe44(%rip),%r15
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1070 <addtoincludepath@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strsep@plt>
test   %rax,%rax
jne    11e0 <ensure_m4path+0x80>
mov    %r14,%rdi
call   1040 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ensure_m4path.envpathdone = internal global i32 0
@.str = [7 x i8] c"M4PATH\00"
@.str.1 = [14 x i8] c"out of memory\00"
@.str.2 = [2 x i8] c":\00"
define void @ensure_m4path() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = load i32, i32* @ensure_m4path.envpathdone
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
br label %30
7: ; preds = %0
store i32 1, i32* @ensure_m4path.envpathdone
%8 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %1
%9 = load i8*, i8** %1
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %7
br label %30
12: ; preds = %7
%13 = load i8*, i8** %1
%14 = call i8* @strdup(i8* %13)
store i8* %14, i8** %1
%15 = load i8*, i8** %1
%16 = icmp ne i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = call i32 @errx(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = load i8*, i8** %1
store i8* %20, i8** %2
br label %21
21: ; preds = %24, %19
%22 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %22, i8** %3
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i8*, i8** %3
%26 = call i32 @addtoincludepath(i8* %25)
br label %21
27: ; preds = %21
%28 = load i8*, i8** %1
%29 = call i32 @free(i8* %28)
br label %30
30: ; preds = %27, %11, %6
ret void
}

LLVM IR (-O2):
@ensure_m4path.envpathdone = internal unnamed_addr global i1 false
@.str = [7 x i8] c"M4PATH\00"
@.str.1 = [14 x i8] c"out of memory\00"
@.str.2 = [2 x i8] c":\00"
define void @ensure_m4path() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = load i1, i1* @ensure_m4path.envpathdone
br i1 %3, label %22, label %4
4: ; preds = %0
store i1 true, i1* @ensure_m4path.envpathdone
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %22, label %7
7: ; preds = %4
%8 = tail call i8* @strdup(i8* %5)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
store i8* %8, i8** %1
%13 = call i8* @strsep(i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %12, %15
%16 = phi i8* [ %18, %15 ], [ %13, %12 ]
%17 = call i32 @addtoincludepath(i8* %16)
%18 = call i8* @strsep(i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %15
20: ; preds = %15, %12
%21 = call i32 @free(i8* %8)
br label %22
22: ; preds = %4, %0, %20
ret void
}