#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*/ sprintf(char *, char *, char *, int);
int strlen(char *);
char *bin_filename(char *nbase, int offset, char *buf) {
  char *p = nbase + strlen(nbase);
  while (p > nbase) {
    if (*p == '.')
      *p = '\0';
    --p;
  }
  sprintf(buf, "%s_offset_%04X.bin", nbase, offset);
  return buf;
}


x86 assembly (clang, -O0):
<bin_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    118a <bin_filename+0x6a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1179 <bin_filename+0x59>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1154 <bin_filename+0x34>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe64(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin_filename>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%rbp
call   1030 <strlen@plt>
test   %eax,%eax
jle    1153 <bin_filename+0x33>
mov    %eax,%eax
add    %rbp,%rax
jmp    1149 <bin_filename+0x29>
nopl   (%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbp,%rax
jbe    1153 <bin_filename+0x33>
cmpb   $0x2e,(%rax)
jne    1140 <bin_filename+0x20>
movb   $0x0,(%rax)
jmp    1140 <bin_filename+0x20>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
mov    %r14d,%ecx
call   1040 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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