#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 */
char *getenv(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
scalar_t__ strlen(char *);
char *loadersRegistryGetFilename(char *registry_name) {
  char *omxregistryfile = NULL;
  char *buffer;
  buffer = getenv("OMX_BELLAGIO_LOADER_REGISTRY");
  if (buffer != NULL && *buffer != '\0') {
    omxregistryfile = strdup(buffer);
    return omxregistryfile;
  }
  buffer = getenv("XDG_DATA_HOME");
  if (buffer != NULL && *buffer != '\0') {
    omxregistryfile = malloc(strlen(buffer) + strlen(registry_name) + 2);
    strcpy(omxregistryfile, buffer);
    strcat(omxregistryfile, "/");
    strcat(omxregistryfile, registry_name);
    return omxregistryfile;
  }
  buffer = getenv("HOME");
  if (buffer != NULL && *buffer != '\0') {
    omxregistryfile = malloc(strlen(buffer) + strlen(registry_name) + 3);
    strcpy(omxregistryfile, buffer);
    strcat(omxregistryfile, "/");
    strcat(omxregistryfile, registry_name);
  } else {
    omxregistryfile = malloc(strlen("/tmp/") + strlen(registry_name) + 2);
    strcpy(omxregistryfile, "/tmp/");
    strcat(omxregistryfile, registry_name);
  }
  return omxregistryfile;
}


x86 assembly (clang, -O0):
<loadersRegistryGetFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b9 <loadersRegistryGetFilename+0x59>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b9 <loadersRegistryGetFilename+0x59>
mov    -0x20(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    131b <loadersRegistryGetFilename+0x1bb>
lea    0xe5d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1245 <loadersRegistryGetFilename+0xe5>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1245 <loadersRegistryGetFilename+0xe5>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    131b <loadersRegistryGetFilename+0x1bb>
lea    0xdda(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12c9 <loadersRegistryGetFilename+0x169>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12c9 <loadersRegistryGetFilename+0x169>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xd7d(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
jmp    1313 <loadersRegistryGetFilename+0x1b3>
lea    0xd5b(%rip),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd2a(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadersRegistryGetFilename>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     118b <loadersRegistryGetFilename+0x2b>
cmpb   $0x0,(%rax)
je     118b <loadersRegistryGetFilename+0x2b>
mov    %rax,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <strdup@plt>
lea    0xe8b(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11c1 <loadersRegistryGetFilename+0x61>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11c1 <loadersRegistryGetFilename+0x61>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x2,%rdi
jmp    11f5 <loadersRegistryGetFilename+0x95>
lea    0xe5e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1219 <loadersRegistryGetFilename+0xb9>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     1219 <loadersRegistryGetFilename+0xb9>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe20(%rip),%rsi
mov    %r15,%rdi
call   1070 <strcat@plt>
jmp    123c <loadersRegistryGetFilename+0xdc>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x7(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xdf7(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"OMX_BELLAGIO_LOADER_REGISTRY\00"
@.str.1 = [14 x i8] c"XDG_DATA_HOME\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [6 x i8] c"/tmp/\00"
define i8* @loadersRegistryGetFilename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %4
%6 = call i8* @getenv(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = call i8* @strdup(i8* %15)
store i8* %16, i8** %4
%17 = load i8*, i8** %4
store i8* %17, i8** %2
br label %83
18: ; preds = %9, %1
%19 = call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %44
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %44
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = call i64 @strlen(i8* %28)
%30 = load i8*, i8** %3
%31 = call i64 @strlen(i8* %30)
%32 = add nsw i64 %29, %31
%33 = add nsw i64 %32, 2
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %4
%35 = load i8*, i8** %4
%36 = load i8*, i8** %5
%37 = call i32 @strcpy(i8* %35, i8* %36)
%38 = load i8*, i8** %4
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = load i8*, i8** %4
%41 = load i8*, i8** %3
%42 = call i32 @strcat(i8* %40, i8* %41)
%43 = load i8*, i8** %4
store i8* %43, i8** %2
br label %83
44: ; preds = %22, %18
%45 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %45, i8** %5
%46 = load i8*, i8** %5
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %69
48: ; preds = %44
%49 = load i8*, i8** %5
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %69
53: ; preds = %48
%54 = load i8*, i8** %5
%55 = call i64 @strlen(i8* %54)
%56 = load i8*, i8** %3
%57 = call i64 @strlen(i8* %56)
%58 = add nsw i64 %55, %57
%59 = add nsw i64 %58, 3
%60 = call i8* @malloc(i64 %59)
store i8* %60, i8** %4
%61 = load i8*, i8** %4
%62 = load i8*, i8** %5
%63 = call i32 @strcpy(i8* %61, i8* %62)
%64 = load i8*, i8** %4
%65 = call i32 @strcat(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%66 = load i8*, i8** %4
%67 = load i8*, i8** %3
%68 = call i32 @strcat(i8* %66, i8* %67)
br label %81
69: ; preds = %48, %44
%70 = call i64 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%71 = load i8*, i8** %3
%72 = call i64 @strlen(i8* %71)
%73 = add nsw i64 %70, %72
%74 = add nsw i64 %73, 2
%75 = call i8* @malloc(i64 %74)
store i8* %75, i8** %4
%76 = load i8*, i8** %4
%77 = call i32 @strcpy(i8* %76, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%78 = load i8*, i8** %4
%79 = load i8*, i8** %3
%80 = call i32 @strcat(i8* %78, i8* %79)
br label %81
81: ; preds = %69, %53
%82 = load i8*, i8** %4
store i8* %82, i8** %2
br label %83
83: ; preds = %81, %27, %14
%84 = load i8*, i8** %2
ret i8* %84
}

LLVM IR (-O2):
@.str = [29 x i8] c"OMX_BELLAGIO_LOADER_REGISTRY\00"
@.str.1 = [14 x i8] c"XDG_DATA_HOME\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [6 x i8] c"/tmp/\00"
define i8* @loadersRegistryGetFilename(i8* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i8* @strdup(i8* %2)
br label %45
9: ; preds = %4, %1
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %24, label %12
12: ; preds = %9
%13 = load i8, i8* %10
%14 = icmp eq i8 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %12
%16 = tail call i64 @strlen(i8* %10)
%17 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%18 = add i64 %16, 2
%19 = add i64 %18, %17
%20 = tail call i8* @malloc(i64 %19)
%21 = tail call i32 @strcpy(i8* %20, i8* %10)
%22 = tail call i32 @strcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @strcat(i8* %20, i8* %0)
br label %45
24: ; preds = %12, %9
%25 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %39, label %27
27: ; preds = %24
%28 = load i8, i8* %25
%29 = icmp eq i8 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %27
%31 = tail call i64 @strlen(i8* %25)
%32 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%33 = add i64 %31, 3
%34 = add i64 %33, %32
%35 = tail call i8* @malloc(i64 %34)
%36 = tail call i32 @strcpy(i8* %35, i8* %25)
%37 = tail call i32 @strcat(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%38 = tail call i32 @strcat(i8* %35, i8* %0)
br label %45
39: ; preds = %27, %24
%40 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%41 = add nsw i64 %40, 7
%42 = tail call i8* @malloc(i64 %41)
%43 = tail call i32 @strcpy(i8* %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%44 = tail call i32 @strcat(i8* %42, i8* %0)
br label %45
45: ; preds = %30, %39, %15, %7
%46 = phi i8* [ %8, %7 ], [ %20, %15 ], [ %35, %30 ], [ %42, %39 ]
ret i8* %46
}