#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 fnode {
  int dummy;
};

/* Variables and functions */
int ENOENT;
struct fnode *fno_search(char *);
int /*<<< orphan*/ fno_unlink(struct fnode *);
int /*<<< orphan*/ path_abs(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int vfs_unlink(void *arg1) {
  char *path = (char *)arg1;
  printf("Trying to rm %s\n", path);
  char abs_p[64];
  struct fnode *f;
  path_abs(path, abs_p, 64);
  f = fno_search(path);
  if (f) {
    fno_unlink(f);
    return 0;
  }
  return -ENOENT;
}


x86 assembly (clang, -O0):
<vfs_unlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x40,%edx
call   1050 <path_abs@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fno_search@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     11a3 <vfs_unlink+0x63>
mov    -0x68(%rbp),%rdi
call   1060 <fno_unlink@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <vfs_unlink+0x71>
xor    %eax,%eax
mov    0x2e2c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vfs_unlink>:
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
lea    0xeb1(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x40,%edx
call   1050 <path_abs@plt>
mov    %rbx,%rdi
call   1040 <fno_search@plt>
test   %rax,%rax
je     1180 <vfs_unlink+0x40>
mov    %rax,%rdi
call   1060 <fno_unlink@plt>
xor    %eax,%eax
jmp    118b <vfs_unlink+0x4b>
mov    0x2e51(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.fnode = type { i32 }
@.str = [17 x i8] c"Trying to rm %s\0A\00"
@ENOENT = global i32 0
define i32 @vfs_unlink(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [64 x i8]
%6 = alloca %struct.fnode*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %4
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%12 = call i32 @path_abs(i8* %10, i8* %11, i32 64)
%13 = load i8*, i8** %4
%14 = call %struct.fnode* @fno_search(i8* %13)
store %struct.fnode* %14, %struct.fnode** %6
%15 = load %struct.fnode*, %struct.fnode** %6
%16 = icmp ne %struct.fnode* %15, null
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load %struct.fnode*, %struct.fnode** %6
%19 = call i32 @fno_unlink(%struct.fnode* %18)
store i32 0, i32* %2
br label %23
20: ; preds = %1
%21 = load i32, i32* @ENOENT
%22 = sub nsw i32 0, %21
store i32 %22, i32* %2
br label %23
23: ; preds = %20, %17
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.fnode = type { i32 }
@.str = [17 x i8] c"Trying to rm %s\0A\00"
@ENOENT = global i32 0
define i32 @vfs_unlink(i8* %0) {
%2 = alloca [64 x i8]
%3 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = call i32 @path_abs(i8* %0, i8* %4, i32 64)
%6 = call %struct.fnode* @fno_search(i8* %0)
%7 = icmp eq %struct.fnode* %6, null
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 @fno_unlink(%struct.fnode* %6)
br label %13
10: ; preds = %1
%11 = load i32, i32* @ENOENT
%12 = sub nsw i32 0, %11
br label %13
13: ; preds = %10, %8
%14 = phi i32 [ 0, %8 ], [ %12, %10 ]
ret i32 %14
}