#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;
int _fno_fullpath(struct fnode *, char *, char **, int);
int strlen(char *);
int fno_fullpath(struct fnode *f, char *dst, int len) {
  char *p = NULL;
  int ret;
  ret = _fno_fullpath(f, dst, &p, len);
  if (ret == 0) {
    int nlen = strlen(dst);
    if (nlen > 1) {
      dst[--nlen] = '\0';
      while (dst[nlen - 1] == '/') {
        dst[nlen - 1] = '\0';
        nlen--;
      }
    }
    return nlen;
  }
  return -ENOENT;
}


x86 assembly (clang, -O0):
<fno_fullpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
lea    -0x28(%rbp),%rdx
call   1040 <_fno_fullpath@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11cf <fno_fullpath+0xaf>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x1,-0x30(%rbp)
jle    11c4 <fno_fullpath+0xa4>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x30(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11bf <fno_fullpath+0x9f>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    1186 <fno_fullpath+0x66>
jmp    11c4 <fno_fullpath+0xa4>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11dd <fno_fullpath+0xbd>
xor    %eax,%eax
mov    0x2e00(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fno_fullpath>:
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ecx
mov    %rsi,%rbx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdx
call   1040 <_fno_fullpath@plt>
test   %eax,%eax
je     114e <fno_fullpath+0x2e>
mov    0x2e90(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    1190 <fno_fullpath+0x70>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     1190 <fno_fullpath+0x70>
mov    %eax,%ecx
lea    -0x1(%rcx),%eax
movb   $0x0,(%rbx,%rax,1)
lea    -0x2(%rcx),%edx
cmpb   $0x2f,(%rbx,%rdx,1)
jne    1190 <fno_fullpath+0x70>
add    %rdx,%rbx
add    $0xffffffff,%ecx
mov    %ecx,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,(%rbx)
add    $0xffffffff,%eax
cmpb   $0x2f,-0x1(%rbx)
lea    -0x1(%rbx),%rbx
je     1180 <fno_fullpath+0x60>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.fnode = type { i32 }
@ENOENT = global i32 0
define i32 @fno_fullpath(%struct.fnode* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.fnode*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store %struct.fnode* %0, %struct.fnode** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* null, i8** %8
%11 = load %struct.fnode*, %struct.fnode** %5
%12 = load i8*, i8** %6
%13 = load i32, i32* %7
%14 = call i32 @_fno_fullpath(%struct.fnode* %11, i8* %12, i8** %8, i32 %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %48
17: ; preds = %3
%18 = load i8*, i8** %6
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %10
%20 = load i32, i32* %10
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %46
22: ; preds = %17
%23 = load i8*, i8** %6
%24 = load i32, i32* %10
%25 = add nsw i32 %24, -1
store i32 %25, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %37, %22
%29 = load i8*, i8** %6
%30 = load i32, i32* %10
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 47
br i1 %36, label %37, label %45
37: ; preds = %28
%38 = load i8*, i8** %6
%39 = load i32, i32* %10
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
store i8 0, i8* %42
%43 = load i32, i32* %10
%44 = add nsw i32 %43, -1
store i32 %44, i32* %10
br label %28
45: ; preds = %28
br label %46
46: ; preds = %45, %17
%47 = load i32, i32* %10
store i32 %47, i32* %4
br label %51
48: ; preds = %3
%49 = load i32, i32* @ENOENT
%50 = sub nsw i32 0, %49
store i32 %50, i32* %4
br label %51
51: ; preds = %48, %46
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
%struct.fnode = type { i32 }
@ENOENT = global i32 0
define i32 @fno_fullpath(%struct.fnode* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = call i32 @_fno_fullpath(%struct.fnode* %0, i8* %1, i8** %4, i32 %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %3
%9 = call i32 @strlen(i8* %1)
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %32
11: ; preds = %8
%12 = add nsw i32 %9, -1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 0, i8* %14
%15 = add nsw i32 %9, -2
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 47
br i1 %19, label %20, label %32
20: ; preds = %11, %20
%21 = phi i64 [ %23, %20 ], [ %16, %11 ]
%22 = phi i8* [ %24, %20 ], [ %17, %11 ]
store i8 0, i8* %22
%23 = add i64 %21, -1
%24 = getelementptr inbounds i8, i8* %1, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 47
br i1 %26, label %20, label %30
27: ; preds = %3
%28 = load i32, i32* @ENOENT
%29 = sub nsw i32 0, %28
br label %32
30: ; preds = %20
%31 = trunc i64 %21 to i32
br label %32
32: ; preds = %30, %11, %8, %27
%33 = phi i32 [ %29, %27 ], [ %9, %8 ], [ %12, %11 ], [ %31, %30 ]
ret i32 %33
}