#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*/ fname;

/* Variables and functions */
int /*<<< orphan*/ fatal(char *);
char *getenv(char *);
char *options_get_str(char *);
int snprintf(char *, int, char *, char *, char const *, ...);
char *create_file_name(const char *file) {
  char *home_dir;
  static char fname[4096];
  char *moc_dir = options_get_str("MOCDir");
  if (moc_dir[0] == '~') {
    if (!(home_dir = getenv("HOME")))
      fatal("No HOME environmential variable.");
    if (snprintf(fname, sizeof(fname), "%s/%s/%s", home_dir,
                 (moc_dir[1] == '/') ? moc_dir + 2 : moc_dir + 1,
                 file) >= (int)sizeof(fname))
      fatal("Path too long.");
  } else if (snprintf(fname, sizeof(fname), "%s/%s", moc_dir, file) >=
             (int)sizeof(fname))
    fatal("Path too long.");
  return fname;
}


x86 assembly (clang, -O0):
<create_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
call   1060 <options_get_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    120a <create_file_name+0xca>
lea    0xe94(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1192 <create_file_name+0x52>
lea    0xe7f(%rip),%rdi
call   1050 <fatal@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    11bc <create_file_name+0x7c>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    11c8 <create_file_name+0x88>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x8(%rbp),%r9
lea    0x2e75(%rip),%rdi
mov    $0x1000,%esi
lea    0xe46(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
cmp    $0x1000,%eax
jl     1205 <create_file_name+0xc5>
lea    0xe36(%rip),%rdi
call   1050 <fatal@plt>
jmp    1248 <create_file_name+0x108>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0x2e37(%rip),%rdi
mov    $0x1000,%esi
lea    0xe0b(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
cmp    $0x1000,%eax
jl     1243 <create_file_name+0x103>
lea    0xdf8(%rip),%rdi
call   1050 <fatal@plt>
jmp    1248 <create_file_name+0x108>
lea    0x2e01(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file_name>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xeb1(%rip),%rdi
call   1060 <options_get_str@plt>
mov    %rax,%rbx
cmpb   $0x7e,(%rax)
jne    11b8 <create_file_name+0x78>
lea    0xea4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r15
test   %rax,%rax
jne    117c <create_file_name+0x3c>
lea    0xe95(%rip),%rdi
call   1050 <fatal@plt>
lea    0x1(%rbx),%rax
mov    %rbx,%r8
add    $0x2,%r8
cmpb   $0x2f,0x1(%rbx)
cmovne %rax,%r8
lea    0x2eba(%rip),%rdi
lea    0xe90(%rip),%rdx
mov    $0x1000,%esi
mov    %r15,%rcx
mov    %r14,%r9
xor    %eax,%eax
call   1040 <snprintf@plt>
cmp    $0xfff,%eax
jg     11df <create_file_name+0x9f>
jmp    11eb <create_file_name+0xab>
lea    0x2e91(%rip),%rdi
lea    0xe6a(%rip),%rdx
mov    $0x1000,%esi
mov    %rbx,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
cmp    $0x1000,%eax
jl     11eb <create_file_name+0xab>
lea    0xe50(%rip),%rdi
call   1050 <fatal@plt>
lea    0x2e5e(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@create_file_name.fname = internal global [4096 x i8] zeroinitializer
@.str = [7 x i8] c"MOCDir\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [33 x i8] c"No HOME environmential variable.\00"
@.str.3 = [9 x i8] c"%s/%s/%s\00"
@.str.4 = [15 x i8] c"Path too long.\00"
@.str.5 = [6 x i8] c"%s/%s\00"
define i8* @create_file_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i8* @options_get_str(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 126
br i1 %10, label %11, label %37
11: ; preds = %1
%12 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @fatal(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = load i8*, i8** %3
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 2
br label %29
26: ; preds = %16
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 1
br label %29
29: ; preds = %26, %23
%30 = phi i8* [ %25, %23 ], [ %28, %26 ]
%31 = load i8*, i8** %2
%32 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @create_file_name.fname, i64 0, i64 0), i32 4096, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %30, i8* %31)
%33 = icmp sge i32 %32, 4096
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @fatal(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
br label %45
37: ; preds = %1
%38 = load i8*, i8** %4
%39 = load i8*, i8** %2
%40 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @create_file_name.fname, i64 0, i64 0), i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %38, i8* %39)
%41 = icmp sge i32 %40, 4096
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @fatal(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %37
br label %45
45: ; preds = %44, %36
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @create_file_name.fname, i64 0, i64 0)
}

LLVM IR (-O2):
@create_file_name.fname = internal global [4096 x i8] zeroinitializer
@.str = [7 x i8] c"MOCDir\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [33 x i8] c"No HOME environmential variable.\00"
@.str.3 = [9 x i8] c"%s/%s/%s\00"
@.str.4 = [15 x i8] c"Path too long.\00"
@.str.5 = [6 x i8] c"%s/%s\00"
define i8* @create_file_name(i8* %0) {
%2 = tail call i8* @options_get_str(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = load i8, i8* %2
%4 = icmp eq i8 %3, 126
br i1 %4, label %5, label %18
5: ; preds = %1
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @fatal(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = getelementptr inbounds i8, i8* %2, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
%14 = getelementptr inbounds i8, i8* %2, i64 2
%15 = select i1 %13, i8* %14, i8* %11
%16 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @create_file_name.fname, i64 0, i64 0), i32 4096, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* %15, i8* %0)
%17 = icmp sgt i32 %16, 4095
br i1 %17, label %21, label %23
18: ; preds = %1
%19 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @create_file_name.fname, i64 0, i64 0), i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* %0)
%20 = icmp sgt i32 %19, 4095
br i1 %20, label %21, label %23
21: ; preds = %18, %10
%22 = tail call i32 @fatal(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %21, %18, %10
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @create_file_name.fname, i64 0, i64 0)
}