#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 const *);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
char *strrchr(char const *, char);
const char *suffix_me(const char *file) {
  const char *p;
  static char buf[4096];
  p = strrchr(file, '.');
  if (p && (strlen(p + 1) < 4))
    strncat(buf, file, p - file);
  else
    strcat(buf, file);
  return &buf[0];
}


x86 assembly (clang, -O0):
<suffix_me>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a1 <suffix_me+0x61>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
jge    11a1 <suffix_me+0x61>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
lea    0x2eb9(%rip),%rdi
call   1050 <strncat@plt>
jmp    11b1 <suffix_me+0x71>
mov    -0x8(%rbp),%rsi
lea    0x2ea4(%rip),%rdi
call   1060 <strcat@plt>
lea    0x2e98(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<suffix_me>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     117d <suffix_me+0x3d>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jg     117d <suffix_me+0x3d>
sub    %r14d,%ebx
lea    0x2edf(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <strncat@plt>
jmp    118c <suffix_me+0x4c>
lea    0x2ecc(%rip),%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
lea    0x2ebd(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@suffix_me.buf = internal global [4096 x i8] zeroinitializer
define i8* @suffix_me(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i8* @strrchr(i8* %4, i8 signext 46)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %22
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = load i8*, i8** %3
%16 = load i8*, i8** %2
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = call i32 @strncat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @suffix_me.buf, i64 0, i64 0), i8* %14, i32 %20)
br label %25
22: ; preds = %8, %1
%23 = load i8*, i8** %2
%24 = call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @suffix_me.buf, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %13
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @suffix_me.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@suffix_me.buf = internal global [4096 x i8] zeroinitializer
define i8* @suffix_me(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = icmp eq i8* %2, null
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
%6 = tail call i32 @strlen(i8* %5)
%7 = icmp slt i32 %6, 4
br i1 %7, label %8, label %14
8: ; preds = %4
%9 = ptrtoint i8* %2 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = tail call i32 @strncat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @suffix_me.buf, i64 0, i64 0), i8* %0, i32 %12)
br label %16
14: ; preds = %4, %1
%15 = tail call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @suffix_me.buf, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %14, %8
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @suffix_me.buf, i64 0, i64 0)
}