#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 */
char *rindex(char *, char);
int /*<<< orphan*/ strip_trailing_slashes(char *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char *line;
  if (argc == 2) {
    strip_trailing_slashes(argv[1]);
    line = rindex(argv[1], '/');
    if (line == NULL) {
      line = ".";
    } else {
      while (line > argv[1] && *line == '/')
        --line;
      line[1] = 0;
      line = argv[1];
    }
    write(1, line, strlen(line));
    write(1, "\n", 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1233 <main+0xf3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strip_trailing_slashes@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x2f,%esi
call   1050 <rindex@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119e <main+0x5e>
lea    0xe6b(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11ff <main+0xbf>
jmp    11a3 <main+0x63>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
xor    %eax,%eax
cmp    0x8(%rdx),%rcx
mov    %al,-0x19(%rbp)
jbe    11ca <main+0x8a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11da <main+0x9a>
jmp    11eb <main+0xab>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11a3 <main+0x63>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    $0x1,%edx
lea    0xdd6(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x2,%edi
jne    11c0 <main+0x80>
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <strip_trailing_slashes@plt>
mov    0x8(%rbx),%rdi
mov    $0x2f,%esi
call   1050 <rindex@plt>
test   %rax,%rax
je     118b <main+0x4b>
mov    0x8(%rbx),%rcx
cmp    %rcx,%rax
jbe    1181 <main+0x41>
xchg   %ax,%ax
cmpb   $0x2f,(%rax)
jne    1181 <main+0x41>
add    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
ja     1170 <main+0x30>
mov    %rcx,%rax
movb   $0x0,0x1(%rax)
mov    0x8(%rbx),%rbx
jmp    1192 <main+0x52>
lea    0xe6e(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe52(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
pop    %rbx
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %50
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strip_trailing_slashes(i8* %12)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i8* @rindex(i8* %16, i8 signext 47)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %9
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
br label %44
21: ; preds = %9
br label %22
22: ; preds = %35, %21
%23 = load i8*, i8** %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = icmp ugt i8* %23, %26
br i1 %27, label %28, label %33
28: ; preds = %22
%29 = load i8*, i8** %6
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 47
br label %33
33: ; preds = %28, %22
%34 = phi i1 [ false, %22 ], [ %32, %28 ]
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i32 -1
store i8* %37, i8** %6
br label %22
38: ; preds = %33
%39 = load i8*, i8** %6
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8 0, i8* %40
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
store i8* %43, i8** %6
br label %44
44: ; preds = %38, %20
%45 = load i8*, i8** %6
%46 = load i8*, i8** %6
%47 = call i32 @strlen(i8* %46)
%48 = call i32 @write(i32 1, i8* %45, i32 %47)
%49 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %50
50: ; preds = %44, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %35
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @strip_trailing_slashes(i8* %6)
%8 = load i8*, i8** %5
%9 = tail call i8* @rindex(i8* %8, i8 signext 47)
%10 = ptrtoint i8* %9 to i64
%11 = icmp eq i8* %9, null
br i1 %11, label %30, label %12
12: ; preds = %4
%13 = load i8*, i8** %5
%14 = icmp ugt i8* %9, %13
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = ptrtoint i8* %13 to i64
%17 = sub i64 %16, %10
%18 = getelementptr i8, i8* %9, i64 %17
br label %19
19: ; preds = %15, %23
%20 = phi i8* [ %24, %23 ], [ %9, %15 ]
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 47
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = getelementptr inbounds i8, i8* %20, i64 -1
%25 = icmp ugt i8* %24, %13
br i1 %25, label %19, label %26
26: ; preds = %19, %23, %12
%27 = phi i8* [ %9, %12 ], [ %18, %23 ], [ %20, %19 ]
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8 0, i8* %28
%29 = load i8*, i8** %5
br label %30
30: ; preds = %4, %26
%31 = phi i8* [ %29, %26 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %4 ]
%32 = tail call i32 @strlen(i8* %31)
%33 = tail call i32 @write(i32 1, i8* %31, i32 %32)
%34 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %35
35: ; preds = %30, %2
ret i32 0
}