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

/* Variables and functions */
scalar_t__ fatfs_open(char *, int /*<<< orphan*/);
struct fnode *fno_create_file(char *);
struct fnode *fno_search(char *);
int /*<<< orphan*/ path_abs(char *, char *, int);
struct fnode *vfs_open(void *arg1, uint32_t arg2) {
  char *rel_path = (char *)arg1;
  struct fnode *f;
  uint32_t flags = arg2;
  char path[64];
  char ppath[64];
  int ret;
  path_abs(rel_path, path, 64);
  f = fno_search(path);
  if (f) {
    if (fatfs_open(path, flags))
      return f;
  }
  f = fno_create_file(path);
  if (f) {
    if (fatfs_open(path, flags))
      return f;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<vfs_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x40,%edx
call   1060 <path_abs@plt>
lea    -0x70(%rbp),%rdi
call   1030 <fno_search@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11b2 <vfs_open+0x72>
lea    -0x70(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <fatfs_open@plt>
cmp    $0x0,%rax
je     11ad <vfs_open+0x6d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <vfs_open+0xba>
jmp    11b2 <vfs_open+0x72>
lea    -0x70(%rbp),%rdi
call   1050 <fno_create_file@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11f2 <vfs_open+0xb2>
lea    -0x70(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <fatfs_open@plt>
cmp    $0x0,%rax
je     11ed <vfs_open+0xad>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <vfs_open+0xba>
jmp    11f2 <vfs_open+0xb2>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vfs_open>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %esi,%ebp
mov    %rsp,%rbx
mov    %rbx,%rsi
mov    $0x40,%edx
call   1060 <path_abs@plt>
mov    %rbx,%rdi
call   1030 <fno_search@plt>
test   %rax,%rax
je     1177 <vfs_open+0x37>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    %ebp,%esi
call   1040 <fatfs_open@plt>
test   %rax,%rax
jne    1198 <vfs_open+0x58>
mov    %rsp,%rdi
call   1050 <fno_create_file@plt>
test   %rax,%rax
je     1196 <vfs_open+0x56>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    %ebp,%esi
call   1040 <fatfs_open@plt>
test   %rax,%rax
jne    1198 <vfs_open+0x58>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.fnode = type { i32 }
define %struct.fnode* @vfs_open(i8* %0, i32 %1) {
%3 = alloca %struct.fnode*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.fnode*
%8 = alloca i32
%9 = alloca [64 x i8]
%10 = alloca [64 x i8]
%11 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%12 = load i8*, i8** %4
store i8* %12, i8** %6
%13 = load i32, i32* %5
store i32 %13, i32* %8
%14 = load i8*, i8** %6
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%16 = call i32 @path_abs(i8* %14, i8* %15, i32 64)
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%18 = call %struct.fnode* @fno_search(i8* %17)
store %struct.fnode* %18, %struct.fnode** %7
%19 = load %struct.fnode*, %struct.fnode** %7
%20 = icmp ne %struct.fnode* %19, null
br i1 %20, label %21, label %29
21: ; preds = %2
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%23 = load i32, i32* %8
%24 = call i64 @fatfs_open(i8* %22, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = load %struct.fnode*, %struct.fnode** %7
store %struct.fnode* %27, %struct.fnode** %3
br label %43
28: ; preds = %21
br label %29
29: ; preds = %28, %2
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%31 = call %struct.fnode* @fno_create_file(i8* %30)
store %struct.fnode* %31, %struct.fnode** %7
%32 = load %struct.fnode*, %struct.fnode** %7
%33 = icmp ne %struct.fnode* %32, null
br i1 %33, label %34, label %42
34: ; preds = %29
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%36 = load i32, i32* %8
%37 = call i64 @fatfs_open(i8* %35, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = load %struct.fnode*, %struct.fnode** %7
store %struct.fnode* %40, %struct.fnode** %3
br label %43
41: ; preds = %34
br label %42
42: ; preds = %41, %29
store %struct.fnode* null, %struct.fnode** %3
br label %43
43: ; preds = %42, %39, %26
%44 = load %struct.fnode*, %struct.fnode** %3
ret %struct.fnode* %44
}

LLVM IR (-O2):
%struct.fnode = type { i32 }
define %struct.fnode* @vfs_open(i8* %0, i32 %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i32 @path_abs(i8* %0, i8* %4, i32 64)
%6 = call %struct.fnode* @fno_search(i8* %4)
%7 = icmp eq %struct.fnode* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = call i64 @fatfs_open(i8* %4, i32 %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %8, %2
%12 = call %struct.fnode* @fno_create_file(i8* %4)
%13 = icmp eq %struct.fnode* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i64 @fatfs_open(i8* %4, i32 %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14, %11
br label %18
18: ; preds = %14, %8, %17
%19 = phi %struct.fnode* [ null, %17 ], [ %6, %8 ], [ %12, %14 ]
ret %struct.fnode* %19
}