#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 *FindInDir(char *, unsigned int);
char *GetAdaptorName();
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
char *FindConfigCluster(unsigned int cluster, char *addr) {
  char *awd;
  char dir[1024];
  char *ret = NULL;
  awd = getenv("AW_DATA_DIR");
  if (awd) {
    sprintf(dir, "%s/sensorconfig", awd);
    ret = FindInDir(dir, cluster);
    if (ret) {
      return ret;
    }
  }
  awd = getenv("ROOTACT");
  if (awd) {
    sprintf(dir, "%s/%s/sensorconfig", awd, GetAdaptorName());
    ret = FindInDir(dir, cluster);
    if (ret) {
      return ret;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<FindConfigCluster>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x428(%rbp)
lea    0xe9c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ca <FindConfigCluster+0x8a>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x420(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <FindInDir@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
je     11c5 <FindConfigCluster+0x85>
mov    -0x428(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1268 <FindConfigCluster+0x128>
jmp    11ca <FindConfigCluster+0x8a>
lea    0xe3b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     125d <FindConfigCluster+0x11d>
lea    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    $0x0,%al
call   1040 <GetAdaptorName@plt>
mov    -0x438(%rbp),%rdi
mov    -0x430(%rbp),%rdx
mov    %rax,%rcx
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x420(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <FindInDir@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
je     1258 <FindConfigCluster+0x118>
mov    -0x428(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1268 <FindConfigCluster+0x128>
jmp    125d <FindConfigCluster+0x11d>
mov    -0x428(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindConfigCluster>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edi,%ebp
lea    0xeac(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1184 <FindConfigCluster+0x44>
lea    0xeb2(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <FindInDir@plt>
test   %rax,%rax
jne    11ca <FindConfigCluster+0x8a>
lea    0xe81(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11c8 <FindConfigCluster+0x88>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <GetAdaptorName@plt>
lea    0xe6e(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <FindInDir@plt>
test   %rax,%rax
jne    11ca <FindConfigCluster+0x8a>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"AW_DATA_DIR\00"
@.str.1 = [16 x i8] c"%s/sensorconfig\00"
@.str.2 = [8 x i8] c"ROOTACT\00"
@.str.3 = [19 x i8] c"%s/%s/sensorconfig\00"
define i8* @FindConfigCluster(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* null, i8** %8
%9 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %24
12: ; preds = %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%14 = load i8*, i8** %6
%15 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%17 = load i32, i32* %4
%18 = call i8* @FindInDir(i8* %16, i32 %17)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = load i8*, i8** %8
store i8* %22, i8** %3
br label %43
23: ; preds = %12
br label %24
24: ; preds = %23, %2
%25 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %41
28: ; preds = %24
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%30 = load i8*, i8** %6
%31 = call i8* (...) @GetAdaptorName()
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %30, i8* %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%34 = load i32, i32* %4
%35 = call i8* @FindInDir(i8* %33, i32 %34)
store i8* %35, i8** %8
%36 = load i8*, i8** %8
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %28
%39 = load i8*, i8** %8
store i8* %39, i8** %3
br label %43
40: ; preds = %28
br label %41
41: ; preds = %40, %24
%42 = load i8*, i8** %8
store i8* %42, i8** %3
br label %43
43: ; preds = %41, %38, %21
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
@.str = [12 x i8] c"AW_DATA_DIR\00"
@.str.1 = [16 x i8] c"%s/sensorconfig\00"
@.str.2 = [8 x i8] c"ROOTACT\00"
@.str.3 = [19 x i8] c"%s/%s/sensorconfig\00"
define i8* @FindConfigCluster(i32 %0, i8* nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%9 = call i8* @FindInDir(i8* %4, i32 %0)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %20
11: ; preds = %7, %2
%12 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = call i8* (...) @GetAdaptorName()
%16 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %12, i8* %15)
%17 = call i8* @FindInDir(i8* %4, i32 %0)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %14, %11
br label %20
20: ; preds = %14, %7, %19
%21 = phi i8* [ null, %19 ], [ %9, %7 ], [ %17, %14 ]
ret i8* %21
}