#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*/ error(char *);
int /*<<< orphan*/ getenv(char *);
scalar_t__ malloc(int);
char *strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
char *path(char *mod) {
  char *modpath;
  modpath = (char *)malloc(sizeof(char) * 512);
  strcpy(modpath, getenv("MKPATH"));
  if (modpath != NULL) {
    modpath = strcat(modpath, "/mkc/il/");
    modpath = strcat(modpath, mod);
    return modpath;
  } else {
    error("Environment variable MKPATH not defined");
    return NULL;
  }
}


x86 assembly (clang, -O0):
<path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x200,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe87(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
cmpq   $0x0,-0x18(%rbp)
je     11c6 <path+0x76>
mov    -0x18(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11da <path+0x8a>
lea    0xe43(%rip),%rdi
call   1060 <error@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
test   %rbx,%rbx
je     11b7 <path+0x57>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movabs $0x2f6c692f636b6d2f,%rcx
69 6c 2f
mov    %rcx,(%rbx,%rax,1)
movb   $0x0,0x8(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
jmp    11c5 <path+0x65>
lea    0xe52(%rip),%rdi
call   1070 <error@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"MKPATH\00"
@.str.1 = [9 x i8] c"/mkc/il/\00"
@.str.2 = [40 x i8] c"Environment variable MKPATH not defined\00"
define i8* @path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = call i64 @malloc(i32 512)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @strcpy(i8* %7, i32 %8)
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %19
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = call i8* @strcat(i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = load i8*, i8** %3
%17 = call i8* @strcat(i8* %15, i8* %16)
store i8* %17, i8** %4
%18 = load i8*, i8** %4
store i8* %18, i8** %2
br label %21
19: ; preds = %1
%20 = call i32 @error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %2
br label %21
21: ; preds = %19, %12
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@.str = [7 x i8] c"MKPATH\00"
@.str.1 = [9 x i8] c"/mkc/il/\00"
@.str.2 = [40 x i8] c"Environment variable MKPATH not defined\00"
define i8* @path(i8* nocapture %0) {
%2 = tail call i64 @malloc(i32 512)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strcpy(i8* %3, i32 %4)
%6 = icmp eq i64 %2, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = tail call i64 @strlen(i8* %3)
%9 = getelementptr i8, i8* %3, i64 %8
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(9) %9, i8* align 1 dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 9, i1 false)
%10 = tail call i8* @strcat(i8* %3, i8* dereferenceable(1) %0)
br label %13
11: ; preds = %1
%12 = tail call i32 @error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
%14 = phi i8* [ %3, %7 ], [ null, %11 ]
ret i8* %14
}