#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 /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int get_template_from_name(char *t, char *s) {
  int i, e = 0;
  int l = strlen(s);
  for (i = l; i >= 0; i--) {
    if (s[i] == '/') {
      e = i;
      break;
    }
  }
  if (e != 0) {
    strncpy(t, s, e + 1);
    t[e + 1] = '\0';
    strcat(t, "*");
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_template_from_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1196 <get_template_from_name+0x66>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1183 <get_template_from_name+0x53>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1196 <get_template_from_name+0x66>
jmp    1188 <get_template_from_name+0x58>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1159 <get_template_from_name+0x29>
cmpl   $0x0,-0x20(%rbp)
je     11e0 <get_template_from_name+0xb0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1050 <strcat@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <get_template_from_name+0xb7>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_template_from_name>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    $0xffffffff,%eax
test   %ebx,%ebx
js     118e <get_template_from_name+0x5e>
xchg   %ax,%ax
mov    %ebx,%ecx
cmpb   $0x2f,(%r15,%rcx,1)
je     1164 <get_template_from_name+0x34>
lea    -0x1(%rbx),%ecx
test   %ebx,%ebx
mov    %ecx,%ebx
jg     1150 <get_template_from_name+0x20>
jmp    118e <get_template_from_name+0x5e>
test   %ebx,%ebx
je     118e <get_template_from_name+0x5e>
add    $0x1,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
lea    0xe7c(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"*\00"
define i32 @get_template_from_name(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
store i32 %11, i32* %6
br label %12
12: ; preds = %26, %2
%13 = load i32, i32* %6
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = load i32, i32* %6
store i32 %24, i32* %7
br label %29
25: ; preds = %15
br label %26
26: ; preds = %25
%27 = load i32, i32* %6
%28 = add nsw i32 %27, -1
store i32 %28, i32* %6
br label %12
29: ; preds = %23, %12
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %45
32: ; preds = %29
%33 = load i8*, i8** %4
%34 = load i8*, i8** %5
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
%37 = call i32 @strncpy(i8* %33, i8* %34, i32 %36)
%38 = load i8*, i8** %4
%39 = load i32, i32* %7
%40 = add 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 i8*, i8** %4
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %46
45: ; preds = %29
store i32 -1, i32* %3
br label %46
46: ; preds = %45, %32
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [2 x i8] c"*\00"
define i32 @get_template_from_name(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %22
5: ; preds = %2, %11
%6 = phi i32 [ %12, %11 ], [ %3, %2 ]
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 47
br i1 %10, label %14, label %11
11: ; preds = %5
%12 = add nsw i32 %6, -1
%13 = icmp sgt i32 %6, 0
br i1 %13, label %5, label %22
14: ; preds = %5
%15 = icmp eq i32 %6, 0
br i1 %15, label %22, label %16
16: ; preds = %14
%17 = add nuw nsw i32 %6, 1
%18 = tail call i32 @strncpy(i8* %0, i8* %1, i32 %17)
%19 = zext i32 %17 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 0, i8* %20
%21 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %11, %2, %14, %16
%23 = phi i32 [ 0, %16 ], [ -1, %14 ], [ -1, %2 ], [ -1, %11 ]
ret i32 %23
}