#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);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *get_file_name(char *str) {
  char *p;
  int len;
  len = strlen(str) - sizeof(".conf") + 1;
  if (len <= 0)
    return NULL;
  if (strcmp(str + len, ".conf"))
    return NULL;
  if ((p = malloc(len + 1)) == NULL)
    return NULL;
  strncpy(p, str, len);
  p[len] = 0;
  return p;
}


x86 assembly (clang, -O0):
<get_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cltq
sub    $0x6,%rax
add    $0x1,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1179 <get_file_name+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <get_file_name+0xb1>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    0xe75(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11a7 <get_file_name+0x67>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <get_file_name+0xb1>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11cd <get_file_name+0x8d>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <get_file_name+0xb1>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    -0x5(%rbx),%ebp
test   %ebp,%ebp
jle    1170 <get_file_name+0x30>
mov    %ebp,%r15d
lea    (%r14,%r15,1),%rdi
lea    0xe9a(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1180 <get_file_name+0x40>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xfffffffc,%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1170 <get_file_name+0x30>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rbx,%r15,1)
jmp    1172 <get_file_name+0x32>

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

LLVM IR (-O2):
@.str = [6 x i8] c".conf\00"
define i8* @get_file_name(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add i32 %2, -5
%4 = icmp slt i32 %3, 1
br i1 %4, label %17, label %5
5: ; preds = %1
%6 = zext i32 %3 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %5
%11 = add i32 %2, -4
%12 = tail call i8* @malloc(i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = tail call i32 @strncpy(i8* %12, i8* %0, i32 %3)
%16 = getelementptr inbounds i8, i8* %12, i64 %6
store i8 0, i8* %16
br label %17
17: ; preds = %10, %5, %1, %14
%18 = phi i8* [ %12, %14 ], [ null, %1 ], [ null, %5 ], [ null, %10 ]
ret i8* %18
}