#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 *basename(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
char *get_file_name_without_ext(char *file_name) {
  char *base_file_name = NULL;
  char *file_name_without_ext = NULL;
  int basename_len = 0, i = 0, file_name_without_ext_len = 0;
  base_file_name = basename(file_name);
  basename_len = strlen(base_file_name);
  for (i = basename_len; i > 0; i--) {
    if (base_file_name[i] == '.')
      break;
  }
  file_name_without_ext_len = basename_len - (basename_len - i);
  file_name_without_ext =
      (char *)malloc(sizeof(char) * (file_name_without_ext_len + 1));
  memcpy(file_name_without_ext, base_file_name, file_name_without_ext_len);
  file_name_without_ext[file_name_without_ext_len] = '\0';
  return file_name_without_ext;
}


x86 assembly (clang, -O0):
<get_file_name_without_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <basename@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    11c7 <get_file_name_without_ext+0x87>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11b4 <get_file_name_without_ext+0x74>
jmp    11c7 <get_file_name_without_ext+0x87>
jmp    11b9 <get_file_name_without_ext+0x79>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1190 <get_file_name_without_ext+0x50>
mov    -0x1c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    -0x20(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_name_without_ext>:
push   %r15
push   %r14
push   %rbx
call   1040 <basename@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1175 <get_file_name_without_ext+0x35>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
cmpb   $0x2e,(%r14,%rax,1)
je     1175 <get_file_name_without_ext+0x35>
lea    -0x1(%rbx),%eax
cmp    $0x1,%ebx
mov    %eax,%ebx
jg     1160 <get_file_name_without_ext+0x20>
xor    %ebx,%ebx
lea    0x1(%rbx),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @get_file_name_without_ext(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %3
store i8* null, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = load i8*, i8** %2
%9 = call i8* @basename(i8* %8)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
store i32 %12, i32* %6
br label %13
13: ; preds = %26, %1
%14 = load i32, i32* %6
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 46
br i1 %23, label %24, label %25
24: ; preds = %16
br label %29
25: ; preds = %16
br label %26
26: ; preds = %25
%27 = load i32, i32* %6
%28 = add nsw i32 %27, -1
store i32 %28, i32* %6
br label %13
29: ; preds = %24, %13
%30 = load i32, i32* %5
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = sub nsw i32 %31, %32
%34 = sub nsw i32 %30, %33
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = mul i64 1, %37
%39 = trunc i64 %38 to i32
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %4
%42 = load i8*, i8** %4
%43 = load i8*, i8** %3
%44 = load i32, i32* %7
%45 = call i32 @memcpy(i8* %42, i8* %43, i32 %44)
%46 = load i8*, i8** %4
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
%50 = load i8*, i8** %4
ret i8* %50
}

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