#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 /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *map_filename(char *nbase, char *buf) {
  char *p = nbase + strlen(nbase);
  while (p > nbase) {
    if (*p == '.')
      *p = '\0';
    --p;
  }
  strcpy(buf, nbase);
  strcat(buf, ".map");
  return buf;
}


x86 assembly (clang, -O0):
<map_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    1197 <map_filename+0x67>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1186 <map_filename+0x56>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1161 <map_filename+0x31>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<map_filename>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
jle    1163 <map_filename+0x33>
mov    %eax,%eax
add    %rbx,%rax
jmp    1159 <map_filename+0x29>
nopw   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jbe    1163 <map_filename+0x33>
cmpb   $0x2e,(%rax)
jne    1150 <map_filename+0x20>
movb   $0x0,(%rax)
jmp    1150 <map_filename+0x20>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe8b(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c".map\00"
define i8* @map_filename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
store i8* %10, i8** %5
br label %11
11: ; preds = %22, %2
%12 = load i8*, i8** %5
%13 = load i8*, i8** %3
%14 = icmp ugt i8* %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 46
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i8*, i8** %5
store i8 0, i8* %21
br label %22
22: ; preds = %20, %15
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 -1
store i8* %24, i8** %5
br label %11
25: ; preds = %11
%26 = load i8*, i8** %4
%27 = load i8*, i8** %3
%28 = call i32 @strcpy(i8* %26, i8* %27)
%29 = load i8*, i8** %4
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%31 = load i8*, i8** %4
ret i8* %31
}

LLVM IR (-O2):
@.str = [5 x i8] c".map\00"
define i8* @map_filename(i8* %0, i8* returned %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = zext i32 %3 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
br label %8
8: ; preds = %5, %13
%9 = phi i8* [ %14, %13 ], [ %7, %5 ]
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 46
br i1 %11, label %12, label %13
12: ; preds = %8
store i8 0, i8* %9
br label %13
13: ; preds = %12, %8
%14 = getelementptr inbounds i8, i8* %9, i64 -1
%15 = icmp ugt i8* %14, %0
br i1 %15, label %8, label %16
16: ; preds = %13, %2
%17 = tail call i32 @strcpy(i8* %1, i8* %0)
%18 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
ret i8* %1
}