#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 */
typedef int /*<<< orphan*/ name;

/* Variables and functions */
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void dbf_getmemofilename(const char *file_dbf, char *buf, int buf_len) {
  char name[4096];
  int len;
  strncpy(name, file_dbf, sizeof(name));
  len = strlen(name) - 1;
  if (len)
    switch (name[len]) {
    case 'F':
      name[len] = 'T';
      break;
    default:
    case 'f':
      name[len] = 't';
      break;
    }
  strncpy(buf, name, buf_len);
}


x86 assembly (clang, -O0):
<dbf_getmemofilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <strncpy@plt>
lea    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x1024(%rbp)
cmpl   $0x0,-0x1024(%rbp)
je     11d1 <dbf_getmemofilename+0xb1>
movslq -0x1024(%rbp),%rax
movsbl -0x1020(%rbp,%rax,1),%eax
ff
mov    %eax,-0x1028(%rbp)
sub    $0x46,%eax
je     11a4 <dbf_getmemofilename+0x84>
jmp    1190 <dbf_getmemofilename+0x70>
mov    -0x1028(%rbp),%eax
sub    $0x66,%eax
je     11bd <dbf_getmemofilename+0x9d>
jmp    11b8 <dbf_getmemofilename+0x98>
movslq -0x1024(%rbp),%rax
movb   $0x54,-0x1020(%rbp,%rax,1)
54
jmp    11cc <dbf_getmemofilename+0xac>
jmp    11bd <dbf_getmemofilename+0x9d>
movslq -0x1024(%rbp),%rax
movb   $0x74,-0x1020(%rbp,%rax,1)
74
jmp    11d1 <dbf_getmemofilename+0xb1>
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbf_getmemofilename>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x1000,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
add    $0xffffffffffffffff,%rax
test   %eax,%eax
je     1166 <dbf_getmemofilename+0x46>
cmpb   $0x46,(%rsp,%rax,1)
setne  %cl
shl    $0x5,%cl
or     $0x54,%cl
mov    %cl,(%rsp,%rax,1)
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1030 <strncpy@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @dbf_getmemofilename(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [4096 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 @strncpy(i8* %9, i8* %10, i32 4096)
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %13, 1
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %33
17: ; preds = %3
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
switch i32 %22, label %27 [
i32 70, label %23
i32 102, label %28
]
23: ; preds = %17
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %25
store i8 84, i8* %26
br label %32
27: ; preds = %17
br label %28
28: ; preds = %17, %27
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %30
store i8 116, i8* %31
br label %32
32: ; preds = %28, %23
br label %33
33: ; preds = %32, %3
%34 = load i8*, i8** %5
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%36 = load i32, i32* %6
%37 = call i32 @strncpy(i8* %34, i8* %35, i32 %36)
ret void
}

LLVM IR (-O2):
define void @dbf_getmemofilename(i8* %0, i8* %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = call i32 @strncpy(i8* %5, i8* %0, i32 4096)
%7 = call i32 @strlen(i8* %5)
%8 = add nsw i32 %7, -1
%9 = icmp eq i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %3
%11 = sext i32 %8 to i64
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 70
%15 = select i1 %14, i8 84, i8 116
store i8 %15, i8* %12
br label %16
16: ; preds = %10, %3
%17 = call i32 @strncpy(i8* %1, i8* %5, i32 %2)
ret void
}