#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 sfs_fs {
  int dummy;
};
struct cache_inode {
  int dummy;
};
typedef int /*<<< orphan*/ ino_t;

/* Variables and functions */
int /*<<< orphan*/ add_entry(struct sfs_fs *, struct cache_inode *,
                             struct cache_inode *, char const *);
struct cache_inode *alloc_cache_inode(struct sfs_fs *, int /*<<< orphan*/,
                                      int /*<<< orphan*/, int);
int /*<<< orphan*/ open_file(struct sfs_fs *, struct cache_inode *,
                             char const *, int);
struct cache_inode *search_cache_inode(struct sfs_fs *, int /*<<< orphan*/);
void add_file(struct sfs_fs *sfs, struct cache_inode *current,
              const char *filename, int fd, ino_t real) {
  struct cache_inode *file;
  if ((file = search_cache_inode(sfs, real)) == NULL) {
    file = alloc_cache_inode(sfs, real, 0, 1);
    open_file(sfs, file, filename, fd);
  }
  add_entry(sfs, current, file, filename);
}


x86 assembly (clang, -O0):
<add_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1030 <search_cache_inode@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a0 <add_file+0x60>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1060 <alloc_cache_inode@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <open_file@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1050 <add_entry@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r13d
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %r8d,%esi
call   1030 <search_cache_inode@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1190 <add_file+0x50>
mov    %rbx,%rdi
mov    %r13d,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1060 <alloc_cache_inode@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r15,%rdx
mov    %r12d,%ecx
call   1040 <open_file@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <add_entry@plt>

LLVM IR (-O0):
%struct.sfs_fs = type { i32 }
%struct.cache_inode = type { i32 }
define void @add_file(%struct.sfs_fs* %0, %struct.cache_inode* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca %struct.sfs_fs*
%7 = alloca %struct.cache_inode*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.cache_inode*
store %struct.sfs_fs* %0, %struct.sfs_fs** %6
store %struct.cache_inode* %1, %struct.cache_inode** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load %struct.sfs_fs*, %struct.sfs_fs** %6
%13 = load i32, i32* %10
%14 = call %struct.cache_inode* @search_cache_inode(%struct.sfs_fs* %12, i32 %13)
store %struct.cache_inode* %14, %struct.cache_inode** %11
%15 = icmp eq %struct.cache_inode* %14, null
br i1 %15, label %16, label %25
16: ; preds = %5
%17 = load %struct.sfs_fs*, %struct.sfs_fs** %6
%18 = load i32, i32* %10
%19 = call %struct.cache_inode* @alloc_cache_inode(%struct.sfs_fs* %17, i32 %18, i32 0, i32 1)
store %struct.cache_inode* %19, %struct.cache_inode** %11
%20 = load %struct.sfs_fs*, %struct.sfs_fs** %6
%21 = load %struct.cache_inode*, %struct.cache_inode** %11
%22 = load i8*, i8** %8
%23 = load i32, i32* %9
%24 = call i32 @open_file(%struct.sfs_fs* %20, %struct.cache_inode* %21, i8* %22, i32 %23)
br label %25
25: ; preds = %16, %5
%26 = load %struct.sfs_fs*, %struct.sfs_fs** %6
%27 = load %struct.cache_inode*, %struct.cache_inode** %7
%28 = load %struct.cache_inode*, %struct.cache_inode** %11
%29 = load i8*, i8** %8
%30 = call i32 @add_entry(%struct.sfs_fs* %26, %struct.cache_inode* %27, %struct.cache_inode* %28, i8* %29)
ret void
}

LLVM IR (-O2):
%struct.sfs_fs = type { i32 }
%struct.cache_inode = type { i32 }
define void @add_file(%struct.sfs_fs* %0, %struct.cache_inode* %1, i8* %2, i32 %3, i32 %4) {
%6 = tail call %struct.cache_inode* @search_cache_inode(%struct.sfs_fs* %0, i32 %4)
%7 = icmp eq %struct.cache_inode* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call %struct.cache_inode* @alloc_cache_inode(%struct.sfs_fs* %0, i32 %4, i32 0, i32 1)
%10 = tail call i32 @open_file(%struct.sfs_fs* %0, %struct.cache_inode* %9, i8* %2, i32 %3)
br label %11
11: ; preds = %8, %5
%12 = phi %struct.cache_inode* [ %9, %8 ], [ %6, %5 ]
%13 = tail call i32 @add_entry(%struct.sfs_fs* %0, %struct.cache_inode* %1, %struct.cache_inode* %12, i8* %2)
ret void
}