#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ logmsg(int, char *, char const *);
char *strdup(char const *);
size_t strlen(char const *);
int tfs_getldt_fn(const char *cache_fn, char **meta_fn) {
  size_t len = strlen(cache_fn);
  if (len < 5) {
    logmsg(1, "tfs_getldt_fn - cache file name [%s] is too short.", cache_fn);
    return EXIT_FAILURE;
  }
  *meta_fn = strdup(cache_fn);
  if (*meta_fn == NULL) {
    logmsg(1,
           "tfs_getldt_fn - unable to allocate memory for meta_fn name based "
           "on [%s]",
           cache_fn);
    return EXIT_FAILURE;
  }
  (*meta_fn)[len - 3] = 'd';
  (*meta_fn)[len - 2] = 'f';
  (*meta_fn)[len - 1] = 's';
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<tfs_getldt_fn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x5,-0x20(%rbp)
jae    117e <tfs_getldt_fn+0x4e>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe98(%rip),%rsi
call   1040 <logmsg@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120a <tfs_getldt_fn+0xda>
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11c5 <tfs_getldt_fn+0x95>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe84(%rip),%rsi
call   1040 <logmsg@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120a <tfs_getldt_fn+0xda>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
sub    $0x3,%rcx
movb   $0x64,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
sub    $0x2,%rcx
movb   $0x66,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x73,(%rax,%rcx,1)
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tfs_getldt_fn>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x4,%rax
ja     114f <tfs_getldt_fn+0x1f>
lea    0xeb3(%rip),%rsi
jmp    117e <tfs_getldt_fn+0x4e>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1177 <tfs_getldt_fn+0x47>
movw   $0x6664,-0x3(%rbx,%rax,1)
movb   $0x73,-0x1(%rbx,%rax,1)
mov    0x2e63(%rip),%rax
jmp    1192 <tfs_getldt_fn+0x62>
lea    0xeb5(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   1040 <logmsg@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [51 x i8] c"tfs_getldt_fn - cache file name [%s] is too short.\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [73 x i8] c"tfs_getldt_fn - unable to allocate memory for meta_fn name based on [%s]\00"
@EXIT_SUCCESS = global i32 0
define i32 @tfs_getldt_fn(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp ult i64 %9, 5
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32 @logmsg(i32 1, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %43
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i8* @strdup(i8* %16)
%18 = load i8**, i8*** %5
store i8* %17, i8** %18
%19 = load i8**, i8*** %5
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i8*, i8** %4
%24 = call i32 @logmsg(i32 1, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
store i32 %25, i32* %3
br label %43
26: ; preds = %15
%27 = load i8**, i8*** %5
%28 = load i8*, i8** %27
%29 = load i64, i64* %6
%30 = sub i64 %29, 3
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 100, i8* %31
%32 = load i8**, i8*** %5
%33 = load i8*, i8** %32
%34 = load i64, i64* %6
%35 = sub i64 %34, 2
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 102, i8* %36
%37 = load i8**, i8*** %5
%38 = load i8*, i8** %37
%39 = load i64, i64* %6
%40 = sub i64 %39, 1
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 115, i8* %41
%42 = load i32, i32* @EXIT_SUCCESS
store i32 %42, i32* %3
br label %43
43: ; preds = %26, %22, %11
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [51 x i8] c"tfs_getldt_fn - cache file name [%s] is too short.\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [73 x i8] c"tfs_getldt_fn - unable to allocate memory for meta_fn name based on [%s]\00"
@EXIT_SUCCESS = global i32 0
define i32 @tfs_getldt_fn(i8* %0, i8** nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = icmp ult i64 %3, 5
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @logmsg(i32 1, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %19
7: ; preds = %2
%8 = tail call i8* @strdup(i8* %0)
store i8* %8, i8** %1
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @logmsg(i32 1, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %19
12: ; preds = %7
%13 = add i64 %3, -3
%14 = getelementptr inbounds i8, i8* %8, i64 %13
store i8 100, i8* %14
%15 = add i64 %3, -2
%16 = getelementptr inbounds i8, i8* %8, i64 %15
store i8 102, i8* %16
%17 = add i64 %3, -1
%18 = getelementptr inbounds i8, i8* %8, i64 %17
store i8 115, i8* %18
br label %19
19: ; preds = %12, %10, %5
%20 = phi i32* [ @EXIT_FAILURE, %5 ], [ @EXIT_FAILURE, %10 ], [ @EXIT_SUCCESS, %12 ]
%21 = load i32, i32* %20
ret i32 %21
}