#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *strip_extension(const char *filename) {
  char *newname;
  char *c;
  if (!filename)
    return NULL;
  newname = (char *)malloc(strlen(filename) + 1);
  if (!newname)
    return NULL;
  strcpy(newname, filename);
  for (c = newname + strlen(newname) - 1; c >= newname; c--) {
    if (*c == '.') {
      *c = 0;
      break;
    }
    if (*c == '\\' || *c == '/' || *c == ':')
      break;
  }
  return newname;
}


x86 assembly (clang, -O0):
<strip_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <strip_extension+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1232 <strip_extension+0x102>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1183 <strip_extension+0x53>
movq   $0x0,-0x8(%rbp)
jmp    1232 <strip_extension+0x102>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     122a <strip_extension+0xfa>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11df <strip_extension+0xaf>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    122a <strip_extension+0xfa>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     120f <strip_extension+0xdf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     120f <strip_extension+0xdf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1214 <strip_extension+0xe4>
jmp    122a <strip_extension+0xfa>
jmp    1219 <strip_extension+0xe9>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11b5 <strip_extension+0x85>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_extension>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     119c <strip_extension+0x6c>
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     119c <strip_extension+0x6c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
nopl   (%rax)
cmp    %rbx,%rax
jb     119e <strip_extension+0x6e>
movzbl (%rax),%ecx
add    $0xffffffffffffffff,%rax
cmp    $0x39,%cl
jg     1190 <strip_extension+0x60>
cmp    $0x2e,%cl
je     11a9 <strip_extension+0x79>
cmp    $0x2f,%cl
jne    1170 <strip_extension+0x40>
jmp    119e <strip_extension+0x6e>
nopl   (%rax)
cmp    $0x3a,%cl
je     119e <strip_extension+0x6e>
cmp    $0x5c,%cl
jne    1170 <strip_extension+0x40>
jmp    119e <strip_extension+0x6e>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movb   $0x0,0x1(%rax)
jmp    119e <strip_extension+0x6e>

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

LLVM IR (-O2):
define i8* @strip_extension(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %21, label %9
9: ; preds = %3
%10 = tail call i32 @strcpy(i8* %7, i8* %0)
%11 = tail call i32 @strlen(i8* %7)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %7, i64 %12
br label %14
14: ; preds = %18, %9
%15 = phi i8* [ %13, %9 ], [ %16, %18 ]
%16 = getelementptr inbounds i8, i8* %15, i64 -1
%17 = icmp ult i8* %16, %7
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i8, i8* %16
switch i8 %19, label %14 [
i8 46, label %20
i8 92, label %21
i8 47, label %21
i8 58, label %21
]
20: ; preds = %18
store i8 0, i8* %16
br label %21
21: ; preds = %14, %18, %18, %18, %20, %3, %1
%22 = phi i8* [ null, %1 ], [ null, %3 ], [ %7, %20 ], [ %7, %18 ], [ %7, %18 ], [ %7, %18 ], [ %7, %14 ]
ret i8* %22
}