#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 */
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
scalar_t__ sys_isabsolutepath(char const *);
int sys_trytoopenone(char *, char const *, char const *, char *, char **,
                     unsigned int, int);
int sys_open_absolute(const char *name, const char *ext, char *dirresult,
                      char **nameresult, unsigned int size, int bin, int *fdp) {
  if (sys_isabsolutepath(name)) {
    char dirbuf[1000], *z = strrchr(name, '/');
    int dirlen;
    if (!z)
      return (0);
    dirlen = z - name;
    if (dirlen > 1000 - 1)
      dirlen = 1000 - 1;
    strncpy(dirbuf, name, dirlen);
    dirbuf[dirlen] = 0;
    *fdp = sys_trytoopenone(dirbuf, name + (dirlen + 1), ext, dirresult,
                            nameresult, size, bin);
    return (1);
  } else
    return (0);
}


x86 assembly (clang, -O0):
<sys_open_absolute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sys_isabsolutepath@plt>
cmp    $0x0,%rax
je     1244 <sys_open_absolute+0x104>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    11a9 <sys_open_absolute+0x69>
movl   $0x0,-0x4(%rbp)
jmp    124b <sys_open_absolute+0x10b>
mov    -0x428(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x42c(%rbp)
cmpl   $0x3e7,-0x42c(%rbp)
jle    11d7 <sys_open_absolute+0x97>
movl   $0x3e7,-0x42c(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x42c(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x42c(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%eax
mov    %eax,(%rsp)
call   1050 <sys_trytoopenone@plt>
mov    %eax,%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    124b <sys_open_absolute+0x10b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_open_absolute>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %r9d,%r13d
mov    %r8d,%r14d
mov    %rcx,%rbp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
call   1060 <sys_isabsolutepath@plt>
test   %rax,%rax
je     11e2 <sys_open_absolute+0xa2>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11e2 <sys_open_absolute+0xa2>
sub    %ebx,%eax
cmp    $0x3e7,%eax
mov    %r14d,0xc(%rsp)
mov    $0x3e7,%r14d
cmovl  %eax,%r14d
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movslq %r14d,%rax
movb   $0x0,0x10(%rsp,%rax,1)
lea    (%rax,%rbx,1),%rsi
add    $0x1,%rsi
mov    %r13d,(%rsp)
lea    0x10(%rsp),%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %rbp,%r8
mov    0xc(%rsp),%r9d
call   1050 <sys_trytoopenone@plt>
mov    0x430(%rsp),%rcx
mov    %eax,(%rcx)
mov    $0x1,%eax
jmp    11e4 <sys_open_absolute+0xa4>
xor    %eax,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sys_open_absolute(i8* %0, i8* %1, i8* %2, i8** %3, i32 %4, i32 %5, i32* %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8**
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
%16 = alloca [1000 x i8]
%17 = alloca i8*
%18 = alloca i32
store i8* %0, i8** %9
store i8* %1, i8** %10
store i8* %2, i8** %11
store i8** %3, i8*** %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32* %6, i32** %15
%19 = load i8*, i8** %9
%20 = call i64 @sys_isabsolutepath(i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %59
22: ; preds = %7
%23 = load i8*, i8** %9
%24 = call i8* @strrchr(i8* %23, i8 signext 47)
store i8* %24, i8** %17
%25 = load i8*, i8** %17
%26 = icmp ne i8* %25, null
br i1 %26, label %28, label %27
27: ; preds = %22
store i32 0, i32* %8
br label %60
28: ; preds = %22
%29 = load i8*, i8** %17
%30 = load i8*, i8** %9
%31 = ptrtoint i8* %29 to i64
%32 = ptrtoint i8* %30 to i64
%33 = sub i64 %31, %32
%34 = trunc i64 %33 to i32
store i32 %34, i32* %18
%35 = load i32, i32* %18
%36 = icmp sgt i32 %35, 999
br i1 %36, label %37, label %38
37: ; preds = %28
store i32 999, i32* %18
br label %38
38: ; preds = %37, %28
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%40 = load i8*, i8** %9
%41 = load i32, i32* %18
%42 = call i32 @strncpy(i8* %39, i8* %40, i32 %41)
%43 = load i32, i32* %18
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 %44
store i8 0, i8* %45
%46 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%47 = load i8*, i8** %9
%48 = load i32, i32* %18
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = load i8*, i8** %10
%53 = load i8*, i8** %11
%54 = load i8**, i8*** %12
%55 = load i32, i32* %13
%56 = load i32, i32* %14
%57 = call i32 @sys_trytoopenone(i8* %46, i8* %51, i8* %52, i8* %53, i8** %54, i32 %55, i32 %56)
%58 = load i32*, i32** %15
store i32 %57, i32* %58
store i32 1, i32* %8
br label %60
59: ; preds = %7
store i32 0, i32* %8
br label %60
60: ; preds = %59, %38, %27
%61 = load i32, i32* %8
ret i32 %61
}

LLVM IR (-O2):
define i32 @sys_open_absolute(i8* %0, i8* %1, i8* %2, i8** %3, i32 %4, i32 %5, i32* nocapture writeonly %6) {
%8 = alloca [1000 x i8]
%9 = tail call i64 @sys_isabsolutepath(i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %31, label %11
11: ; preds = %7
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%13 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%14 = icmp eq i8* %13, null
br i1 %14, label %29, label %15
15: ; preds = %11
%16 = ptrtoint i8* %13 to i64
%17 = ptrtoint i8* %0 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = icmp slt i32 %19, 999
%21 = select i1 %20, i32 %19, i32 999
%22 = call i32 @strncpy(i8* %12, i8* %0, i32 %21)
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 %23
store i8 0, i8* %24
%25 = add nsw i32 %21, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = call i32 @sys_trytoopenone(i8* %12, i8* %27, i8* %1, i8* %2, i8** %3, i32 %4, i32 %5)
store i32 %28, i32* %6
br label %29
29: ; preds = %11, %15
%30 = phi i32 [ 1, %15 ], [ 0, %11 ]
br label %31
31: ; preds = %7, %29
%32 = phi i32 [ %30, %29 ], [ 0, %7 ]
ret i32 %32
}