#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 *strchr(char const *, char);
int /*<<< orphan*/ strcmp(char const *, char *);
char *strrchr(char const *, char);
const char *stripped(const char *name, int num_components) {
  const char *basename;
  int i = 0;
  if (!strcmp(name, "/dev/null"))
    return name;
  basename = strrchr(name, '/');
  if (!basename)
    basename = name;
  else
    basename++;
  while (i < num_components && (name = strchr(name, '/')) != NULL) {
    while (*name == '/')
      name++;
    i++;
  }
  return name ? name : basename;
}


x86 assembly (clang, -O0):
<stripped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    116c <stripped+0x3c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1240 <stripped+0x110>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1196 <stripped+0x66>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11a2 <stripped+0x72>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a7 <stripped+0x77>
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x25(%rbp)
jge    11d4 <stripped+0xa4>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11e4 <stripped+0xb4>
jmp    1218 <stripped+0xe8>
jmp    11e9 <stripped+0xb9>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    120a <stripped+0xda>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11e9 <stripped+0xb9>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a7 <stripped+0x77>
cmpq   $0x0,-0x10(%rbp)
je     1230 <stripped+0x100>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1238 <stripped+0x108>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripped>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xebc(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11ad <stripped+0x7d>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%r14
test   %rax,%rax
cmove  %rbx,%r14
test   %r15d,%r15d
jle    11a6 <stripped+0x76>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11a4 <stripped+0x74>
mov    %rax,%rbx
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax)
cmpb   $0x2f,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     1190 <stripped+0x60>
add    $0x1,%ebp
cmp    %r15d,%ebp
jne    1170 <stripped+0x40>
jmp    11a6 <stripped+0x76>
xor    %ebx,%ebx
test   %rbx,%rbx
cmove  %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
define i8* @stripped(i8* %0, i32 %1) {
%3 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %28, label %5
5: ; preds = %2
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%7 = icmp eq i8* %6, null
%8 = getelementptr inbounds i8, i8* %6, i64 1
%9 = select i1 %7, i8* %0, i8* %8
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %24
11: ; preds = %5, %21
%12 = phi i32 [ %22, %21 ], [ 0, %5 ]
%13 = phi i8* [ %17, %21 ], [ %0, %5 ]
%14 = tail call i8* @strchr(i8* dereferenceable(1) %13, i8 signext 47)
%15 = icmp eq i8* %14, null
br i1 %15, label %24, label %16
16: ; preds = %11, %16
%17 = phi i8* [ %20, %16 ], [ %14, %11 ]
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 47
%20 = getelementptr inbounds i8, i8* %17, i64 1
br i1 %19, label %16, label %21
21: ; preds = %16
%22 = add nuw nsw i32 %12, 1
%23 = icmp eq i32 %22, %1
br i1 %23, label %24, label %11
24: ; preds = %11, %21, %5
%25 = phi i8* [ %0, %5 ], [ %17, %21 ], [ null, %11 ]
%26 = icmp eq i8* %25, null
%27 = select i1 %26, i8* %9, i8* %25
br label %28
28: ; preds = %2, %24
%29 = phi i8* [ %27, %24 ], [ %0, %2 ]
ret i8* %29
}