#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 *componentsRegistryGetFilename() {
  char *omxregistryfile = NULL;
  char *buffer;
  buffer = getenv("OMX_BELLAGIO_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(".omxregister") + 2);
    strcpy(omxregistryfile, buffer);
    strcat(omxregistryfile, "/");
    strcat(omxregistryfile, ".omxregister");
    return omxregistryfile;
  }
  buffer = getenv("HOME");
  if (buffer != NULL && *buffer != '\0') {
    omxregistryfile = malloc(strlen(buffer) + strlen(".omxregister") + 3);
    strcpy(omxregistryfile, buffer);
    strcat(omxregistryfile, "/");
    strcat(omxregistryfile, ".omxregister");
  } else {
    omxregistryfile = malloc(strlen("/tmp/") + strlen(".omxregister") + 2);
    strcpy(omxregistryfile, "/tmp/");
    strcat(omxregistryfile, ".omxregister");
  }
  return omxregistryfile;
}


x86 assembly (clang, -O0):
<componentsRegistryGetFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x10(%rbp)
lea    0xe89(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b5 <componentsRegistryGetFilename+0x55>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b5 <componentsRegistryGetFilename+0x55>
mov    -0x18(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1329 <componentsRegistryGetFilename+0x1c9>
lea    0xe5a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1247 <componentsRegistryGetFilename+0xe7>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1247 <componentsRegistryGetFilename+0xe7>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
lea    0xe30(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe10(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1329 <componentsRegistryGetFilename+0x1c9>
lea    0xdd1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12d1 <componentsRegistryGetFilename+0x171>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12d1 <componentsRegistryGetFilename+0x171>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
lea    0xd9e(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xd7e(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xd5d(%rip),%rsi
call   1070 <strcat@plt>
jmp    1321 <componentsRegistryGetFilename+0x1c1>
lea    0xd59(%rip),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
lea    0xd3c(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xd25(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xd08(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<componentsRegistryGetFilename>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1189 <componentsRegistryGetFilename+0x29>
cmpb   $0x0,(%rax)
je     1189 <componentsRegistryGetFilename+0x29>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <strdup@plt>
lea    0xe86(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11b0 <componentsRegistryGetFilename+0x50>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11b0 <componentsRegistryGetFilename+0x50>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xe(%rax),%rdi
jmp    11d5 <componentsRegistryGetFilename+0x75>
lea    0xe68(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11f9 <componentsRegistryGetFilename+0x99>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11f9 <componentsRegistryGetFilename+0x99>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xf(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe46(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
jmp    1215 <componentsRegistryGetFilename+0xb5>
mov    $0x13,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe24(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
lea    0xe08(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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