#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
char *libdir(char *file) {
  static char buf[1024];
  char *nchome = getenv("NC100EM_HOME");
  if (nchome) {
    mkdir(nchome, 0777);
    snprintf(buf, sizeof(buf), "%s/%s", nchome, file);
  } else {
    char *home = getenv("HOME");
    if (!home)
      snprintf(buf, sizeof(buf), "%s", file);
    else {
      snprintf(buf, sizeof(buf), "%s/nc100", home);
      mkdir(buf, 0777);
      snprintf(buf, sizeof(buf), "%s/nc100/%s", home, file);
    }
  }
  return (buf);
}


x86 assembly (clang, -O0):
<libdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118c <libdir+0x5c>
mov    -0x10(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0x2edc(%rip),%rdi
mov    $0x400,%esi
lea    0xe8d(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    1220 <libdir+0xf0>
lea    0xe75(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ca <libdir+0x9a>
mov    -0x8(%rbp),%rcx
lea    0x2e9e(%rip),%rdi
mov    $0x400,%esi
lea    0xe67(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    121b <libdir+0xeb>
mov    -0x18(%rbp),%rcx
lea    0x2e7b(%rip),%rdi
mov    $0x400,%esi
lea    0xe32(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    0x2e61(%rip),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0x2e48(%rip),%rdi
mov    $0x400,%esi
lea    0xe08(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    1220 <libdir+0xf0>
lea    0x2e29(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libdir>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xec1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1169 <libdir+0x39>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
lea    0x2ef0(%rip),%rdi
lea    0xea6(%rip),%rdx
jmp    11b4 <libdir+0x84>
lea    0xe98(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11d3 <libdir+0xa3>
mov    %rax,%rbx
lea    0x2ecc(%rip),%r15
lea    0xe88(%rip),%rdx
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %r15,%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
lea    0xe6b(%rip),%rdx
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0x2e83(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0x2e76(%rip),%rdi
lea    0xe44(%rip),%rdx
mov    $0x400,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
jmp    11c6 <libdir+0x96>

LLVM IR (-O0):
@libdir.buf = internal global [1024 x i8] zeroinitializer
@.str = [13 x i8] c"NC100EM_HOME\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [9 x i8] c"%s/nc100\00"
@.str.5 = [12 x i8] c"%s/nc100/%s\00"
define i8* @libdir(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @mkdir(i8* %9, i32 511)
%11 = load i8*, i8** %3
%12 = load i8*, i8** %2
%13 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @libdir.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %12)
br label %29
14: ; preds = %1
%15 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i8*, i8** %2
%20 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @libdir.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %28
21: ; preds = %14
%22 = load i8*, i8** %4
%23 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @libdir.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %22)
%24 = call i32 @mkdir(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @libdir.buf, i64 0, i64 0), i32 511)
%25 = load i8*, i8** %4
%26 = load i8*, i8** %2
%27 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @libdir.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %25, i8* %26)
br label %28
28: ; preds = %21, %18
br label %29
29: ; preds = %28, %8
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @libdir.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@libdir.buf = internal global [1024 x i8] zeroinitializer
@.str = [13 x i8] c"NC100EM_HOME\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [9 x i8] c"%s/nc100\00"
@.str.5 = [12 x i8] c"%s/nc100/%s\00"
define i8* @libdir(i8* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 @mkdir(i8* %2, i32 511)
%6 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @libdir.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %0)
br label %16
7: ; preds = %1
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @libdir.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %16
12: ; preds = %7
%13 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @libdir.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%14 = tail call i32 @mkdir(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @libdir.buf, i64 0, i64 0), i32 511)
%15 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @libdir.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %8, i8* %0)
br label %16
16: ; preds = %10, %12, %4
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @libdir.buf, i64 0, i64 0)
}