#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 */
typedef int /*<<< orphan*/ path_buf;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int PATH_MAX;
scalar_t__ access(char *, int /*<<< orphan*/);
scalar_t__ adb_is_absolute_host_path(char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int top_works(const char *top) {
  if (top != NULL && adb_is_absolute_host_path(top)) {
    char path_buf[PATH_MAX];
    snprintf(path_buf, sizeof(path_buf),
             "%s"
             "/"
             "config"
             "/"
             "envsetup.make",
             top);
    return access(path_buf, F_OK) == 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<top_works>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c5 <top_works+0x95>
mov    -0x10(%rbp),%rdi
call   1040 <adb_is_absolute_host_path@plt>
cmp    $0x0,%rax
je     11c5 <top_works+0x95>
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
lea    0xe6d(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    11cc <top_works+0x9c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<top_works>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rdi,%rdi
je     119c <top_works+0x6c>
mov    %rdi,%r14
call   1040 <adb_is_absolute_host_path@plt>
test   %rax,%rax
je     119c <top_works+0x6c>
mov    %rsp,%r15
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe8b(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rcx
call   1030 <snprintf@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    %r15,%rsp
mov    %ebx,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [24 x i8] c"%s/config/envsetup.make\00"
@F_OK = global i32 0
define i32 @top_works(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %25
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i64 @adb_is_absolute_host_path(i8* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load i32, i32* @PATH_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %4
%16 = alloca i8, i64 %14
store i64 %14, i64* %5
%17 = trunc i64 %14 to i32
%18 = load i8*, i8** %3
%19 = call i32 @snprintf(i8* %16, i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @F_OK
%21 = call i64 @access(i8* %16, i32 %20)
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
store i32 %23, i32* %2
%24 = load i8*, i8** %4
br label %26
25: ; preds = %8, %1
store i32 0, i32* %2
br label %26
26: ; preds = %25, %12
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [24 x i8] c"%s/config/envsetup.make\00"
@F_OK = global i32 0
define i32 @top_works(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = tail call i64 @adb_is_absolute_host_path(i8* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = load i32, i32* @PATH_MAX
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = call i32 @snprintf(i8* %10, i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = load i32, i32* @F_OK
%13 = call i64 @access(i8* %10, i32 %12)
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %1, %3, %6
%17 = phi i32 [ %15, %6 ], [ 0, %3 ], [ 0, %1 ]
ret i32 %17
}