#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 input_file {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
struct input_file *dopath(struct input_file *, char const *);
int /*<<< orphan*/ ensure_m4path();
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ set_input(struct input_file *, int /*<<< orphan*/ *,
                             char const *);
struct input_file *fopen_trypath(struct input_file *i, const char *filename) {
  FILE *f;
  f = fopen(filename, "r");
  if (f != NULL) {
    set_input(i, f, filename);
    return i;
  }
  if (filename[0] == '/')
    return NULL;
  ensure_m4path();
  return dopath(i, filename);
}


x86 assembly (clang, -O0):
<fopen_trypath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118d <fopen_trypath+0x4d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <set_input@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c2 <fopen_trypath+0x82>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11aa <fopen_trypath+0x6a>
movq   $0x0,-0x8(%rbp)
jmp    11c2 <fopen_trypath+0x82>
mov    $0x0,%al
call   1060 <ensure_m4path@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <dopath@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fopen_trypath>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     116e <fopen_trypath+0x2e>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <set_input@plt>
jmp    1176 <fopen_trypath+0x36>
cmpb   $0x2f,(%rbx)
jne    1181 <fopen_trypath+0x41>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1060 <ensure_m4path@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <dopath@plt>

LLVM IR (-O0):
%struct.input_file = type { i32 }
@.str = [2 x i8] c"r\00"
define %struct.input_file* @fopen_trypath(%struct.input_file* %0, i8* %1) {
%3 = alloca %struct.input_file*
%4 = alloca %struct.input_file*
%5 = alloca i8*
%6 = alloca i32*
store %struct.input_file* %0, %struct.input_file** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load %struct.input_file*, %struct.input_file** %4
%13 = load i32*, i32** %6
%14 = load i8*, i8** %5
%15 = call i32 @set_input(%struct.input_file* %12, i32* %13, i8* %14)
%16 = load %struct.input_file*, %struct.input_file** %4
store %struct.input_file* %16, %struct.input_file** %3
br label %29
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %24
23: ; preds = %17
store %struct.input_file* null, %struct.input_file** %3
br label %29
24: ; preds = %17
%25 = call i32 (...) @ensure_m4path()
%26 = load %struct.input_file*, %struct.input_file** %4
%27 = load i8*, i8** %5
%28 = call %struct.input_file* @dopath(%struct.input_file* %26, i8* %27)
store %struct.input_file* %28, %struct.input_file** %3
br label %29
29: ; preds = %24, %23, %11
%30 = load %struct.input_file*, %struct.input_file** %3
ret %struct.input_file* %30
}

LLVM IR (-O2):
%struct.input_file = type { i32 }
@.str = [2 x i8] c"r\00"
define %struct.input_file* @fopen_trypath(%struct.input_file* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @set_input(%struct.input_file* %0, i32* %3, i8* %1)
br label %13
7: ; preds = %2
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 47
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 (...) @ensure_m4path()
%12 = tail call %struct.input_file* @dopath(%struct.input_file* %0, i8* %1)
br label %13
13: ; preds = %7, %10, %5
%14 = phi %struct.input_file* [ %0, %5 ], [ %12, %10 ], [ null, %7 ]
ret %struct.input_file* %14
}