#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 *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *sfindductype(char filepath[]) {
  int len = strlen(filepath);
  int i;
  char *cp;
  char *type;
  for (i = len; i > 0; i--) {
    if (filepath[i] == '/') {
      return NULL;
    } else if (filepath[i] == '.') {
      cp = (char *)((int)filepath + i + 1);
      type = malloc(strlen(cp) + 1);
      strcpy(type, cp);
      if (((cp = strchr(type, '%')) != NULL) ||
          ((cp = strchr(type, '%')) != NULL)) {
        cp[0] = '\0';
      }
      return type;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<sfindductype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1237 <sfindductype+0xf7>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    118a <sfindductype+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    123f <sfindductype+0xff>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    121f <sfindductype+0xdf>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    $0x25,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    120b <sfindductype+0xcb>
mov    -0x28(%rbp),%rdi
mov    $0x25,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1212 <sfindductype+0xd2>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123f <sfindductype+0xff>
jmp    1224 <sfindductype+0xe4>
jmp    1229 <sfindductype+0xe9>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    115e <sfindductype+0x1e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sfindductype>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1040 <strlen@plt>
test   %eax,%eax
jle    118f <sfindductype+0x4f>
mov    %eax,%ecx
lea    (%r15,%rax,1),%ebx
add    $0x1,%ebx
shl    $0x20,%rbx
add    $0x1,%rcx
xor    %r14d,%r14d
movabs $0xffffffff00000000,%rax
ff ff ff
nop
movzbl -0x1(%r15,%rcx,1),%edx
cmp    $0x2f,%dl
je     11cb <sfindductype+0x8b>
cmp    $0x2e,%dl
je     1194 <sfindductype+0x54>
add    %rax,%rbx
add    $0xffffffffffffffff,%rcx
cmp    $0x1,%rcx
jg     1170 <sfindductype+0x30>
jmp    11cb <sfindductype+0x8b>
xor    %r14d,%r14d
jmp    11cb <sfindductype+0x8b>
sar    $0x20,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    $0x25,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11cb <sfindductype+0x8b>
movb   $0x0,(%rax)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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