#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 */
struct PState {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getArgPath(char *, struct PState *);
int /*<<< orphan*/ getEnvPath(char *);
int /*<<< orphan*/ getLocalPath(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ testPath(char *);
void getFilePath(char path[], struct PState *pstate) {
  if (!getArgPath(path, pstate)) {
    if (!getEnvPath(path)) {
      if (!getLocalPath(path)) {
        strcat(path, "items.lst");
      }
    }
  }
  if (!testPath(path)) {
    printf("Could not find a valid data file at %s\n", path);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<getFilePath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <getArgPath@plt>
cmp    $0x0,%eax
jne    11d4 <getFilePath+0x64>
mov    -0x8(%rbp),%rdi
call   1070 <getEnvPath@plt>
cmp    $0x0,%eax
jne    11cf <getFilePath+0x5f>
mov    -0x8(%rbp),%rdi
call   1060 <getLocalPath@plt>
cmp    $0x0,%eax
jne    11ca <getFilePath+0x5a>
mov    -0x8(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1080 <strcat@plt>
jmp    11cf <getFilePath+0x5f>
jmp    11d4 <getFilePath+0x64>
mov    -0x8(%rbp),%rdi
call   1030 <testPath@plt>
cmp    $0x0,%eax
jne    1204 <getFilePath+0x94>
mov    -0x8(%rbp),%rsi
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFilePath>:
push   %rbx
mov    %rdi,%rbx
call   1050 <getArgPath@plt>
test   %eax,%eax
jne    11a4 <getFilePath+0x34>
mov    %rbx,%rdi
call   1070 <getEnvPath@plt>
test   %eax,%eax
jne    11a4 <getFilePath+0x34>
mov    %rbx,%rdi
call   1060 <getLocalPath@plt>
test   %eax,%eax
jne    11a4 <getFilePath+0x34>
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    %rbx,%rdi
call   1030 <testPath@plt>
test   %eax,%eax
je     11b2 <getFilePath+0x42>
pop    %rbx
ret
lea    0xe51(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.PState = type { i32 }
@.str = [10 x i8] c"items.lst\00"
@.str.1 = [40 x i8] c"Could not find a valid data file at %s\0A\00"
@EXIT_FAILURE = global i32 0
define void @getFilePath(i8* %0, %struct.PState* %1) {
%3 = alloca i8*
%4 = alloca %struct.PState*
store i8* %0, i8** %3
store %struct.PState* %1, %struct.PState** %4
%5 = load i8*, i8** %3
%6 = load %struct.PState*, %struct.PState** %4
%7 = call i32 @getArgPath(i8* %5, %struct.PState* %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 @getEnvPath(i8* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = call i32 @getLocalPath(i8* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %17, %13
br label %21
21: ; preds = %20, %9
br label %22
22: ; preds = %21, %2
%23 = load i8*, i8** %3
%24 = call i32 @testPath(i8* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %22
%27 = load i8*, i8** %3
%28 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %22
ret void
}

LLVM IR (-O2):
%struct.PState = type { i32 }
@.str = [10 x i8] c"items.lst\00"
@.str.1 = [40 x i8] c"Could not find a valid data file at %s\0A\00"
@EXIT_FAILURE = global i32 0
define void @getFilePath(i8* %0, %struct.PState* %1) {
%3 = tail call i32 @getArgPath(i8* %0, %struct.PState* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = tail call i32 @getEnvPath(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = tail call i32 @getLocalPath(i8* %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %5, %11, %8, %2
%14 = tail call i32 @testPath(i8* %0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %13
ret void
}