#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 *malloc(int);
char *package_name(char *path) {
  int last = 0;
  int i = 0;
  char c;
  int n = 0;
  while ((c = path[i]) != '\0') {
    if (c == '/') {
      if (path[i + 1] == '\0') {
        break;
      }
      n = 0;
      last = i + 1;
    } else {
      n++;
    }
    i++;
  }
  char *out = malloc(sizeof(char) * (n + 1));
  for (int i = 0; i < n; i++) {
    out[i] = path[last + i];
  }
  out[n] = '\0';
  return out;
}


x86 assembly (clang, -O0):
<package_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11a3 <package_name+0x93>
movsbl -0x11(%rbp),%eax
cmp    $0x2f,%eax
jne    118c <package_name+0x7c>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1177 <package_name+0x67>
jmp    11a3 <package_name+0x93>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1195 <package_name+0x85>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1131 <package_name+0x21>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11f6 <package_name+0xe6>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c1 <package_name+0xb1>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<package_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
mov    %rax,%r12
add    $0x1,%rax
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movzbl -0x1(%r14,%rax,1),%ecx
test   %cl,%cl
je     1167 <package_name+0x47>
cmp    $0x2f,%cl
je     1160 <package_name+0x40>
add    $0x1,%rax
add    $0x1,%rbx
jmp    1140 <package_name+0x20>
nopl   0x0(%rax)
cmpb   $0x0,(%r14,%rax,1)
jne    112d <package_name+0xd>
lea    0x1(%rbx),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
test   %ebx,%ebx
je     118a <package_name+0x6a>
movslq %r12d,%rax
add    %rax,%r14
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @package_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %6
br label %9
9: ; preds = %37, %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
store i8 %14, i8* %5
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %40
17: ; preds = %9
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 47
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i8*, i8** %2
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %21
br label %40
31: ; preds = %21
store i32 0, i32* %6
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %37
34: ; preds = %17
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %37
37: ; preds = %34, %31
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %9
40: ; preds = %30, %9
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = mul i64 1, %43
%45 = trunc i64 %44 to i32
%46 = call i8* @malloc(i32 %45)
store i8* %46, i8** %7
store i32 0, i32* %8
br label %47
47: ; preds = %63, %40
%48 = load i32, i32* %8
%49 = load i32, i32* %6
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %66
51: ; preds = %47
%52 = load i8*, i8** %2
%53 = load i32, i32* %3
%54 = load i32, i32* %8
%55 = add nsw i32 %53, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %52, i64 %56
%58 = load i8, i8* %57
%59 = load i8*, i8** %7
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 %58, i8* %62
br label %63
63: ; preds = %51
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %47
66: ; preds = %47
%67 = load i8*, i8** %7
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
store i8 0, i8* %70
%71 = load i8*, i8** %7
ret i8* %71
}

LLVM IR (-O2):
define noalias i8* @package_name(i8* nocapture %0) {
br label %2
2: ; preds = %9, %1
%3 = phi i64 [ %10, %9 ], [ 0, %1 ]
br label %4
4: ; preds = %2, %14
%5 = phi i64 [ %16, %14 ], [ %3, %2 ]
%6 = phi i32 [ %15, %14 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %5
%8 = load i8, i8* %7
switch i8 %8, label %14 [
i8 0, label %17
i8 47, label %9
]
9: ; preds = %4
%10 = add nuw i64 %5, 1
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %17, label %2
14: ; preds = %4
%15 = add nuw nsw i32 %6, 1
%16 = add nuw i64 %5, 1
br label %4
17: ; preds = %9, %4
%18 = add nuw nsw i32 %6, 1
%19 = tail call i8* @malloc(i32 %18)
%20 = icmp eq i32 %6, 0
br i1 %20, label %26, label %21
21: ; preds = %17
%22 = shl i64 %3, 32
%23 = ashr exact i64 %22, 32
%24 = getelementptr i8, i8* %0, i64 %23
%25 = zext i32 %6 to i64
br label %26
26: ; preds = %21, %17
%27 = zext i32 %6 to i64
%28 = getelementptr inbounds i8, i8* %19, i64 %27
store i8 0, i8* %28
ret i8* %19
}