#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 */

/* Variables and functions */
int strlen(char *);
char *strrchr(char *, char);
int set_dir_name_length(char *pathname, int *dir_name_length) {
  unsigned int s;
  char *p;
  s = strlen(pathname);
  if (*(pathname + s - 1) == '/')
    *(pathname + s - 1) = 0;
  if ((p = strrchr(pathname, '/')) == NULL)
    return -1;
  *p = 0;
  *dir_name_length = strlen(pathname) + 1;
  *p = '/';
  return 0;
}


x86 assembly (clang, -O0):
<set_dir_name_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl -0x1(%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    115d <set_dir_name_length+0x3d>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x0,-0x1(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1185 <set_dir_name_length+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <set_dir_name_length+0x8e>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x2f,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_dir_name_length>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%eax
cmpb   $0x2f,-0x1(%rbx,%rax,1)
jne    113e <set_dir_name_length+0x1e>
movb   $0x0,-0x1(%rbx,%rax,1)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     116c <set_dir_name_length+0x4c>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,(%r14)
movb   $0x2f,(%r15)
xor    %eax,%eax
jmp    1171 <set_dir_name_length+0x51>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @set_dir_name_length(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i8*, i8** %4
%11 = load i32, i32* %6
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 -1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 47
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = load i32, i32* %6
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = getelementptr inbounds i8, i8* %22, i64 -1
store i8 0, i8* %23
br label %24
24: ; preds = %18, %2
%25 = load i8*, i8** %4
%26 = call i8* @strrchr(i8* %25, i8 signext 47)
store i8* %26, i8** %7
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 -1, i32* %3
br label %36
29: ; preds = %24
%30 = load i8*, i8** %7
store i8 0, i8* %30
%31 = load i8*, i8** %4
%32 = call i32 @strlen(i8* %31)
%33 = add nsw i32 %32, 1
%34 = load i32*, i32** %5
store i32 %33, i32* %34
%35 = load i8*, i8** %7
store i8 47, i8* %35
store i32 0, i32* %3
br label %36
36: ; preds = %29, %28
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @set_dir_name_length(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = getelementptr inbounds i8, i8* %5, i64 -1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 47
br i1 %8, label %9, label %10
9: ; preds = %2
store i8 0, i8* %6
br label %10
10: ; preds = %9, %2
%11 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
store i8 0, i8* %11
%14 = tail call i32 @strlen(i8* %0)
%15 = add nsw i32 %14, 1
store i32 %15, i32* %1
store i8 47, i8* %11
br label %16
16: ; preds = %10, %13
%17 = phi i32 [ 0, %13 ], [ -1, %10 ]
ret i32 %17
}