#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 */
scalar_t__ DirHasPandPARTS(char *);
char *getenv(char *);
int /*<<< orphan*/ strcatSafe(char *, int, char *);
int /*<<< orphan*/ strcpySafe(char *, int, char const *);
int TryTypicalLDrawDirs(char *Str, int sizeofStr) {
  const char *e;
  e = getenv("HOME");
  if (e) {
    strcpySafe(Str, sizeofStr, e);
    strcatSafe(Str, sizeofStr, "/LDRAW");
    if (DirHasPandPARTS(Str))
      return 1;
  }
  strcpySafe(Str, sizeofStr, "/usr/local/share/LDRAW");
  if (DirHasPandPARTS(Str))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<TryTypicalLDrawDirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b1 <TryTypicalLDrawDirs+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <strcpySafe@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe8d(%rip),%rdx
call   1040 <strcatSafe@plt>
mov    -0x10(%rbp),%rdi
call   1050 <DirHasPandPARTS@plt>
cmp    $0x0,%rax
je     11ac <TryTypicalLDrawDirs+0x6c>
movl   $0x1,-0x4(%rbp)
jmp    11ea <TryTypicalLDrawDirs+0xaa>
jmp    11b1 <TryTypicalLDrawDirs+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe46(%rip),%rdx
call   1060 <strcpySafe@plt>
mov    -0x10(%rbp),%rdi
call   1050 <DirHasPandPARTS@plt>
cmp    $0x0,%rax
je     11e3 <TryTypicalLDrawDirs+0xa3>
movl   $0x1,-0x4(%rbp)
jmp    11ea <TryTypicalLDrawDirs+0xaa>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TryTypicalLDrawDirs>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     118c <TryTypicalLDrawDirs+0x4c>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1060 <strcpySafe@plt>
lea    0xea8(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <strcatSafe@plt>
mov    %rbx,%rdi
call   1050 <DirHasPandPARTS@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11b0 <TryTypicalLDrawDirs+0x70>
lea    0xe72(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <strcpySafe@plt>
mov    %rbx,%rdi
call   1050 <DirHasPandPARTS@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [7 x i8] c"/LDRAW\00"
@.str.2 = [23 x i8] c"/usr/local/share/LDRAW\00"
define i32 @TryTypicalLDrawDirs(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %23
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = load i8*, i8** %6
%14 = call i32 @strcpySafe(i8* %11, i32 %12, i8* %13)
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = call i32 @strcatSafe(i8* %15, i32 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = load i8*, i8** %4
%19 = call i64 @DirHasPandPARTS(i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %10
store i32 1, i32* %3
br label %32
22: ; preds = %10
br label %23
23: ; preds = %22, %2
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = call i32 @strcpySafe(i8* %24, i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8*, i8** %4
%28 = call i64 @DirHasPandPARTS(i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %23
store i32 1, i32* %3
br label %32
31: ; preds = %23
store i32 0, i32* %3
br label %32
32: ; preds = %31, %30, %21
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [7 x i8] c"/LDRAW\00"
@.str.2 = [23 x i8] c"/usr/local/share/LDRAW\00"
define i32 @TryTypicalLDrawDirs(i8* %0, i32 %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i32 @strcpySafe(i8* %0, i32 %1, i8* %3)
%7 = tail call i32 @strcatSafe(i8* %0, i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i64 @DirHasPandPARTS(i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %5, %2
%11 = tail call i32 @strcpySafe(i8* %0, i32 %1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i64 @DirHasPandPARTS(i8* %0)
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %10, %5
%16 = phi i32 [ 1, %5 ], [ %14, %10 ]
ret i32 %16
}